Bug #110503 | rewriteBatchedStatements=true leads to unexpected result | ||
---|---|---|---|
Submitted: | 26 Mar 2023 8:25 | Modified: | 17 Nov 2023 19:23 |
Reporter: | Wenqian Deng | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | Connector / J | Severity: | S3 (Non-critical) |
Version: | 8.0.32 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[26 Mar 2023 8:25]
Wenqian Deng
[29 Mar 2023 7:44]
MySQL Verification Team
Hello Wenqian Deng, Thank you for the report and test case. regards, Umesh
[21 Oct 2023 0:43]
Filipe Silva
Posted by developer: The observed result is expected. This is so because when rewriteBatchedStatements=true, Connector/J tries to avoid submitting queries individually to the server. So, when one of the query fails, subsequent queries are not executed. On the other hand, with rewriteBatchedStatements=false, all queries are executed regardless of failures. When setting rewriteBatchedStatements=true one must be aware of such differences and make their choice consciously.
[21 Oct 2023 1:08]
Wenqian Deng
I think that if this behavior is intended as a feature, it should be more clearly documented. Users may not expect that setting "rewriteBatchedStatements" would result in inconsistent behavior of the connector.
[30 Oct 2023 15:45]
Wenqian Deng
I have another confused point according to your comment "So, when one of the query fails, subsequent queries are not executed. On the other hand, with rewriteBatchedStatements=false, all queries are executed regardless of failures.". In the test case, with rewriteBatchedStatements=true, when the second batch is: executeBatch(con, new String[]{"INSERT INTO t0 VALUES (1217233624)", "TRUNCATE t0", "INSERT INTO t0 VALUES (1722235442)"}); the result shows "TRUNCATE t0" executed successfully, but when the second batch is executeBatch(con, new String[]{"INSERT INTO t0 VALUES (1217233624)", "TRUNCATE t0", "INSERT INTO t0 VALUES (-751078476)", "INSERT INTO t0 VALUES (-671105839)", "INSERT INTO t0 VALUES (1722235442)"}); the result shows "TRUNCATE t0" executed failed. It means with rewriteBatchedStatements=true, sometimes subsequent queries are not executed but sometimes they are executed. I think it is a bug and please open it.
[17 Nov 2023 19:23]
Filipe Silva
Well, yes, it could be documented better. Regarding your last observation, this is so because statement re-writing only kicks in if the batch has at least 5 queries. Note that this feature was designed having in mind that batched statements are typically INSERTs or UPDATEs (as the documentation for Statement#addBatch() states) and the goal is to improve performance when executing a large number of them. It is kind of implicit that in theses cases the input comes from a "clean" source and no data consistency exceptions are expected while executing those queries. If you aren't sure the queries you need to execute won't throw a data consistency exception, then you shouldn't use "rewriteBatchedStatements=true". Normal applications have little to no gain in setting "rewriteBatchedStatements=true", actually, quite the opposite. You can see this as a feature to use when importing CSV files to a database or similar. I'm setting the bug as "Verified" but just from the perspective of improving the documentation of the connection property "rewriteBatchedStatements".