I have the following table cl:
id - int(10) primary key
contact - int(10)
list - int(10)
With a unique index on contact and list. When I run concurrently the following query in batch by 100 records:
INSERT INTO cl(list, contact) VALUES (?, ?) ON DUPLICATE KEY UPDATE cl.id = cl.id
Under high pressure it fails in about 20% with the following error:
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ON DUPLICATE KEY UPDATE cl.id = cl.id' at line 1
80% of the queries runs just fine. When I rerun failed queries with the same parameters, again 20% fail.
Why some of the queries fail and then produce no errors when executed for the second time?
INSERT INTO cl(list, contact) VALUES (?, ?) ON DUPLICATE KEY UPDATE list = ?...or if you want to update contact, then you should try:INSERT INTO cl(list, contact) VALUES (?, ?) ON DUPLICATE KEY UPDATE contact = ?...or if you want to update both:INSERT INTO cl(list, contact) VALUES (?, ?) ON DUPLICATE KEY UPDATE list = ?,contact = ?....on key duplicate updateis mainly used when you are passing the id as parameter also, like:INSERT INTO cl(id,list, contact) VALUES (?,?, ?) ON DUPLICATE KEY UPDATE cl.id = cl.id...you are not passing the id, and if the id is also autoincrement, then you should never going to reach the on dup key update part.....It is not recommended to use this statement on tables with more than one unique index.....