当我使用以下查询时,响应时间真的很糟糕(有时超过一分钟!)。
select * from cdr where start_time < now() - interval '4 hours' and final = 0 limit 50
我正在尝试获取 final=0 且开始时间超过 4 小时的记录。以下是我在桌子上的索引:
CREATE INDEX "cdr_Final_ix"
ON cdr
USING btree
(start_time , final );
以下是解释分析:
"Limit (cost=0.00..167.81 rows=50 width=188) (actual time=64491.409..64650.635 rows=11 loops=1)"
" -> Seq Scan on cdr (cost=0.00..749671.06 rows=223372 width=188) (actual time=64491.407..64650.625 rows=11 loops=1)"
"Filter: ((final = 0) AND (start_time < (now() - '04:00:00'::interval)))"
"Total runtime: 64650.690 ms"
任何帮助将不胜感激。谢谢,阿里