2

I am encountering deadlocks while trying to update multiple rows (a batch) using INSERT..ON DUPLICATE KEY UPDATE. Does MySQL lock all the rows in one batch or does it lock only the row it is updating at a point of time?

asked Oct 28, 2013 at 12:49

2 Answers 2

1

since mysql 5.7, it will acquire GAP lock if the value(has unique index) does not exist.

INSERT INTO ... SELECT ... ON DUPLICATE KEY UPDATE and LOAD DATA CONCURRENT REPLACE took too weak a lock, leading to the possibility of concurrent SELECT statements returning inconsistent results. (Bug #38046, Bug #11749055)

refer this link for detail:

https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-0.html

answered Nov 30, 2018 at 2:56
0

This would depend on the Storage Engine.

  • MyISAM : Table-level locks are performed. Consequently, all rows are locked.

  • InnoDB : Row-level locks are employed. Since InnoDB is transactional, all rows are locked implcitly. Those locks would be visible when you run SHOW ENGINE INNODB STATUS\G. If you want to manually lock those rows beforehand to prevent sharing, you could run SELECT ... FOR UPDATE.

answered Oct 28, 2013 at 13:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.