我有一个来自单个表的非常简单的查询(三个条件;两个等于,一个介于两者之间),在MySQL查询浏览器中,查询运行时间不到半秒,返回8300条记录。如果我使用MySQL数据连接器(实际上只是一个OLEDB包装器)运行完全相同的查询,大约需要35秒。
查询是:
select drh_data.reading_time, drh_data.raw_value, drh_data.float_value, drh_data.data_quality
from drh_data
where drh_data.site_id=202
and drh_data.device_id=7
and reading_time between '2009-04-08 11:15:01' and '2009-05-08 11:15:02'
order by drh_data.reading_time desc;
有什么想法吗?
更新:我终于抽出时间检查了CPU使用情况(正如一位回答者所建议的那样),发现我的应用程序使用了50%的CPU时间。运行MySQL(在CentOS中)的VirtualPC盒子在这20秒左右的时间里没有0%,所以问题都在客户端。我还对查询进行了解释,结果如下:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE drh_data range PRIMARY,idx_site_device_reading_receive idx_site_device_reading_receive 11 7674 Using where
我在这里累坏了。有人有办法解决这个问题吗?我即将通过LIMIT打破选择,但我认为我不应该这样做。