-
Notifications
You must be signed in to change notification settings - Fork 315
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
Prepared statement support in MySQL and PostgreSQL #470
Comments
@sunng87 Should some logic be added here? like parsing sql to see if it is greptimedb/src/servers/src/mysql/handler.rs Line 143 in 57979c9
some references: |
@SSebo I think "prepared" stmt should be handled here: greptimedb/src/servers/src/mysql/handler.rs Line 111 in 57979c9
ane then "execute" here: greptimedb/src/servers/src/mysql/handler.rs Line 123 in 57979c9
|
@MichaelScofield This issue is dependent on #600, right? |
@MichaelScofield I found |
@SSebo It seems you have to use COM_STMT_PREPARE to trigger the callback of |
@MichaelScofield Thanks a lot! |
@SSebo prepare stmt in mysql could be executed in mysql-cli like this, and this feature request is tracked in #769 . I think in this issue, we can focus on the "COM_STMT_PREPARE" type of prepare stmt. At last, it's the most often used type of prepare stmt. (Applications use some mysql drivers tend to use binary protocol to submit prepare stmt.) As for pg, there're "simple" and "extended" query protocols, and prepare stmt uses the latter one. pgwire has the corresponding "simple" and "extended" handler for us to implement prepare stmt. |
@SSebo Yes, it's not COM_STMT_PREPARE. It's not using binary protocol, in the mysql command cli. It's the other form of prepare stmt. |
ping @SSebo , any updates? |
@MichaelScofield Sorry for delay, I'll pick it up this week. |
hi @SSebo , at least in modern postgresql clients, prepare keyword is no longer used. I have implemented prepared statement for postgresql in #925. Now it should work for most clients except rust-postgres, which uses parameter type inference that requires an upgrade of datafusion to support. I suggest you to check mysql clients if |
@sunng87 Got it. I'll do the MySQL binary protocol prepared statements
|
It takes me lots of times to figure out how to infer the placeholder types in prepared sql which used in ' COM_STMT_PREPARE_OK'. Infer prepared statement parameter types supported by datafusion by this PR apache/datafusion#4701 I patched the latest datafusion prepared statement logic to greptime used revision apache/datafusion@main...SSebo:arrow-datafusion:prepare. when I debug the code I checked some mysql clients. I checked the rust, golang, and c mysql connector source code, I found the type information just ignored. Only the number of params is used. so in my PR, just generate some dummy column in prepare phase. |
The situation is quite similar in postgresql, pg has parameter type inference as well, but some clients like jdbc are not using this feature at all. However, other clients like rust-postgres fully rely on this and has strict check for returned types. |
@sunng87 @MichaelScofield I'm working on the type infer version of prepare. Should statement be saved or plain query string? Since |
@SSebo |
I would suggest to cache At the moment we only use I think after the refactoring, protocol servers(mysql/pg) are responsible for 1. parsing sql query string to statement in protocol server's dialect; 2. transforming statement into neutral If we have a plan for this, I think @SSebo can hold on the work on prepared statement and join the refactoring above. @MichaelScofield WDTY |
@sunng87 https://docs.pingcap.com/tidb/v5.4/sql-prepared-plan-cache this feature is very similar to your idea. |
The final PR was merged #1813 We can close this issue right now, thanks to all of you. |
In order to support prepared statement, we need to implement a parse-bind-execute process in frontend caches parsed statement at connection-session scope.
The text was updated successfully, but these errors were encountered: