我有一个查询返回以下说明:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE this_ index_merge CategoryId,Deleted,PublishedOn,_ComputedDeletedValue,_Temporary_Flag,Published,_TestItemSessionGuid Deleted,_ComputedDeletedValue,_Temporary_Flag,Published 1,1,1,1 6203 Using intersect(Deleted,_ComputedDeletedValue,_Temporary_Flag,Published); Using where
这是否表明查询到处都在使用索引,还是可以通过添加其他索引来改进?基于此:http ://dev.mysql.com/doc/refman/5.1/en/explain-output.html ,它提到该key
列显示实际使用的索引。我对每一列都有一个索引。
有问题的查询如下:
SELECT SQL_NO_CACHE count(*) FROM
article this_
WHERE
(this_._Temporary_Flag = 0 OR this_._Temporary_Flag = NULL) AND
this_.Published = 1 AND
(this_.PublishedOn IS NULL OR this_.PublishedOn <= '2012-10-30 18:46:18 ') AND
(this_.Deleted = 0 OR this_.Deleted = NULL) AND
(this_._ComputedDeletedValue = 0 OR this_._ComputedDeletedValue = NULL) AND
((this_._TestItemSessionGuid IS NULL OR this_._TestItemSessionGuid = ''))
AND NOT (this_.CategoryId IS NULL)
表有大约 140,000 条记录。此查询需要 3 秒执行,并返回 135,725 作为结果。