I have this simple query in pg
EXPLAIN ANALYZE
select * from email_events
where act_owner_id = 500
order by date desc
limit 500
The first query execution take very long time about 7 seconds.
"Limit (cost=0.43..8792.83 rows=500 width=2311) (actual time=3.064..7282.497 rows=500 loops=1)"
" -> Index Scan Backward using email_events_idx_date on email_events (cost=0.43..233667.36 rows=13288 width=2311) (actual time=3.059..7282.094 rows=500 loops=1)"
" Filter: (act_owner_id = 500)"
" Rows Removed by Filter: 1053020"
"Total runtime: 7282.818 ms"
After the first execution the query i guess is cached and goes in 20-30 ms.
Why the LIMIT is so slow when there is no cache? How can i fix this?
act_owner_id + date
(in this order). – kordirko Feb 21 at 20:12