Bug #111703 | INSERT ON DUPLICATE KEY locks INSERT if table have many PRIMARY and UNIQUE key | ||
---|---|---|---|
Submitted: | 10 Jul 2023 6:40 | Modified: | 15 Jul 2023 1:58 |
Reporter: | Aristotle Po | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 8.0.33, 5.7.42 | OS: | Any |
Assigned to: | Jon Stephens | CPU Architecture: | Any |
Tags: | ON DUPLICATE KEY UPDATE |
[10 Jul 2023 6:40]
Aristotle Po
[10 Jul 2023 7:15]
Aristotle Po
I also got similar result with INSERT ... ON DUPLICATE KEY UPDATE on Session 2 ###################### # Session 1 ###################### mysql [localhost:5742] {msandbox} (test) > BEGIN; Query OK, 0 rows affected (0.00 sec) mysql [localhost:5742] {msandbox} (test) > INSERT INTO t1(a, b) values(1, 'test1') ON DUPLICATE KEY UPDATE b = VALUES(b); Query OK, 0 rows affected (0.00 sec) ###################### # Session 2 ###################### mysql [localhost:5742] {msandbox} (test) > INSERT INTO t1(a, b) values(3, 'test3') ON DUPLICATE KEY UPDATE a = VALUES(a), b= VALUES(b); ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
[10 Jul 2023 7:43]
Aristotle Po
Further testing shows the locking happens for both existing and non existing records : ############## # Session 1 ############## t1> BEGIN; Query OK, 0 rows affected (0.00 sec) t1> INSERT INTO t1(a, b) values(1, 'test1') ON DUPLICATE KEY UPDATE b = VALUES(b); Query OK, 0 rows affected (0.00 sec) t1> SELECT * FROM t1; +---+---+-------+ | i | a | b | +---+---+-------+ | 1 | 1 | test1 | | 2 | 2 | test2 | +---+---+-------+ 2 rows in set (0.01 sec) ############## # Session 2 ############## t2> INSERT INTO t1(a, b) values(3, 'test3') ON DUPLICATE KEY UPDATE a = VALUES(a), b= VALUES(b); -- non existing ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction t2> INSERT INTO t1(a, b) values(2, 'test2') ON DUPLICATE KEY UPDATE a = VALUES(a), b= VALUES(b); -- already existing ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
[10 Jul 2023 7:47]
MySQL Verification Team
Hello Aristotle Po, Thank you for the report and feedback. regards, Umesh
[15 Jul 2023 1:58]
Jon Stephens
Hi! I'm sorry, but this is not a bug. Reason: We already indicate in the Manual that you should not use ON DUPLICATE KEY UPDATE with tables having multiple unique keys. (Note that primary keys are by definition also unique keys.) We provide some reasons for this. It's not an exhaustive list, nor does it need to be; we've established that it's a Bad Thing to be avoided. I don't mean to sound harsh, but when you go directly against advice given in the Manual, I don't think we can't really be held responsible for what happens next, and I don't see how enshrining it in our documentation provides any benefit to users. Thanks and regards, jon.