From fb926a1bd27ae2b1c9e66bb708e9ed3576698de3 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 27 Jun 2022 17:34:19 -0500 Subject: [PATCH] ai tags: replace tag_id index with (tag_id, score) index. Index on (tag_id, score) instead of (tag_id) to allow tags to be filtered and sorted by confidence more efficiently. This index takes up about the same amount of space as an index on tag_id alone, so including the score in the index is essentially free. --- ...20220627211714_add_tag_id_and_score_index_to_ai_tags.rb | 6 ++++++ db/structure.sql | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20220627211714_add_tag_id_and_score_index_to_ai_tags.rb diff --git a/db/migrate/20220627211714_add_tag_id_and_score_index_to_ai_tags.rb b/db/migrate/20220627211714_add_tag_id_and_score_index_to_ai_tags.rb new file mode 100644 index 000000000..c771e6393 --- /dev/null +++ b/db/migrate/20220627211714_add_tag_id_and_score_index_to_ai_tags.rb @@ -0,0 +1,6 @@ +class AddTagIdAndScoreIndexToAITags < ActiveRecord::Migration[7.0] + def change + add_index :ai_tags, [:tag_id, :score], if_not_exists: true + remove_index :ai_tags, :tag_id + end +end diff --git a/db/structure.sql b/db/structure.sql index bbf224757..489e59819 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3149,10 +3149,10 @@ CREATE INDEX index_ai_tags_on_score ON public.ai_tags USING btree (score); -- --- Name: index_ai_tags_on_tag_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_ai_tags_on_tag_id_and_score; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_ai_tags_on_tag_id ON public.ai_tags USING btree (tag_id); +CREATE INDEX index_ai_tags_on_tag_id_and_score ON public.ai_tags USING btree (tag_id, score); -- @@ -5975,6 +5975,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220504235329'), ('20220514175125'), ('20220525214746'), -('20220623052547'); +('20220623052547'), +('20220627211714');