Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
3.5.6
-
None
-
None
Description
This is a followon ticket from the changes made on CONJ-1238.
On that ticket, I created a PR which reintroduced the rewriteBatchedStatements connection property, and it looks like that was merged into develop on 2025-09-03.
Soon after there was an additional commit on 2025-09-08 ( https://github.com/mariadb-corporation/mariadb-connector-j/commit/91e7724f201a233c3f8e72fadb9492289b1de013 ) which substantially changed that code, which is OK, but I think those changes introduced some regressions around what statements are allowed to be rewritten, and the bounds of the repeating segment in that rewritten query.
In the original PR, the following query would not have been rewritable:
INSERT INTO b VALUES (?,?), (?,?) |
as it would have triggered caused this code to execute in ClientParser.rewriteableParts() when the third question mark was parsed:
case (byte) '?': |
if (state == LexState.Normal) { |
paramPositions.add(i);
|
if (valuesBracketPositions.size() == 2) { |
reWritablePrepare = false; |
}
|
}
|
Note this logic is consistent with the old code that was removed in https://github.com/mariadb-corporation/mariadb-connector-j/commit/6c2213a5d3e0561a11d22afba915bf2383a85799 , i.e. the code we are trying to be backwards-compatible with by reintroducing the rewriteBatchedStatements connection property.
In the modified code, that ClientParser code is now
case (byte) '?': |
if (state == LexState.Normal) { |
paramPositions.add(i);
|
// have parameter outside values parenthesis |
if (valuesBracketPositions.size() == 1 |
&& lastParenthesisPosition > 0 |
&& isInParenthesis == 0) { |
reWritablePrepare = false; |
}
|
}
|
break; |
where 'lastParenthesisPosition' is updated whenever a top-level ')' character is encountered.
This works for this particular query, as the entire (?, ?), (?,?) section can be repeated, but it fails for this query
INSERT INTO b VALUES (?,?) AS v ON DUPLICATE KEY UPDATE b.a=(v.a) |
as it attempts to repeat the entire (?,?) AS v ON DUPLICATE KEY UPDATE b.a=(v.a) section which result in an SQL syntax error; it should only repeat the (?,?) section.