From 045b3f2215034bc61b3d9f94a4e5f4c3c1bb09cc Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 22 Jul 2025 16:25:35 +0800 Subject: [PATCH] PERF: Create index `ON ai_topics_embeddings(topic_id, model_id)` This index helps to speed up queries that joins the `topics` table against the `ai_topics_embeddings` table on the `topic_id` column. There are a number of queries which filters on `ai_topics_embeddings.model_id` so we are including that in the index as well. --- ...0250722082515_add_index_to_ai_topics_embeddings.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/migrate/20250722082515_add_index_to_ai_topics_embeddings.rb diff --git a/db/migrate/20250722082515_add_index_to_ai_topics_embeddings.rb b/db/migrate/20250722082515_add_index_to_ai_topics_embeddings.rb new file mode 100644 index 000000000..b918d6547 --- /dev/null +++ b/db/migrate/20250722082515_add_index_to_ai_topics_embeddings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddIndexToAiTopicsEmbeddings < ActiveRecord::Migration[7.2] + def up + add_index :ai_topics_embeddings, %i[topic_id model_id] + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end