Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.1(EOL), 10.2(EOL), 10.3(EOL)
Description
create table ten(a int); |
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); |
create table one_k(a int); |
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C; |
create table t20 (a int, b int, c int, filler char(100)); |
insert into t20 select a,a,a,a from one_k; |
alter table t20 add key(a), add key(b); |
mysql> explain delete from t20 where a between 1 and 300 order by b limit 1;
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------------+
|
| 1 | SIMPLE | t20 | range | a | a | 5 | NULL | 300 | Using where; Using filesort |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------------+
|
Here, it will use range + sorting regardless of whether it is possible to use some other index that would match the LIMIT.
For comparison:
mysql> explain delete from t20 where a+0 between 1 and 300 order by b limit 1;
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|
| 1 | SIMPLE | t20 | index | NULL | b | 5 | NULL | 1 | Using where |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|
Attachments
Issue Links
- relates to
-
MDEV-17761 Odd optimizer choice with ORDER BY LIMIT and condition selectivity
- Stalled