PERF: drop idx_regular_post_search_data during migration

Rebuilding this index while amending the boolean is very expensive.

Avoid this work
This commit is contained in:
Sam Saffron 2020-08-20 12:48:12 +10:00
parent 4395e4d165
commit 628319aad3
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
1 changed files with 13 additions and 1 deletions

View File

@ -18,7 +18,7 @@ class UpdatePrivateMessageOnPostSearchData < ActiveRecord::Migration[6.0]
JOIN topics t ON t.id = p.topic_id
WHERE pd.private_message IS NULL OR
pd.private_message <> CASE WHEN t.archetype = 'private_message' THEN TRUE ELSE FALSE END
LIMIT 200000
LIMIT 3000000
) X
WHERE X.post_id = post_search_data.post_id
SQL
@ -34,6 +34,13 @@ class UpdatePrivateMessageOnPostSearchData < ActiveRecord::Migration[6.0]
end
def up
# must drop index cause we do not want an enormous amount of work done
# as we are changing data
execute <<~SQL
DROP INDEX IF EXISTS idx_regular_post_search_data
SQL
# Delete post_search_data of orphaned posts
execute <<~SQL
DELETE FROM post_search_data
@ -62,6 +69,11 @@ class UpdatePrivateMessageOnPostSearchData < ActiveRecord::Migration[6.0]
update_private_message_flag
change_column_null(:post_search_data, :private_message, false)
end
execute <<~SQL
CREATE INDEX CONCURRENTLY idx_regular_post_search_data
ON post_search_data USING GIN(search_data) WHERE NOT private_message
SQL
end
def down