]> Untitled Git - lemmy.git/commitdiff
Update post_aggregates indexes to account for featured_local and featured_community...
authorDessalines <dessalines@users.noreply.github.com>
Fri, 20 Jan 2023 17:44:03 +0000 (12:44 -0500)
committerGitHub <noreply@github.com>
Fri, 20 Jan 2023 17:44:03 +0000 (12:44 -0500)
- Fixes #2660

migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/down.sql [new file with mode: 0644]
migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/up.sql [new file with mode: 0644]

diff --git a/migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/down.sql b/migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/down.sql
new file mode 100644 (file)
index 0000000..d91843e
--- /dev/null
@@ -0,0 +1,22 @@
+-- Drop the new indexes
+drop index idx_post_aggregates_featured_local_newest_comment_time,
+  idx_post_aggregates_featured_community_newest_comment_time,
+  idx_post_aggregates_featured_local_comments,
+  idx_post_aggregates_featured_community_comments,
+  idx_post_aggregates_featured_local_hot,
+  idx_post_aggregates_featured_community_hot,
+  idx_post_aggregates_featured_local_active,
+  idx_post_aggregates_featured_community_active,
+  idx_post_aggregates_featured_local_score,
+  idx_post_aggregates_featured_community_score,
+  idx_post_aggregates_featured_local_published,
+  idx_post_aggregates_featured_community_published;
+
+-- Create the old indexes
+create index idx_post_aggregates_newest_comment_time on post_aggregates (newest_comment_time desc);
+create index idx_post_aggregates_comments on post_aggregates (comments desc);
+create index idx_post_aggregates_hot on post_aggregates (hot_rank(score, published) desc, published desc);
+create index idx_post_aggregates_active on post_aggregates (hot_rank(score, newest_comment_time) desc, newest_comment_time desc);
+create index idx_post_aggregates_score on post_aggregates (score desc);
+create index idx_post_aggregates_published on post_aggregates (published desc);
+
diff --git a/migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/up.sql b/migrations/2023-01-17-165819_cleanup_post_aggregates_indexes/up.sql
new file mode 100644 (file)
index 0000000..8810892
--- /dev/null
@@ -0,0 +1,30 @@
+-- Drop the old indexes
+drop index idx_post_aggregates_newest_comment_time,
+  idx_post_aggregates_comments,
+  idx_post_aggregates_hot,
+  idx_post_aggregates_active,
+  idx_post_aggregates_score,
+  idx_post_aggregates_published;
+
+-- All of the post fetching queries now start with either 
+-- featured_local desc, or featured_community desc, then the other sorts.
+-- So you now need to double these indexes
+
+create index idx_post_aggregates_featured_local_newest_comment_time on post_aggregates (featured_local desc, newest_comment_time desc);
+create index idx_post_aggregates_featured_community_newest_comment_time on post_aggregates (featured_community desc, newest_comment_time desc);
+
+create index idx_post_aggregates_featured_local_comments on post_aggregates (featured_local desc, comments desc);
+create index idx_post_aggregates_featured_community_comments on post_aggregates (featured_community desc, comments desc);
+
+create index idx_post_aggregates_featured_local_hot on post_aggregates (featured_local desc, hot_rank(score, published) desc, published desc);
+create index idx_post_aggregates_featured_community_hot on post_aggregates (featured_community desc, hot_rank(score, published) desc, published desc);
+
+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);
+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);
+
+create index idx_post_aggregates_featured_local_score on post_aggregates (featured_local desc, score desc);
+create index idx_post_aggregates_featured_community_score on post_aggregates (featured_community desc, score desc);
+
+create index idx_post_aggregates_featured_local_published on post_aggregates (featured_local desc, published desc);
+create index idx_post_aggregates_featured_community_published on post_aggregates (featured_community desc, published desc);
+