# MEGATOPIC：公共福祉还是公共威胁？

**URL:** <https://meta.discourse.org/t/the-megatopic-public-good-or-public-menace/85592>\
**Category:** Community Building\
**Created:** [2018 年4 月 18 日 02:14 UTC](https://meta.discourse.org/t/the-megatopic-public-good-or-public-menace/85592 "2018-04-18T02:14:08Z")\
**Posts on this page:** 1\
**Showing post:** 36

<div class="post-metadata">

作者： ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
发布日期： [2020 年4 月 24 日 21:16 UTC](https://meta.discourse.org/t/the-megatopic-public-good-or-public-menace/85592/36 "2020-04-24T21:16:44Z")

</div>

这是我编写的一个数据探索器查询，试图回答你的问题。你可以用不同的主题和偏移量来尝试运行它。

```plaintext
-- [params]
-- int :topic_id = 107216
-- int :offset = 10000

SELECT "posts"."id" FROM "posts" 
WHERE ("posts"."deleted_at" IS NULL) 
AND "posts"."topic_id" = :topic_id
AND "posts"."post_type" IN (1,2,3) ORDER BY "posts"."sort_order" ASC LIMIT 20 
OFFSET :offset

```

下面是一个普通大小的主题和一个超大主题的例子：

```plaintext
示例耗时：3.4ms
  -> Index Scan using index_posts_on_topic_id_and_sort_order on posts (cost=0.43..1925.22 rows=477 width=8)

示例耗时：353.9ms, 739.6 ms（时间因数据库缓存情况而异）
  -> Index Scan using index_posts_on_topic_id_and_sort_order on posts (cost=0.43..605155.88 rows=161255 width=8)

```

我记得见过超过 750 毫秒的耗时。

以下是中位数和 99 百分位耗时。中位数耗时出人意料地好，但中位数的特性在于，你无法判断在 60% 百分位时情况是否比中位数案例糟糕得多。

 ![image](https://global.discourse-cdn.com/meta/original/3X/d/e/deafe2e4a3b3651cd6fb842168aa1013d9f927c5.png)

这是另一个服务器的数据（它拥有大量类别，这也导致了性能下降，因此如果不考虑巨型主题，这并非完全可比），但你可以看到其中位数性能提高了一倍，而最坏情况也改善了很多：

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/0/b0a28de429eca97bb7c4e51b95cae2ff8b68abb6.png)

---

_[View the full topic](https://meta.discourse.org/t/the-megatopic-public-good-or-public-menace/85592)._
