I've been working on optimisations for a while now, but I really can't crack this one.
The query:
SELECT `field` FROM `table` WHERE `column_id` = 12341
The index:
ALTER TABLE `table`
ADD INDEX `column_id` (`column_id`);
Now the explain of the query (EXPLAIN SELECT field FROM table WHERE column_id = 12341
) shows me there are 50.000 rows.
However, in reality, there are only 20.000 rows with column_id = 12341.
- EXPLAIN shows me it's using the column_id index
- However, it shows me there are '50.000' rows
- In reality it's only 20.000 rows
- I know the EXPLAIN rows is an estimate, but this is such an easy index..
- This is an InnoDB
- I tried optimize table / analyze table..
Now this could be annoying since MySQL uses the number of rows estimation to pick the right indexes and it could end up picking up the wrong index, simply because of the wrong estimate.
Is there some indexing trick I don't know about?