UPDATE ... WHERE ... ORDER BY... always does a filesort when not required
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
MySQL Server |
Unknown
|
Unknown
|
||||
Percona Server moved to https://jira.percona.com/projects/PS | Status tracked in 5.7 | |||||
5.1 |
Won't Fix
|
Medium
|
Unassigned | |||
5.5 |
Triaged
|
Medium
|
Unassigned | |||
5.6 |
Triaged
|
Medium
|
Unassigned | |||
5.7 |
Triaged
|
Medium
|
Unassigned | |||
Percona XtraDB Cluster moved to https://jira.percona.com/projects/PXC | Status tracked in 5.6 | |||||
5.5 |
Confirmed
|
Undecided
|
Unassigned | |||
5.6 |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql -uroot -proot -P3312 test
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE TABLE update_test (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT,
INDEX (b,c));
Query OK, 0 rows affected (1.20 sec)
mysql> INSERT INTO update_test (b, c) VALUES (1, 1), (1, 2), (1,3), (2, 2), (2,
3), (2,4), (2, 5), (5, 5), (6,6), (7,7);
Query OK, 10 rows affected (0.19 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql>
mysql> -- no filesort
mysql> SELECT * FROM update_test WHERE b = 1 ORDER BY c LIMIT 2;
+---+------+------+
| a | b | c |
+---+------+------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
+---+------+------+
2 rows in set (0.13 sec)
mysql> SHOW SESSION STATUS LIKE 'Sort%';
+------
| Variable_name | Value |
+------
| Sort_merge_passes | 0 |
| Sort_range | 0 |
| Sort_rows | 0 |
| Sort_scan | 0 |
+------
4 rows in set (0.08 sec)
mysql>
mysql> -- does an unneeded filesort
mysql> UPDATE update_test SET a = a + 10 WHERE b = 1 ORDER BY c LIMIT 2;
Query OK, 2 rows affected (0.11 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> SHOW SESSION STATUS LIKE 'Sort%';
+------
| Variable_name | Value |
+------
| Sort_merge_passes | 0 |
| Sort_range | 1 |
| Sort_rows | 2 |
| Sort_scan | 0 |
+------
4 rows in set (0.00 sec)
tags: | added: i42464 |
This bug is originally reported for PXC version PXC 5.5.34.