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.
This commit is contained in:
evazion
2022-06-27 17:34:19 -05:00
parent ab7462a42d
commit fb926a1bd2
2 changed files with 10 additions and 3 deletions

View File

@@ -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

View File

@@ -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');