When I use the following query, the response time is really terrible(sometimes over a minute!).
select * from cdr where start_time < now() - interval '4 hours' and final = 0 limit 50
I am trying to get records where the final=0 and the starttime is over 4 hours old. the following is the index I have on the table:
CREATE INDEX "cdr_Final_ix"
ON cdr
USING btree
(start_time , final );
The following is the explain analyze:
"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"
Any help would be Greatly appreciated. Thanks, Ari
order byWHERE final=0) I get sstill get index scans, results in sub-millisecond times, with normal index 100--200 ms, with about 2.5M rows UPDATE: I'll post as an answer.