我的表中有一个时间戳字段,想要选择
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条记录
EXPLAIN
"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秒太长了
答案 0 :(得分:0)
cluster table using myindex;
运行缓慢(特别是第一次),但它会组织表格内容,使您使用的查询更有效。
特别是如果你使用较小的时间范围或有更大的表格。