I have a MySQL table with ~17M rows where I end up doing a lot of aggregation queries.
For this example lets say I have index_on_b, index_on_c, compound_index_on_a_b, compound_index_on_a_c
I try and run a query explain
EXPLAIN SELECT SUM(revenue) FROM table WHERE a = some_value AND b = other_value And I find that the selected index is index_on_b, but when I use a query hint
SELECT SUM(revenue) FROM table USE INDEX(compound_index_on_a_b) The query runs way way faster. Is there anything I can do in MySQL config to make MySQL choose the compound indexes first?
SHOW CREATE TABLEand theSELECT. There could be subtle things such as datatype inconsistencies getting in the way. AlsoEXPLAIN SELECT ...