mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-02 06:48:58 +08:00
In some pathological cases on the tag intersection route
for topics, when querying across multiple tags, the SQL query
planner can choose a suboptimal plan that results in a
sequential scan of the topic_tags table instead of using
the existing topic_id, tag_id index.
```
-> Parallel Seq Scan on topic_tags t2 (cost=0.00..23043.22 rows=13618 width=4) (actual time=0.031..54.114 rows=10535 loops=3)
Filter: (tag_id = 58)
Rows Removed by Filter: 579415
```
This resulted in a very slow query. Adding this extra
index allows us to hint the query planner to use a more
efficient plan by filtering using the tag ID first _then_ the topic ID.
|
||
|---|---|---|
| .. | ||
| fixtures | ||
| migrate | ||
| post_migrate | ||
| api_test_seeds.rb | ||