When the subselect runs faster
A few weeks ago, we had a query optimization request from one of our customer.
The query was very simple like:
-
SELECT * FROM `table` WHERE (col1='A'||col1='B') ORDER BY id DESC LIMIT 20 OFFSET 0
This column in the table is looks like this:
-
`col1` enum('A','B','C','CD','DE','F','G','HI') default NULL
The table have 549252 rows and of course, there is an index on the col1. MySQL estimated the cardinality of that index as 87, though what was of course misleading as index cardinality in this case can't be over 9, as there is only 8(+ NULL) different possible values for this column.
-
+----+-------------+-------+-------+---------------+------+---------+------+--------+-----------------------------+
-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-
+----+-------------+-------+-------+---------------+------+---------+------+--------+-----------------------------+
-
| 1 | SIMPLE | table | range | col1 | col1 | 2 | NULL | 549252 | Using where; Using filesort |
-
+----+-------------+-------+-------+---------------+------+---------+------+--------+-----------------------------+
This query took more than 5 minutes (the rows are large and table does not fit in cache well)
[read more...]

29-30 Jul








del.icio.us
digg