From 0dd57a933ba2d0ae75db79a5c9d46008f9346d1f Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 22 Sep 2022 20:17:19 -0500 Subject: [PATCH] db: add indexes on comment fields. --- .../20220923010905_add_indexes_on_comments.rb | 11 ++++++ db/structure.sql | 38 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220923010905_add_indexes_on_comments.rb diff --git a/db/migrate/20220923010905_add_indexes_on_comments.rb b/db/migrate/20220923010905_add_indexes_on_comments.rb new file mode 100644 index 000000000..67d06be4c --- /dev/null +++ b/db/migrate/20220923010905_add_indexes_on_comments.rb @@ -0,0 +1,11 @@ +class AddIndexesOnComments < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def change + add_index :comments, :score, if_not_exists: true, algorithm: :concurrently + add_index :comments, :is_deleted, where: "is_deleted = true", if_not_exists: true, algorithm: :concurrently + add_index :comments, :is_sticky, where: "is_sticky = true", if_not_exists: true, algorithm: :concurrently + add_index :comments, :do_not_bump_post, where: "do_not_bump_post = true", if_not_exists: true, algorithm: :concurrently + add_index :comments, :updater_id, where: "updater_id IS NOT NULL", if_not_exists: true, algorithm: :concurrently + end +end diff --git a/db/structure.sql b/db/structure.sql index b9762d5fb..bfa3676c2 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3676,6 +3676,27 @@ CREATE INDEX index_comments_on_creator_id_and_created_at ON public.comments USIN CREATE INDEX index_comments_on_creator_id_and_post_id ON public.comments USING btree (creator_id, post_id); +-- +-- Name: index_comments_on_do_not_bump_post; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_comments_on_do_not_bump_post ON public.comments USING btree (do_not_bump_post) WHERE (do_not_bump_post = true); + + +-- +-- Name: index_comments_on_is_deleted; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_comments_on_is_deleted ON public.comments USING btree (is_deleted) WHERE (is_deleted = true); + + +-- +-- Name: index_comments_on_is_sticky; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_comments_on_is_sticky ON public.comments USING btree (is_sticky) WHERE (is_sticky = true); + + -- -- Name: index_comments_on_post_id; Type: INDEX; Schema: public; Owner: - -- @@ -3683,6 +3704,20 @@ CREATE INDEX index_comments_on_creator_id_and_post_id ON public.comments USING b CREATE INDEX index_comments_on_post_id ON public.comments USING btree (post_id); +-- +-- Name: index_comments_on_score; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_comments_on_score ON public.comments USING btree (score); + + +-- +-- Name: index_comments_on_updater_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_comments_on_updater_id ON public.comments USING btree (updater_id) WHERE (updater_id IS NOT NULL); + + -- -- Name: index_completed_user_upgrades_on_created_at; Type: INDEX; Schema: public; Owner: - -- @@ -6637,6 +6672,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220919041622'), ('20220920224005'), ('20220921022408'), -('20220922014326'); +('20220922014326'), +('20220923010905');