forked from e621ng/e621ng
[DB] Improve performance of some wildcard text searches
Comments are consistently timing out. The others don't necessarily need this, but it improves performance nevertheless
This commit is contained in:
parent
0efe3defed
commit
2cd96817b0
17
db/migrate/20230517155547_add_text_wildcard_search_index.rb
Normal file
17
db/migrate/20230517155547_add_text_wildcard_search_index.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class AddTextWildcardSearchIndex < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
add_gin_index :blips, :body
|
||||
add_gin_index :comments, :body
|
||||
add_gin_index :dmails, :body
|
||||
add_gin_index :forum_posts, :body
|
||||
add_gin_index :forum_topics, :title
|
||||
add_gin_index :notes, :body
|
||||
add_gin_index :user_feedback, :body
|
||||
add_gin_index :wiki_pages, :body
|
||||
add_gin_index :wiki_pages, :title
|
||||
end
|
||||
|
||||
def add_gin_index(table, column)
|
||||
execute("CREATE INDEX index_#{table}_on_lower_#{column}_trgm ON #{table} USING gin ((lower(#{column})) gin_trgm_ops)")
|
||||
end
|
||||
end
|
@ -3424,6 +3424,13 @@ CREATE INDEX index_bans_on_expires_at ON public.bans USING btree (expires_at);
|
||||
CREATE INDEX index_bans_on_user_id ON public.bans USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_blips_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_blips_on_lower_body_trgm ON public.blips USING gin (lower((body)::text) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_blips_on_to_tsvector_english_body; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -3487,6 +3494,13 @@ CREATE INDEX index_comments_on_creator_id_and_post_id ON public.comments USING b
|
||||
CREATE INDEX index_comments_on_creator_ip_addr ON public.comments USING btree (creator_ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_comments_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_comments_on_lower_body_trgm ON public.comments USING gin (lower(body) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_comments_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -3529,6 +3543,13 @@ CREATE INDEX index_dmails_on_is_deleted ON public.dmails USING btree (is_deleted
|
||||
CREATE INDEX index_dmails_on_is_read ON public.dmails USING btree (is_read);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_dmails_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_dmails_on_lower_body_trgm ON public.dmails USING gin (lower(body) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_dmails_on_owner_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -3599,6 +3620,13 @@ CREATE UNIQUE INDEX index_forum_post_votes_on_forum_post_id_and_creator_id ON pu
|
||||
CREATE INDEX index_forum_posts_on_creator_id ON public.forum_posts USING btree (creator_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_forum_posts_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_forum_posts_on_lower_body_trgm ON public.forum_posts USING gin (lower(body) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_forum_posts_on_to_tsvector_english_body; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -3662,6 +3690,13 @@ CREATE INDEX index_forum_topics_on_creator_id ON public.forum_topics USING btree
|
||||
CREATE INDEX index_forum_topics_on_is_sticky_and_updated_at ON public.forum_topics USING btree (is_sticky, updated_at);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_forum_topics_on_lower_title_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_forum_topics_on_lower_title_trgm ON public.forum_topics USING gin (lower((title)::text) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_forum_topics_on_to_tsvector_english_title; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -3753,6 +3788,13 @@ CREATE INDEX index_note_versions_on_updater_ip_addr ON public.note_versions USIN
|
||||
CREATE INDEX index_notes_on_creator_id_and_post_id ON public.notes USING btree (creator_id, post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_notes_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_notes_on_lower_body_trgm ON public.notes USING gin (lower(body) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_notes_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -4195,6 +4237,13 @@ CREATE INDEX index_user_feedback_on_creator_id ON public.user_feedback USING btr
|
||||
CREATE INDEX index_user_feedback_on_creator_ip_addr ON public.user_feedback USING btree (creator_ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_feedback_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_feedback_on_lower_body_trgm ON public.user_feedback USING gin (lower(body) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_feedback_on_to_tsvector_english_body; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -4279,6 +4328,20 @@ CREATE INDEX index_wiki_page_versions_on_updater_ip_addr ON public.wiki_page_ver
|
||||
CREATE INDEX index_wiki_page_versions_on_wiki_page_id ON public.wiki_page_versions USING btree (wiki_page_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_wiki_pages_on_lower_body_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_wiki_pages_on_lower_body_trgm ON public.wiki_pages USING gin (lower(body) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_wiki_pages_on_lower_title_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_wiki_pages_on_lower_title_trgm ON public.wiki_pages USING gin (lower((title)::text) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_wiki_pages_on_other_names; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -4640,6 +4703,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20230314170352'),
|
||||
('20230316084945'),
|
||||
('20230506161827'),
|
||||
('20230513074838');
|
||||
('20230513074838'),
|
||||
('20230517155547');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user