Bug #68656 ORDER BY ignored in some situations for UPDATE query
| Submitted: | 12 Mar 2013 21:58 | Modified: | 2 Oct 2013 16:30 |
|---|---|---|---|
| Reporter: | Lance Ivy | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
| Version: | 5.5.6 | OS: | Any |
| Assigned to: | CPU Architecture: | Any |
[12 Mar 2013 21:58]
Lance Ivy
[12 Mar 2013 22:14]
Lance Ivy
We found a way to force the UPDATE to respect the ORDER BY, by forcing a different index. Namely: UPDATE foo FORCE INDEX (index_foo_on_baz) SET qux = 1 WHERE bar = 1 AND qux IS NULL ORDER BY baz ASC LIMIT 1;
[13 Mar 2013 8:22]
Shane Bester
I tested all versions. This is a changed introduced in 5.5.6. Probably related: http://bugs.mysql.com/bug.php?id=53742 MySQL [test]> SELECT * FROM foo; +----+------+---------------------+------+ | id | bar | baz | qux | +----+------+---------------------+------+ | 1 | 1 | 2013-01-01 00:00:01 | 1 | | 2 | 1 | 2013-01-01 00:00:00 | NULL | +----+------+---------------------+------+ 2 rows in set (0.00 sec) MySQL [test]> select version(); +-----------+ | version() | +-----------+ | 5.5.6-rc | +-----------+ 1 row in set (0.00 sec) ------------ MySQL [test]> SELECT * FROM foo; +----+------+---------------------+------+ | id | bar | baz | qux | +----+------+---------------------+------+ | 1 | 1 | 2013-01-01 00:00:01 | NULL | | 2 | 1 | 2013-01-01 00:00:00 | 1 | +----+------+---------------------+------+ 2 rows in set (0.00 sec) MySQL [test]> select version(); +-----------+ | version() | +-----------+ | 5.5.5-m3 | +-----------+ 1 row in set (0.00 sec)
[13 Mar 2013 8:24]
Shane Bester
5.5, 5.6, 5.7 affected.
[2 Oct 2013 16:30]
Paul DuBois
Noted in 5.5.35, 5.6.15, 5.7.3 changelogs. For queries of the form UPDATE ... WHERE unique_key ORDER BY ... LIMIT ..., incorrect rows could be updated. Unique keys permit multiple NULL values, but the optimizer did not always consider all of them.
[4 Dec 2013 9:12]
Laurynas Biveinis
5.5$ bzr log -r 4477 ------------------------------------------------------------ revno: 4477 committer: Tor Didriksen <tor.didriksen@oracle.com> branch nick: 5.5-bug16482467updatelimit timestamp: Tue 2013-09-10 11:20:29 +0200 message: Bug#16482467 ORDER BY IGNORED IN SOME SITUATIONS FOR UPDATE QUERY For queries like update t1 set ... where <unique key> order by ... limit ... we need to handle the fact that unique keys allow NULL values, and hence can return more than one row.
[16 May 2017 14:22]
Shane Bester
looks like this fix caused a regression https://bugs.mysql.com/bug.php?id=72040
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.