Bug #103039 | Query with group by not showing that it is using the index for the group by | ||
---|---|---|---|
Submitted: | 18 Mar 2021 14:49 | Modified: | 26 Mar 2021 2:03 |
Reporter: | John Carew | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 8.0.23, 5.7.33 | OS: | CentOS (8.2.2004) |
Assigned to: | CPU Architecture: | Any |
[18 Mar 2021 14:49]
John Carew
[18 Mar 2021 15:37]
MySQL Verification Team
Hello John Carew, Thank you for the report and test case. regards, Umesh
[18 Mar 2021 16:05]
John Carew
Just to be clear, we are seeing this behavior with one of our small queries against a very large table(13 mil). That is what brought us to try the simple example in the docs, to see if we could get the group by to use the index in the example first. Then move onto our query. But we were never able to successfully get it to work with the docs sample either.
[19 Mar 2021 10:27]
Cat Vo Minh
Hello John, I'm a newbie in the forum, very like working on MySQL. I just built Mysql 8.0.23 from source in MacOS and run your test case via mysql client command. It works for me. Which mysql client do you use ? I'm not sure sql client that affect `EXPLAIN` query plan in this case. mysql> EXPLAIN SELECT c1, c2 FROM t1 GROUP BY c1, c2; | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------+ | 1 | SIMPLE | t1 | NULL | range | idx | idx | 66 | NULL | 5 | 100.00 | Using index for group-by |
[19 Mar 2021 16:18]
John Carew
Well, first we are not running it on MacOS and secondly the client is irrelevant to the query. Did you run the table create statement as I have pasted? Your explain plan is showing much different than ours; your type is range instead of index, and rows is 5 instead of 9. mysql> EXPLAIN SELECT c1, c2 FROM t1 GROUP BY c1, c2; +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | t1 | NULL | index | idx | idx | 99 | NULL | 9 | 100.00 | Using index | +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)
[23 Mar 2021 11:29]
Cat Vo Minh
ah It's my mistake as I try to reproduce the bug. Thank John!
[26 Mar 2021 2:03]
John Carew
This now shows as verified, is the status correct? Was someone able to verify this?
[26 Mar 2021 11:34]
Erlend Dahl
Indeed, the bug report has been verified.