discourse/app
Alan Guo Xiang Tan fe5cd479eb
PERF: Add index on topic_id and created_at to posts table (#22818)
Why this change?

In `PostDestroyer#make_previous_post_the_last_one` and
`Topic.reset_highest`, we have a query that looks something like this:

```
SELECT user_id FROM posts
WHERE topic_id = :topic_id AND
      deleted_at IS NULL AND
      post_type <> 4
      #{post_type}
ORDER BY created_at desc
LIMIT 1
```

However, we currently don't have an index that caters directly to this
query. As a result, we have seen this query performing poorly on large
sites if the PG planner ends up using an index that is suboptimal for
the query.

This commit adds an index to the `posts` table on `topic_id` and then
`created_at`. For the query above, PG will be able to do a backwards
index scan efficiently.
2023-07-27 10:55:10 +08:00
..
assets UX: Minor alignment fix for compact tag selector (#22810) 2023-07-26 14:13:39 -04:00
controllers FEATURE: Regenerate outdated summaries. (#22718) 2023-07-20 15:25:46 -03:00
helpers SECURITY: Don't reuse CSP nonce between requests (#22544) 2023-07-11 15:24:36 -06:00
jobs DEV: Replace raw comments with deprecation warnings (#22617) 2023-07-18 10:13:40 +08:00
mailers FIX: Order tags shown in email subject by topics count and name (#22586) 2023-07-13 15:39:58 +08:00
models PERF: Add index on topic_id and created_at to posts table (#22818) 2023-07-27 10:55:10 +08:00
serializers FIX: Seed all categories and tags configured as defaults for nav menu (#22793) 2023-07-27 10:52:33 +08:00
services FIX: Seed all categories and tags configured as defaults for nav menu (#22793) 2023-07-27 10:52:33 +08:00
views SECURITY: Don't reuse CSP nonce between requests (#22544) 2023-07-11 15:24:36 -06:00