Bug #111969 | The performance of version 8.0 when using count(1) is significantly lower compar | ||
---|---|---|---|
Submitted: | 4 Aug 2023 9:50 | Modified: | 4 Aug 2023 14:59 |
Reporter: | fander chan | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 8.0.17+ | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[4 Aug 2023 9:50]
fander chan
[4 Aug 2023 13:04]
MySQL Verification Team
Hi Mr. chan, Thank you for your bug report. However, there are hundreds of bug reporting a significant performance drop when upgrading from 5.7 to 8.0. There are many, so we chose one. of the most similar bug, to be the original bug of your report: https://bugs.mysql.com/bug.php?id=108430 Duplicate.
[4 Aug 2023 13:20]
fander chan
I am absolutely certain that you have misunderstood my statements. Among the two bugs I pointed out, One is related to performance. It's not about the difference between 5.7 and 8.0; I just used them as examples for convenience. The actual problem is caused by a feature introduced in version 8.0.17. The other bug is completely unrelated to performance. I regard it as a display issue and a product defect that misleads users.
[4 Aug 2023 13:23]
MySQL Verification Team
HI Mr. chan, You are correct. However, that feature is here to stay, so we can not remove it. Not a bug.
[4 Aug 2023 13:37]
fander chan
mysql> explain select count(1) from t0; +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-------------+ | 1 | SIMPLE | t0 | NULL | index | NULL | idx_i1 | 4 | NULL | 1992549 | 100.00 | Using index | +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-------------+ 1 row in set, 1 warning (0.00 sec) for my 8.0 case,I think this explain result is best: mysql> explain select count(1) from t0; +----+-------------+-------+------------+-------+---------------+---------+---------+------+---------+----------+-----------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+---------+---------+------+---------+----------+-----------------------+ | 1 | SIMPLE | t0 | NULL | index | NULL | PRIMARY | 4 | NULL | 1992549 | 100.00 | Using index; Parallel | +----+-------------+-------+------------+-------+---------------+---------+---------+------+---------+----------+-----------------------+ 1 row in set, 1 warning (0.00 sec)
[4 Aug 2023 14:33]
MySQL Verification Team
Hi Mr. chan, Both queries return in 0 seconds. Hence, we do not see what kind of bug it is. What is it exactly that you want us to do???
[4 Aug 2023 14:59]
fander chan
In my tests, whether using the parallel primary key index scan algorithm (the default behavior in 8.0.17+ versions, I think it is hard-coded) or the secondary index scan algorithm (in 8.0.16 or lower versions, including 5.7), their final execution plans are the same as follows. mysql> explain select count(1) from t0; +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-------------+ | 1 | SIMPLE | t0 | NULL | index | NULL | idx_i1 | 4 | NULL | 1992549 | 100.00 | Using index | +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-------------+ 1 row in set, 1 warning (0.00 sec) To better distinguish, if the execution plan uses a parallel primary key index scanning algorithm, it should look like the following, key=PRIMARY, this would truly represent a full primary index scan in MySQL. I believe this won't mislead users. mysql> explain select count(1) from t0; +----+-------------+-------+------------+-------+---------------+---------+---------+------+---------+----------+-----------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+---------+---------+------+---------+----------+-----------------------+ | 1 | SIMPLE | t0 | NULL | index | NULL | PRIMARY | 4 | NULL | 1992549 | 100.00 | Using index; Parallel | +----+-------------+-------+------------+-------+---------------+---------+---------+------+---------+----------+-----------------------+ 1 row in set, 1 warning (0.00 sec)
[4 Aug 2023 15:06]
MySQL Verification Team
Thank you, Mr. chan, But this is not a bug. The results are correct and performance is similar. Not a bug.