Skip to content

Query vs Execute #1601

Answered by sidorares
nzlotrfan asked this question in Q&A
Jul 31, 2022 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

1 - yes, main reason to reuse connection is to reduce query/execute latency, especially in case of non-local mysql server. Each connection is more than one packet round trip and adds to a total query execution

2 - it depends, .execute() under the hood consist of 2 steps: prepare ( only for the first time .execute is used with this connection ) and then statement.execute. For short query that is already in the mysql server query cache performance might be identical ( or sometimes even better for .query() ). The main reason to use .execute is to avoid client side parameters serialization into sql string and potential security bugs if this serialization is not safe ( .execute does not need i…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@nzlotrfan
Comment options

@sidorares
Comment options

@nzlotrfan
Comment options

Answer selected by nzlotrfan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants