Bug #39657 | InnDB - 2 simple update queries cause deadlock. | ||
---|---|---|---|
Submitted: | 26 Sep 2008 2:46 | Modified: | 13 May 2010 16:03 |
Reporter: | SeWoong Jeon | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S4 (Feature request) |
Version: | 5.0.40 Enterprise | OS: | Linux (Cent OS 4.5) |
Assigned to: | CPU Architecture: | Any | |
Tags: | deadlock, innodb |
[26 Sep 2008 2:46]
SeWoong Jeon
[26 Sep 2008 4:07]
Valeriy Kravchuk
This is a known InnoDB problem that should be fixed eventually. Please, check if this is still repeatable with 5.1.28.
[20 Oct 2008 17:42]
Mikhail Izioumtchenko
Correcting the status. Valery, when you say 'a known problem', does it have a bug number? And in your opinion, is it really a bug, or just something that the customer doesn't like about InnoDB because it doesn't behave like MSSQL. The latter case would make it a feature request. How a deadlock is a bug and not the fact of life about database systems?
[21 Oct 2008 1:45]
SeWoong Jeon
Hi, Michael. Do you think I hate InnoDB because it doesn't behave like MSSQL? Please let there is no misunderstanding about this. I love MySQL and InnoDB. :-) Simple update query like "UPDATE TABLE SET col=col+1 WHERE PK=$val", should get X-lock first, not S-lock. Because InnoDB does not have U-Lock (like MSSQL). It is point of this problem. If this deadlock situration is normal, how can I avoid this deadlock situration? "BEGIN; SELECT @val:=col .. FOR UPDATE; UPDATE .. SET col=@val+1 ..; COMMIT" ??
[21 Oct 2008 3:18]
Mikhail Izioumtchenko
>Hi, Michael. thank you for your prompt response. >Do you think I hate InnoDB because it doesn't behave like MSSQL? no, not at all >Please let there is no misunderstanding about this. >I love MySQL and InnoDB. :-) it's just that today I didn't really have time to concentrate properly or even to formulate my question clearly. The question is (was), does the situation conform to the transaction isolation level? If so, the application has to try again. If no, it's a bug in InnoDB no matter how we love InnoDB. Actually I was pretty sure the answer was 'no, it's a bug in InnoDB', I was just confused by the mention of the U-lock which is something I don't know what it is and didn't have the time today to Google it. >Simple update query like "UPDATE TABLE SET col=col+1 WHERE PK=$val", should get X-lock >first, not S-lock. I do agree. >Because InnoDB does not have U-Lock (like MSSQL). >It is point of this problem. can you give me the table structure? I can guess that PK must be the primary key and col is not. What interests me most, is any of col or PK, or any other column an autoinc? >If this deadlock situration is normal, no this can't be normal > how can I avoid this deadlock >situration? "BEGIN; SELECT @val:=col .. FOR UPDATE; UPDATE .. SET col=@val+1 ..; COMMIT" ?? well I think the ref manual chapter on the InnoDB engine says that SELECT @val:=col .. FOR UPDATE would acquire an X-lock on every row it would find, so we do seem to have a problem here. A complete CREATE TABLE statement, including each index on the table, would be a good starting point for the investigation. Also, 'a known problem', how known? A bug number or just a reference to a blog entry would be nice. And, how reproducible is it? Sorry for asking trivial questions but I'm a bit new to MySQL/Innodb, I used to work with pretty much everything else that's out there except Sybase or mssql which are (used to be when mssql started) the same thing anyway
[21 Oct 2008 5:35]
SeWoong Jeon
Michael, thank you for response. We use REPEATABLE-READ isolation level. And.. Actually, we use dual-master (master-master) replication. Roll-backed update query was executed by SQL Thread, and SQL Thread was stopped. Table structure is very very simple. and, you can find 2 queries in my original message. (innodb status) CREATE TABLE `buddylist` ( `userid` varchar(36) NOT NULL default '', `buddyid` varchar(36) NOT NULL default '', `btype` tinyint(4) default NULL, `crdate` datetime default NULL, PRIMARY KEY (`userid`,`buddyid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 I also want to know whether this is known problem. Valeriy, Can you give us more information about this problem ?
[21 Oct 2008 5:54]
Valeriy Kravchuk
I meant this old feature request, bug #21356.
[21 Oct 2008 17:11]
Mikhail Izioumtchenko
Got it, finally, so the replication has nothing to do with it, but rather it's a duplicate of a well known problem, http://bugs.mysql.com/bug.php?id=21356. Thanks for the reference, Valeriy. My opinion on lock escalation taking priority over existing X-waiter maybe not as strong as Valeriy's but my opinion doesn't matter too much. I do suspect that there may be applications out there that would start perform worse after this change. Or more generally, for most code changes there exists an application that will suffer. Heikki already declared http://bugs.mysql.com/bug.php?id=21356 a feature request, so I'm setting the status back to 'Verified', assigning to Sunny, setting S5. I'd also suggest triaging it as D5, and in fact I'd simply set the status of this one to be 'Duplicate', but I'll leave it to Sunny to decide. Also, if I understand correctly MySQL procedures, a feature request, when/if implemented is unlikely to be backported to an older release. Regardless of the potential usefulness of U locks in InnoDB I can't see how lack of row level intent locks can be a bug. It's definitely a feature request.