How number of items in IN clause relates to index usage

Viewed 370

I'm trying to optimize a query but I'm seeing a weird behavior I don't understand.

I have a table contains almost 2 million records, with an index on column "status_code" which is tinyint.

When I call the query with 10 numbers in In clause, mysql do a full table scan

select * from `table` as t
where t.code in (1,2,3,4,5,6,7,8,9,10);

full scan

When I call it with 9 numbers in the IN clause, the index is used.

select * from `table` as t
where t.code in (1,2,3,4,5,6,7,8,9);

index Note: Number of rows here is '9' although the query returns only 1 row.

I'm using Amazon RDS, I need to understand why is this behavior, and if there is any kind of configuration that controls this.

2 Answers
Related