+ -
当前位置:首页 → 问答吧 → 对于大表查询时间范围的一点疑问

对于大表查询时间范围的一点疑问

时间:2011-09-08

来源:互联网

我有一张 430W 数据的大表,这表 有create_time 的字段

查询语句 如下:

select pl.id,pl.data,pl.create_time from tbl_zb_point_log as pl where pl.create_time >= '2011-09-08 01:32:25' and pl.create_time <= '2011-09-08 01:39:25' and pl.point_id = 250;
就是时间区域为7分钟
费时 5.31S 
如果改成

select pl.id,pl.data,pl.create_time from tbl_zb_point_log as pl where pl.create_time >= '2011-09-08 01:32:25' and pl.create_time <= '2011-09-08 01:38:25' and pl.point_id = 250;

就是时间区域为6分钟。
费时 0.03S。

create_time point_id 都已经建立索引

请问 是什么原因 造成 这么大的差距?


最好能解释一下原理

作者: counter198   发布时间: 2011-09-08

你确认执行时没有缓存吗?

作者: wfevgch   发布时间: 2011-09-08

第一次已经把数据放到了内存 不需要再去读磁盘了

作者: rucypli   发布时间: 2011-09-08

贴出你的explain select pl.id,pl.data,pl.create_time from tbl_zb_point_log as pl where pl.create_time >= '2011-09-08 01:32:25' and pl.create_time <= '2011-09-08 01:38:25' and pl.point_id = 250; 

explain select pl.id,pl.data,pl.create_time from tbl_zb_point_log as pl where pl.create_time >= '2011-09-08 01:32:25' and pl.create_time <= '2011-09-08 01:39:25' and pl.point_id = 250;

show index from tbl_zb_point_log 

以供分析。


另外做对比的时候,建议同一语句至少执行三次以上来对比。

作者: ACMAIN_CHM   发布时间: 2011-09-08

(没有任何根据的)IMHO,第二句SQL的结果集是第一句结果集的子集,而且,相关索引已经加载过,只要筛选其子集即可。

作者: shine333   发布时间: 2011-09-08