mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
PERF: Replace posts reply_to_post_number index (#26385)
post_number is a sequence per topic, so it doesn't make sense to have an index on only reply_to_post_number without also including the topic_id.
This commit is contained in:

committed by
GitHub

parent
957b945d25
commit
cc8f0a79e2
35
db/migrate/20240327000440_replace_post_reply_index.rb
Normal file
35
db/migrate/20240327000440_replace_post_reply_index.rb
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ReplacePostReplyIndex < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
execute <<~SQL
|
||||
DROP INDEX CONCURRENTLY IF EXISTS "index_posts_on_topic_id_and_reply_to_post_number"
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS "index_posts_on_topic_id_and_reply_to_post_number"
|
||||
ON "posts" ("topic_id", "reply_to_post_number")
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
DROP INDEX CONCURRENTLY IF EXISTS "index_posts_on_reply_to_post_number"
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
execute <<~SQL
|
||||
DROP INDEX CONCURRENTLY IF EXISTS "index_posts_on_reply_to_post_number"
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS "index_posts_on_reply_to_post_number"
|
||||
ON "posts" ("reply_to_post_number")
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
DROP INDEX CONCURRENTLY IF EXISTS "index_posts_on_topic_id_and_reply_to_post_number"
|
||||
SQL
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user