mirror of
https://github.com/discourse/discourse.git
synced 2026-08-05 18:57:20 -05:00
PERF: Add index_topics_on_category_id (#37022)
Joining the `topics` table against the `categories` table is a common thing we do and the missing index on the `category_id` foreign key is hurting performance on sites with lots of rows in the `topics` and `categories` tables.
This commit is contained in:
@@ -2304,6 +2304,7 @@ end
|
||||
# idxtopicslug (slug) WHERE ((deleted_at IS NULL) AND (slug IS NOT NULL))
|
||||
# index_topics_on_bannered_until (bannered_until) WHERE (bannered_until IS NOT NULL)
|
||||
# index_topics_on_bumped_at_public (bumped_at) WHERE ((deleted_at IS NULL) AND ((archetype)::text <> 'private_message'::text))
|
||||
# index_topics_on_category_id (category_id) WHERE ((deleted_at IS NULL) AND ((archetype)::text <> 'private_message'::text))
|
||||
# index_topics_on_created_at_and_visible (created_at,visible) WHERE ((deleted_at IS NULL) AND ((archetype)::text <> 'private_message'::text))
|
||||
# index_topics_on_external_id (external_id) UNIQUE WHERE (external_id IS NOT NULL)
|
||||
# index_topics_on_id_and_deleted_at (id,deleted_at)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
class AddIndexCategoryOnTopics < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
execute "DROP INDEX IF EXISTS index_topics_on_category_id;"
|
||||
execute "CREATE INDEX CONCURRENTLY index_topics_on_category_id ON topics (category_id) WHERE deleted_at IS NULL AND (archetype <> 'private_message');"
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user