-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add support for the MySQL prepare command protocol #3862
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to get this working? According to https://dev.mysql.com/doc/internals/en/prepared-statements.html, this is an entirely different protocol end-to-end. This means that the results have to be returned differently. I don't see any code for those parts.
We considered implementing this protocol. However, given that the Prepare protocol never gained popularity, we decided not to support it.
Ahh ok. I see now. Github didn't show me all the changes... |
OK, I'll add test case. |
Waiting for you merge to master |
@linuxgood1230 I'm very busy recently. After a few days I'll write test case. Thanks for your attention. |
Signed-off-by: dcadevil <dcadevil@126.com>
Signed-off-by: dcadevil <dcadevil@126.com>
Signed-off-by: dcadevil <dcadevil@126.com>
Signed-off-by: dcadevil <dcadevil@126.com>
Signed-off-by: dcadevil <dcadevil@126.com>
Signed-off-by: dcadevil <dcadevil@126.com>
Signed-off-by: dcadevil <dcadevil@126.com>
Tests to be added:
|
@dcadevil I'm planning to write the testcases so that we can get this PR merged. |
@deepthi Thank you very much, if you need any help, please let me know. |
hi @dcadevil, can you put in some examples of how this feature is intended to be used? Also, what client are you using to connect to vitess? The stock mysql client doesn't seem to work:
|
hi, @deepthi, the MySQL prepare protocol implemented here is not the prepare in the SQL syntax. You can use java's jdbc driver client (note: useServerPrepStmts=true), or golang's go-mysql-driver(https://github.com/go-sql-driver/mysql) to test. The basically example by golang can be found here: https://github.com/go-sql-driver/mysql/wiki/Examples |
@dcadevil I am writing the unit tests for this PR and I am learning more about the MySQL protocol. I am trying to write tests for:
and I am following the pattern of the tests. I noticed there are parse functions associated with them but no write functions. I am not very familiar with MySQL protocol but is there an example you can give to help test those functions properly? Also, |
@saifalharthi, writeBinaryRows function can be regarded as the write function of parseComStmtExecute function. In fact, this function is used to transform the execution result into MySQL protocol format result after ComStmtExecute execution. In addition, it should be noted that the parameters of the parseComStmtExecute function contain a map of prepareData, the key of which is the statementID, which contains the statement and the number of parameters. So to use the parseComStmtExecute function, you need to set up the map. The setting of another data parameter is rather complicated. I recommend using JDBC or golang's MySQL client driver to execute prepared statement program to get it. Of course, it is a bit cumbersome and complicated to do so. |
I think this might solve our long standing issue with using the JDBC MySQL driver and Vitess: #4100 Packet 20/0x16 is COM_PREPARE_STMT which is what that complains about. I think the MySQL JDBC driver always uses prepare statements. Checking now. |
@@ -153,6 +153,24 @@ const ( | |||
// ComBinlogDump is COM_BINLOG_DUMP. | |||
ComBinlogDump = 0x12 | |||
|
|||
// ComPrepare is COM_PREPARE. | |||
ComPrepare = 0x16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is called COM_STMT_PREPARE
in the MySQL codebase: https://dev.mysql.com/doc/internals/en/com-stmt-prepare.html
This is really amazing and thanks for all the effort you've put into this. I'm trying this out in one of our apps and I'm running into this issue: Something wrong with the string encoding? |
No description provided.