[CONJ-1135] MariaDB Java Client 3.3.1 - Java batched insrt on duplicate key does not work properly Created: 2023-12-07  Updated: 2023-12-13  Resolved: 2023-12-13

Status: Closed
Project: MariaDB Connector/J
Component/s: batch
Affects Version/s: None
Fix Version/s: 3.3.2

Type: Bug Priority: Major
Reporter: Teodor Mysko Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-30366 Permit bulk implementation to return ... Stalled
relates to CONJ-920 MariaDB Java Client 3.0.3 - Java batc... Closed

 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)


 Comments   
Comment by Diego Dupin [ 2023-12-13 ]

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-30366 is done.

Generated at Thu Feb 08 03:20:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.