From 78892e623969572c52dfc23a19daa64e476791b2 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 26 Jan 2021 19:24:18 -0600 Subject: [PATCH] posts: add index on rating column. Should improve performance for rating:e and rating:q searches. Rating:s isn't isn't indexed because Postgres is unlikely to use the index for rating:s searches (the selectivity is too low, ~77% of all posts are rating:s). --- db/migrate/20210127012303_add_rating_index_to_posts.rb | 5 +++++ db/structure.sql | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210127012303_add_rating_index_to_posts.rb diff --git a/db/migrate/20210127012303_add_rating_index_to_posts.rb b/db/migrate/20210127012303_add_rating_index_to_posts.rb new file mode 100644 index 000000000..0a2394cce --- /dev/null +++ b/db/migrate/20210127012303_add_rating_index_to_posts.rb @@ -0,0 +1,5 @@ +class AddRatingIndexToPosts < ActiveRecord::Migration[6.1] + def change + add_index :posts, :rating, where: "rating != 's'" + end +end diff --git a/db/structure.sql b/db/structure.sql index bcb289cfd..8b19ec044 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -7239,6 +7239,13 @@ CREATE INDEX index_posts_on_parent_id ON public.posts USING btree (parent_id) WH CREATE INDEX index_posts_on_pixiv_id ON public.posts USING btree (pixiv_id) WHERE (pixiv_id IS NOT NULL); +-- +-- Name: index_posts_on_rating; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_posts_on_rating ON public.posts USING btree (rating) WHERE (rating <> 's'::bpchar); + + -- -- Name: index_posts_on_source_trgm; Type: INDEX; Schema: public; Owner: - -- @@ -7948,6 +7955,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210110090656'), ('20210115015308'), ('20210123112752'), -('20210127000201'); +('20210127000201'), +('20210127012303');