Skip to content

db.mysql query and real_query do not wait until execution is complete. #18063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
einar-hjortdal opened this issue Apr 26, 2023 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@einar-hjortdal
Copy link
Contributor

Describe the bug

query and real_query do not wait until execution is complete. This allows functions to be invoked while the previous is still executing, causing error if the next operations rely on the previous incomplete operation.

Expected Behavior

query and real_query should wait for all the statements to be executed by the mysql server before allowing the next functions on the stack to be executed.

Current Behavior

query and real_query do not wait.

Reproduction Steps

I have an sql file with ~130 tables.
I read this file and execute it with real_query (or query, same outcome) in one function

mut mysql_conn := new_mysql_conn_with_flag(mysql.ConnectionFlag.client_multi_statements)
file_data := os.read_file(file_path) or { panic(err) } 
mysql_conn.real_query(file_data) or { panic(err) } 

The next function relies on the tables created with this sql file. It is run immediately after the function containing this code.
MySQL server only creates about 40 tables before the next function crashes the program because the tables required aren't found.

If I instead do other operations, by invoking other time-consuming functions instead of the function that crashes the program, I can see the MySQL server slowly creating tables while other operations are running. This shows that the real_query is still being executed, while the program is executing other tasks.

This seems like concurrent behavior.

Possible Solution

No response

Additional Information/Context

No response

V version

Current V version: V 0.3.3 0a8a0fd, timestamp: 2023-03-25 14:38:47 +0200

Environment details (OS name and version, etc.)

V full version: V 0.3.3 ee4150f.c4b34c9
OS: linux, Linux version 5.14.0-162.23.1.el9_1.x86_64 (mockbuild@pp-el9) (gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2), GNU ld version 2.35.2-24.el9) #1 SMP PREEMPT_DYNAMIC Wed Apr 12 16:23:09 UTC 2023
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz

getwd: /home/coachonko/Documents/projects/vlang/peony
vexe: /home/coachonko/.local/lib64/v/v
vexe mtime: 2023-04-26 09:47:45

vroot: OK, value: /home/coachonko/.local/lib64/v
VMODULES: OK, value: /home/coachonko/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.31.1
Git vroot status: weekly.2023.15-62-gc4b34c94
.git/config present: true

CC version: cc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
@einar-hjortdal einar-hjortdal added the Bug This tag is applied to issues which reports bugs. label Apr 26, 2023
@einar-hjortdal
Copy link
Contributor Author

einar-hjortdal commented Apr 29, 2023

As an update: I believe query and real_query do wait for execution to be complete when the query is a single statement, when multiple statements are provided it is likely they wait for the first result only.
As a workaround, instead of passing the entire content of the .sql file to query, parse it into an array of queries and loop through them:

# Instead of 
mut mysql_conn := new_mysql_conn_with_flag(mysql.ConnectionFlag.client_multi_statements)
file_data := os.read_file(file_path) or { panic(err) } 
mysql_conn.real_query(file_data) or { panic(err) } 

# Do this
mut mysql_conn := new_mysql_conn()
file_data := os.read_file(file_path) or { panic(err) } 
parsed_data := file_data.split(';')
for query in parsed_data[0...parsed_data-1] { // remove last element as it should be an empty string
	mysql_conn.query(query) or { panic(err) }
}

Essentially, mysql.ConnectionFlag.client_multi_statements is not supported, just like in #18061

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant