我在某些具有较大可能结果集的数据库查询中遇到性能问题。
有问题的查询,我AND
在WHERE子句中有三个
条款的顺序重要吗?
与之类似,如果我将ASI_EVENT_TIME子句放在第一位(因为这样会从所有子句中删除大部分结果。
这会改善查询的运行时间吗?
查询:
SELECT DISTINCT activity_seismo_info.*
FROM `activity_seismo_info`
WHERE
activity_seismo_info.ASI_ACTIVITY_ID IS NOT NULL AND
activity_seismo_info.ASI_SEISMO_ID IN (43,44,...,259) AND
(
activity_seismo_info.ASI_EVENT_TIME>='2011-03-10 00:00:00' AND
activity_seismo_info.ASI_EVENT_TIME<='2011-03-17 23:59:59'
)
ORDER BY activity_seismo_info.ASI_EVENT_TIME DESC
查询说明:
+----+-------------+---------+-------+---------------------------+--------------+---------+------+-------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------------------+--------------+---------+------+-------+-----------------------------+
| 1 | SIMPLE | act...o | range | act...o_FI_1,act...o_FI_2 | act...o_FI_1 | 5 | NULL | 65412 | Using where; Using filesort |
+----+-------------+---------+-------+---------------------------+--------------+---------+------+-------+-----------------------------+
使用:
PHP 5.2
MySQL 5.0.51a-3ubuntu5.4
推进1.3
Symfony 1.2.5
order by
属于数据库。