MYSQL优化'IN'和'ORDER BY'

时间:2012-09-03 13:41:41

标签: mysql database

EXPLAIN 
    SELECT * FROM test_askcomment WHERE cid IN(1,2,3) ORDER BY dateline DESC;


id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  test_askcomment ALL PRIMARY NULL    NULL    NULL    3   Using where; Using filesort

1 个答案:

答案 0 :(得分:1)

ALTER TABLE `test_askcomment ` ADD INDEX `index1` (`cid`);

ALTER TABLE `test_askcomment ` ADD INDEX `index2` (`dateline `);

尝试索引您正在使用where子句的列或选择列