I have a review table which has, app_id(string), reviews_updated_at(timestamp), description(text)
and other stuff. The table has around 90 million entries, I have around 2000 read IOPS limit on my database instance and the below mentioned query takes 30-40 sec to complete, Is there any way i can make this query execute faster?.
I have two indexes app_id(btree)
, reviews_updated_at(btree)
Query:
select * from reviews
where app_id = '2332223'
order by review_updated_at
offset 200 limit 100
Query Plan:
Limit (cost=243270.84..364905.97 rows=100 width=258) (actual time=23212.698..32806.020 rows=100 loops=1)
-> Index Scan using index_reviews_on_review_updated_at on reviews (cost=0.57..327489222.63 rows=269239 width=258) (actual time=237.720..32805.359 rows=300 loops=1)
Filter: ((app_id)::text = '2332223'::text)
Rows Removed by Filter: 36376
Planning time: 0.160 ms
Execution time: 32806.216 ms
WHERE ap_id = 2332223
(and maybe your statistics are off)