I have table checked_result
with columns idx
,A
, B
and C
with 200.000+ records.
I created indices for idx
and each column and combination of those columns, 16 indices in total :
idx,A,B,C,AB,BC,AC,ABC,(idx,A), (idx,B), (idx,C), (idx,A,B), (idx,A,C), (idx,B,C), (idx,A,B,C).
All indices should be used according to how query filters. When I use queries for single column :
SELECT * FROM checked_result WHERE (A in ('123')) AND idx >= 0 ORDER BY B DESC LIMIT 10
SELECT * FROM checked_result WHERE (A in ('123')) AND idx >= 0 ORDER BY B DESC, C ASC LIMIT 10
it's fast, but when I filter multiple values in one column :
SELECT * FROM checked_result WHERE (A in ('123','456')) AND idx >= 0 ORDER BY B DESC
SELECT * FROM checked_result WHERE (A in ('123','456')) AND idx >= 0 ORDER BY B DESC, C ASC LIMIT 10
it's really slow. Why does this happen even after indexing? How can I make it faster?
EXPLAIN QUERY PLAN SELECT * FROM checked_result WHERE (A in ('123')) AND idx >= 0
EXPLAIN QUERY PLAN SELECT * FROM checked_result WHERE (A in ('123','456')) AND idx >= 0
Each shows the following result:
SEARCH TABLE checked_result USING INDEX idx_checked_result_A_B (A=?)
SCAN TABLE checked_result USING INDEX idx_checked_result_A_B_C