-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use index hint for idx_contracts_fcid_timestamp
, MySQL does not select it otherwise
#1059
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 questions before I approve this
- Did you manually verify the speedup on gompa to get some numbers for with vs without index hint?
- Is SQLite using the index? If not we might want hints for SQLite as well in which case numbers from Arequipa would be great as well.
|
The hint is great but it would be great to measure the result rather than relying on the logging. You definitely shouldn't deploy to gompa but you can still pick one of the queries that were logged as slow and run it directly against gompa's database with and without the hint. |
I measured it on We can close this out if you want, we should maybe remove the index though in that case. We added it here, maybe it was a case of two optimisations where one did the bulk of the work and the other didn't really matter all that much? |
How did you run it on gompa? 100ms seems way too slow. I searched for the query that I ran when I added the index and this is the result I'm getting on gompa. mysql> SELECT hex(fcid) FROM contracts WHERE contracts.timestamp >= 1706106000000 AND contracts.timestamp < 1708698000000 - 86400000 AND contracts.fcid = x'00195BA795481F5941ADB10463ADC89D12BED28EE61B4A684451DF8E3C5F9402' LIMIT 1;
+------------------------------------------------------------------+
| hex(fcid) |
+------------------------------------------------------------------+
| 00195BA795481F5941ADB10463ADC89D12BED28EE61B4A684451DF8E3C5F9402 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> EXPLAIN SELECT hex(fcid) FROM contracts WHERE contracts.timestamp >= 1706106000000 AND contracts.timestamp < 1708698000000 - 86400000 AND contracts.fcid = x'00195BA795481F5941ADB10463ADC89D12BED28EE61B4A684451DF8E3C5F9402' LIMIT 1;
+----+-------------+-----------+------------+-------+--------------------------------------------------------------------------+------------------------------+---------+------+------+----------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-----------+------------+-------+--------------------------------------------------------------------------+------------------------------+---------+------+------+----------+--------------------------+
| 1 | SIMPLE | contracts | NULL | range | idx_contracts_timestamp,idx_contracts_fc_id,idx_contracts_fcid_timestamp | idx_contracts_fcid_timestamp | 42 | NULL | 2437 | 100.00 | Using where; Using index |
+----+-------------+-----------+------------+-------+--------------------------------------------------------------------------+------------------------------+---------+------+------+----------+--------------------------+
1 row in set, 1 warning (0.00 sec) Even without hint it appears to be using the index. So maybe that's why you aren't seeing a difference. |
Hm interesting on my personal node it is not using that index. I guess because I'm on SQL 8.0.32 maybe... mysql> EXPLAIN SELECT hex(fcid) FROM contracts WHERE contracts.timestamp >= 1706106000000 AND contracts.timestamp < 1708698000000 - 86400000 AND contracts.fcid = x'00195BA795481F5941ADB10463ADC89D12BED28EE61B4A684451DF8E3C5F9402' LIMIT 1
-> ;
+----+-------------+-----------+------------+------+--------------------------------------------------------------------------+---------------------+---------+-------+------+----------+------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-----------+------------+------+--------------------------------------------------------------------------+---------------------+---------+-------+------+----------+------------------------------------+
| 1 | SIMPLE | contracts | NULL | ref | idx_contracts_timestamp,idx_contracts_fc_id,idx_contracts_fcid_timestamp | idx_contracts_fc_id | 34 | const | 1 | 5.00 | Using index condition; Using where |
+----+-------------+-----------+------------+------+--------------------------------------------------------------------------+---------------------+---------+-------+------+----------+------------------------------------+
1 row in set, 1 warning (0.00 sec) You're also right by the way, the reason I wasn't seeing a speedup on |
I was still seeing
SLOW SQL
warnings forSELECT * FROM contracts WHERE contracts.timestamp >= 1709984700000 AND contracts.timestamp < 1710071100000 AND contracts.fcid = '<binary>' LIMIT 1
, afterEXPLAIN
ing I found thatMySQL
doesn't use the index we added.