Bug #114825 | Index hints do not work expectedly | ||
---|---|---|---|
Submitted: | 30 Apr 2024 14:33 | Modified: | 30 Apr 2024 15:10 |
Reporter: | John Jove | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 8.0.36 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[30 Apr 2024 14:33]
John Jove
[30 Apr 2024 14:34]
John Jove
init_database.sql
Attachment: init_database.sql (application/octet-stream, text), 8.05 KiB.
[30 Apr 2024 14:52]
MySQL Verification Team
Hi Mr. Jove, Thank you for your bug report. However, it is not a bug. USE INDEX is a hint ...... but Optimiser can avoid it if using no index is faster. FORCE INDEX is what you are looking for, because it will be used even if it is slower: +----+-------------+-------+------------+------+---------------+------+---------+------------+------+----------+-----------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+------+---------+------------+------+----------+-----------------------+ | 1 | SIMPLE | t7 | NULL | ALL | PRIMARY | NULL | NULL | NULL | 1 | 100.00 | NULL | | 1 | SIMPLE | t5 | NULL | ref | i6 | i6 | 6 | test.t7.c1 | 30 | 100.00 | Using index condition | +----+-------------+-------+------------+------+---------------+------+---------+------------+------+----------+-----------------------+ Not a bug.
[30 Apr 2024 15:10]
John Jove
Thanks, I got it. When applying USE INDEX, the optimizer decides the final choice. By the way, do optimizer hints perform like a hint or an enforcement?
[30 Apr 2024 15:41]
MySQL Verification Team
Mr. Jove, Optimiser hints are enforced, sometimes even at the detriment to performance. No need to reply to this message.