I have a simple table →
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
by_id INT UNSIGNED NOT NULL
posted_on INT UNSIGNED NOT NULL
My table engine MyISAM.
I have an index with multiple columns called combo1onby_id,posted_on,id
I ran this query →
EXPLAIN SELECT * FROM books
WHERE by_id = '1' AND posted_on = '0'
ORDER BY id DESC LIMIT 7;
The column Extraindicates Using whereand the key column indicatescombo1
But, when I run this query →
EXPLAIN SELECT * FROM books
WHERE by_id IN(1,7,10) AND posted_on = '0'
ORDER BY id DESC LIMIT 7;
The column Extraindicates Using where; Using filesort, and the key column indicates combo1.
Why in the second case it does filesort, although QEP shows that the optimizer uses the combo1 index, in which "id" is indexed.
source
share