ENH Speed up query in stagesDifferInLocale by hinting the use of index #1017
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We found a case where the query in
stagesDifferInLocaletakes a long time to complete, because it is not using the right index.The issue doesn't seem to occur for other accounts. On closer look, the
site is waiting for the following SQL query
which takes about nearly 3 minutes(!) to complete, because
LIMIT 1lures MariaDB into not using the right index. Compare the query plans
without the
LIMIT 1(execution time 1.359s)+------+-------------+-------+--------+-----------------------------------+---------------+---------+----------------------------------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+--------+-----------------------------------+---------------+---------+----------------------------------+------+-----------------------------+
| 1 | SIMPLE | V | ref | RecordID_Version,RecordID,Version | RecordID | 4 | const | 8414 | Using where; Using filesort |
| 1 | SIMPLE | VL | eq_ref | Fluent_Record,Fluent_Version | Fluent_Record | 41 | const,const,extensions.V.Version | 1 | Using where; Using index |
+------+-------------+-------+--------+-----------------------------------+---------------+---------+----------------------------------+------+-----------------------------+
and now with the
LIMIT 1(execution time 165.333s)+------+-------------+-------+--------+-----------------------------------+---------------+---------+----------------------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+--------+-----------------------------------+---------------+---------+----------------------------------+------+--------------------------+
| 1 | SIMPLE | V | index | RecordID_Version,RecordID,Version | Version | 4 | NULL | 227 | Using where |
| 1 | SIMPLE | VL | eq_ref | Fluent_Record,Fluent_Version | Fluent_Record | 41 | const,const,extensions.V.Version | 1 | Using where; Using index |
+------+-------------+-------+--------+-----------------------------------+---------------+---------+----------------------------------+------+--------------------------+
Using an index hint to force MySQL to use the right index
completes in 1.114s.
Manual testing steps
Querying the modified queries directly in mysql client.
Issues
Pull request checklist