Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Hi, this issue might be related to CONJ-920.
System setup
- MariaDB Connector J 3.3.1
- MariaDb 10.5.23
- Java 8
- HikariCP 4.0.3 JDBC connection pool
Issue
I'm trying to do a batch query with INSERT ON DUPLICATE KEY UPDATE statement and when inserting more than one row into a table where all keys already exist then the update performed properly but executeBatch() returns an array where all values are -2 instead of 2:
expected [2,2,2] but was [-2,-2-2]
However, if I insert only one row with the existing key then I get the correct value of 2.
If I have two rows (one new one and the second one existing) then I get [-2,-2] instead of [2,1]
In the case where all rows are new one works properly, and value 1 is returned for each row.
I've tried ?useBulkStmts=false&useBulkStmtsForInserts=true and ?useBulkStmts=true&useBulkStmtsForInserts=true and got the same result.
Is it supposed to work like that? To me it seems like a bug, I can not distinguish updates from inserts in this case.
To summarize:
- insert of multiple existing rows - produces [-2,-2,-2], expected [2,2,2]
- insert of multiple mixed rows (new and existing) - produces [-2,-2,-2], expected [2,1,2]
- insert of single existing row - produces [2] (as expected)
- insert of multiple new rows - produces [1,1,1] (as expected)
- insert of single new row - produces [1] (as expected)
Attachments
Issue Links
- relates to
-
MDEV-30366 Permit bulk implementation to return ALL individual results
- Closed
-
CONJ-920 MariaDB Java Client 3.0.3 - Java batched statements with optimistic locking failing
- Closed
Thanks for reporting this issue.
When batching with one command only, connector doesn't use BULK command, but normal query command, resulting in returning expected result.
Problem is that "INSERT ON DUPLICATE KEY UPDATE" must not be considered as standard INSERT, that will either always return either 0 or 1 affected rows.
Those specific commands must not use BULK to return affected rows, until
MDEV-30366is done.