]> Untitled Git - lemmy.git/blob - migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/up.sql
881089293541622f1bc1cc1c6406aa3326ddc230
[lemmy.git] / migrations / 2023-01-17-165819_cleanup_post_aggregates_indexes / up.sql
1 -- Drop the old indexes
2 drop index idx_post_aggregates_newest_comment_time,
3   idx_post_aggregates_comments,
4   idx_post_aggregates_hot,
5   idx_post_aggregates_active,
6   idx_post_aggregates_score,
7   idx_post_aggregates_published;
8
9 -- All of the post fetching queries now start with either 
10 -- featured_local desc, or featured_community desc, then the other sorts.
11 -- So you now need to double these indexes
12
13 create index idx_post_aggregates_featured_local_newest_comment_time on post_aggregates (featured_local desc, newest_comment_time desc);
14 create index idx_post_aggregates_featured_community_newest_comment_time on post_aggregates (featured_community desc, newest_comment_time desc);
15
16 create index idx_post_aggregates_featured_local_comments on post_aggregates (featured_local desc, comments desc);
17 create index idx_post_aggregates_featured_community_comments on post_aggregates (featured_community desc, comments desc);
18
19 create index idx_post_aggregates_featured_local_hot on post_aggregates (featured_local desc, hot_rank(score, published) desc, published desc);
20 create index idx_post_aggregates_featured_community_hot on post_aggregates (featured_community desc, hot_rank(score, published) desc, published desc);
21
22 create index idx_post_aggregates_featured_local_active on post_aggregates (featured_local desc, hot_rank(score, newest_comment_time) desc, newest_comment_time desc);
23 create index idx_post_aggregates_featured_community_active on post_aggregates (featured_community desc, hot_rank(score, newest_comment_time) desc, newest_comment_time desc);
24
25 create index idx_post_aggregates_featured_local_score on post_aggregates (featured_local desc, score desc);
26 create index idx_post_aggregates_featured_community_score on post_aggregates (featured_community desc, score desc);
27
28 create index idx_post_aggregates_featured_local_published on post_aggregates (featured_local desc, published desc);
29 create index idx_post_aggregates_featured_community_published on post_aggregates (featured_community desc, published desc);
30