I am finding ORDER BY to be quite slow in cases where it uses filesort (as shown by EXPLAIN)
Good, fast query:
mysql> EXPLAIN SELECT uid FROM iwantu_profile_1_1 WHERE profile_updated > 1032717646 ORDER BY profile_updated LIMIT 0,30;
+--------------------+-------+---------------------+---------------------+---------+------+--------+------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------------------+-------+---------------------+---------------------+---------+------+--------+------------+
| iwantu_profile_1_1 | range | idx_profile_updated | idx_profile_updated | 4 | NULL | 717033 | where used |
+--------------------+-------+---------------------+---------------------+---------+------+--------+------------+
Now look how it changes to use filesort if I make it order by DESC instead:
mysql> EXPLAIN SELECT uid FROM iwantu_profile_1_1 WHERE profile_updated > 1032717646 ORDER BY profile_updated DESC LIMIT 0,30;
+--------------------+-------+---------------------+---------------------+---------+------+--------+----------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------------------+-------+---------------------+---------------------+---------+------+--------+----------------------------+
| iwantu_profile_1_1 | range | idx_profile_updated | idx_profile_updated | 4 | NULL | 717033 | where used; Using filesort |
+--------------------+-------+---------------------+---------------------+---------+------+--------+----------------------------+
Or if I add anything else into the WHERE clause:
mysql> EXPLAIN SELECT uid FROM iwantu_profile_1_1 WHERE profile_updated > 1032717646 AND profile_gender=1 ORDER BY profile_updated DESC LIMIT
0,30;
+--------------------+------+----------------------------------------+--------------------+---------+-------+--------+----------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra
|
+--------------------+------+----------------------------------------+--------------------+---------+-------+--------+----------------------------+
| iwantu_profile_1_1 | ref | idx_profile_updated,idx_profile_gender | idx_profile_gender | 4 | const | 548368 | where used; Using filesort |
+--------------------+------+----------------------------------------+--------------------+---------+-------+--------+----------------------------+
my field definitions are:
| uid | mediumint(8) unsigned | | MUL | 0 | |
| profile_updated | int(10) unsigned | | MUL | 0 | |
| profile_gender | int(1) | | MUL | 0 | |
ANY help or comments that could help me would be appreciated!
Thanks, Keith
--
Keith Bussey <kbussey@wisol.com>
Chief Tech. Manager - WISOL.com
(514) 398-9994 ext.225