我的表中有一个时间戳字段,我想选择
SELECT * FROM table
WHERE time BETWEEN '2014-12-06' AND '2014-12-09'我创建了这个索引
CREATE INDEX myindex ON table (time);该表包含1.014.890个条目
该查询在16秒内返回282.000条记录
解释
"Bitmap Heap Scan on trackdatagps (cost=6126.29..25884.11 rows=288188 width=79)"
" Recheck Cond: (("time" >= '2014-12-06 00:00:00'::timestamp without time zone)
AND
("time" <= '2014-12-09 00:00:00'::timestamp without time zone))"
" -> Bitmap Index Scan on table (cost=0.00..6054.24 rows=288188 width=0)"
" Index Cond: (("time" >= '2014-12-06 00:00:00'::timestamp without time zone)
AND
("time" <= '2014-12-09 00:00:00'::timestamp without time zone))"有没有办法加快速度呢?我觉得16秒太长了
发布于 2014-12-09 19:55:29
cluster table using myindex;这将运行缓慢(特别是在第一次),但它将组织表内容,使您使用的查询更有效。
特别是如果您使用较小的时间范围或有一个较大的表。
https://stackoverflow.com/questions/27377211
复制相似问题