-
Notifications
You must be signed in to change notification settings - Fork 979
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
last_insert_ID() not served from connection-cache when used in prepared statement #4621
Comments
Hi @sbstnpl1 . First of all, I think that any application using
That would work. The use of text query for
It seems to be Java related. In JDBC you can use
No , this doesn't work.
If you want to use Should ProxySQL reply to Again, possible to implement, but I don't think the effort is justified. |
Hi @renecannao , thank you for your fast and detailed clarification. We totally agree with all your points. Use of LAST_INSERT_ID() is not really necessary and is absolutely nonesense to use it in prepared statement. You might want to add this information to documentation. The feature is described here. It might be useful to mention here that this does not work with prepared statements. Cause blindly relying on it (like we did), will lead do data/ID inconsistencies. again, thanks for you support. Enjoy your weekend! |
Good day,
we've noticed, ProxySQL's feature to return LAST_INSERT_ID() from the Connection-Cache instead of querying it from db-node (to allow Multipexing in conjunction with LAST_INSERT_ID) does not work, if
SELECT LAST_INSERT_ID()
is queried as a prepared statement (binary protocol).Steps to reproduce:
I used a python3 script below to reproduce. The
SELECT LAST_INSERT_ID()
Statement does show up in the audit log of the MySQL Backend node. When settingprepared=True
toprepared=False
for stmt2, it's not beeing forwarded to Backend-Node and served from Connection Cache es expected.Impact:
As multiplexing won't be disabled and last_insert_id won't be served from connection cache, this inevitably leads to last_insert_id not working reliable and wrong IDs to be returned.
(im)possible Workarounds:
regular statements
Of course an easy solution would be to simply use regular statements instead of prepare. However, we use MyBatis, which useses prepared statements by default and we can't change that easily.
convert them with a query rule
We tried to use proxysql query rules to convert those prepared statements to regular statements. Surprisingly, this generally seems to work, but the response won't be accepted by the client as it expects a binary OK packet:
erfaceError('Expected Binary OK packet')
use mysql-auto_increment_delay_multiplex
this is of course a working workaround, but not very nice and also not 100% reliable.
Fix:
The LAST_INSERT_ID should also be returned from connection cache when used in a prepared statement.
The text was updated successfully, but these errors were encountered: