我有一个评论表,其中有app_id(string), reviews_updated_at(timestamp), description(text)
和其他东西。该表拥有约9000万个条目,我的数据库实例有2000个读IOPS限制,下面提到的查询需要30-40秒才能完成,有什么办法可以使这个查询更快执行吗?日期时间排序非常缓慢postgresql
我有两个指标app_id(btree)
,reviews_updated_at(btree)
查询:
select * from reviews
where app_id = '2332223'
order by review_updated_at
offset 200 limit 100
查询计划:
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_is似乎是一个整数。删除引号 - >'WHERE ap_id = 2332223'(也许你的统计数据已关闭) – wildplasser
@DanBracuk what where子句?这些是我想要的记录。 – rajat