【发布时间】:2017-04-02 17:07:53
【问题描述】:
我正在 postgres 中编写查询以选择具有更多 cmets 的帖子。
以下工作,但我想知道它是否会成为许多帖子的性能问题。
查询:
SELECT
po.*,
(SELECT count(id) FROM comments WHERE post_id = po.id) AS comments_count
FROM posts AS po
ORDER BY comments_count DESC
LIMIT 10;
结果:
id title body comments_count
2 Foo Bar 5
1 Click Bait 4
我可以做些什么来提高此查询性能还是可以?
【问题讨论】:
标签: sql postgresql count sqlperformance