Bug #43342 FORCE INDEX hint does not differentiate between ORDER BY and GROUP BY
Description:
The FORCE INDEX FOR GROUP BY hint forces to use the specified index for queries without any GROUP BY:
mysql> explain select * from t1 order by a;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 7 | Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set (0.00 sec)
mysql> explain select * from t1 force index for order by (idx) order by a;
+----+-------------+-------+-------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | t1 | index | NULL | idx | 5 | NULL | 7 | |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
mysql> explain select * from t1 force index for group by (idx) order by a;
+----+-------------+-------+-------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | t1 | index | NULL | idx | 5 | NULL | 7 | |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
How to repeat:
Run the following sequence of commands to see the problem:
create table t1 (a int, b int, index idx(a));
insert into t1 values (5,50), (3,30), (3,33), (7,77), (5,55), (5,51), (3,31);
explain select * from t1 order by a;
explain select * from t1 force index for order by (idx) order by a;
explain select * from t1 force index for group by (idx) order by a;
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.050 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.