Bug #115843 | The incorrect calculation of 'select_limit' led to an incorrect index selection | ||
---|---|---|---|
Submitted: | 15 Aug 2024 8:26 | Modified: | 21 Aug 2024 8:04 |
Reporter: | ksql- team | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 8.0.32, 8.0.39 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | Optimizer bug, order by |
[15 Aug 2024 8:26]
ksql- team
[16 Aug 2024 7:56]
MySQL Verification Team
Hello! Thank you for the report and detailed steps to reproduce. Verified as described. Sincerely, Umesh
[16 Aug 2024 8:16]
MySQL Verification Team
8.4.2 seems to be Ok. bin/mysql -uroot -S/tmp/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.4.2 MySQL Community Server - GPL Copyright (c) 2000, 2024, Oracle and/or its affiliates. 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 database test; Query OK, 1 row affected (0.00 sec) mysql> use test Database changed mysql> explain SELECT * FROM test1 WHERE a = 1 ORDER BY c DESC LIMIT 1; +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+--------------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+--------------------------------------------+ | 1 | SIMPLE | test1 | NULL | range | idx_a_b_c,idx_a_c | idx_a_c | 5 | NULL | 1000 | 100.00 | Using index condition; Backward index scan | +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+--------------------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> SELECT * FROM test1 WHERE a = 1 ORDER BY c DESC LIMIT 1; +------+------+------+------+------+ | id | a | b | c | d | +------+------+------+------+------+ | 1000 | 1 | 1 | 1 | 1 | +------+------+------+------+------+ 1 row in set (0.00 sec) mysql> explain SELECT * FROM test2 WHERE a = 1 ORDER BY c DESC LIMIT 1; +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+--------------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+--------------------------------------------+ | 1 | SIMPLE | test2 | NULL | range | idx_a_b_c,idx_a_c | idx_a_c | 5 | NULL | 1000 | 100.00 | Using index condition; Backward index scan | +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+--------------------------------------------+ 1 row in set, 1 warning (0.01 sec) mysql> SELECT * FROM test2 WHERE a = 1 ORDER BY c DESC LIMIT 1; +------+------+------+------+------+ | id | a | b | c | d | +------+------+------+------+------+ | 1000 | 1 | 1 | 1 | 1 | +------+------+------+------+------+ 1 row in set (0.00 sec) mysql>
[21 Aug 2024 8:04]
ksql- team
Hello! Thank you for your prompt response and for testing the MySQL 8.4.2 version. However, I have encountered a discrepancy that I would like to bring to your attention. I downloaded the MySQL source code from the official GitHub repository and checked out the mysql-8.4.2 tag. After compiling the source code in my local environment on CentOS 7 with GCC version 11.2.1, I attempted to reproduce the steps and queries you provided in your response. Unfortunately, the results I obtained were not consistent with what you observed. Specifically, the issue I initially reported still appears to be present in 8.4.2. To better understand the situation, could you please provide details on the testing environment and the compilation options you used during your testing? This information would be greatly helpful for me to align my setup and further investigate the issue. Thank you again for your assistance, and I look forward to your guidance. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.4.2-debug Source distribution Copyright (c) 2000, 2024, Oracle and/or its affiliates. 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> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> explain SELECT * FROM test1 WHERE a = 1 ORDER BY c DESC LIMIT 1; +----+-------------+-------+------------+-------+-------------------+-------+---------+------+------+----------+----------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+-------------------+-------+---------+------+------+----------+----------------------------------+ | 1 | SIMPLE | test1 | NULL | index | idx_a_b_c,idx_a_c | idx_c | 5 | NULL | 99 | 1.01 | Using where; Backward index scan | +----+-------------+-------+------------+-------+-------------------+-------+---------+------+------+----------+----------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> SELECT * FROM test1 WHERE a = 1 ORDER BY c DESC LIMIT 1; +------+------+------+------+------+ | id | a | b | c | d | +------+------+------+------+------+ | 1000 | 1 | 1 | 1 | 1 | +------+------+------+------+------+ 1 row in set (25.36 sec) mysql> explain SELECT * FROM test2 WHERE a = 1 ORDER BY c DESC LIMIT 1; +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+----------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+----------------------------------+ | 1 | SIMPLE | test2 | NULL | range | idx_a_b_c,idx_a_c | idx_a_c | 5 | NULL | 1000 | 100.00 | Using where; Backward index scan | +----+-------------+-------+------------+-------+-------------------+---------+---------+------+------+----------+----------------------------------+ 1 row in set, 1 warning (0.01 sec) mysql> SELECT * FROM test2 WHERE a = 1 ORDER BY c DESC LIMIT 1; +------+------+------+------+------+ | id | a | b | c | d | +------+------+------+------+------+ | 1000 | 1 | 1 | 1 | 1 | +------+------+------+------+------+ 1 row in set (0.02 sec)