Using the IN () clause, resulting in the use of Filesort

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.

+5
source share
1 answer

- B+. , by_id 1 post_on 0 by_id 1, . by_id 7 , _0 .

, 3 , , 1,2,4 by_id 1, 3,5 - by_id 10; MySQL 1,2,4,3,5 .

,

+6

All Articles