From 87de8948c0719d259a5420ca707c4520474b0e88 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 21 Aug 2020 07:21:34 +0800 Subject: [PATCH] DEV: Drop search index on non-pm posts. The problem with this index is that on sites with a high non-pm to pm posts ratio, the index is esstentially duplicating the existing index on `PostSearchData#search_data`. If the site is huge, the index ends up taking up more diskspace. --- ...200820232017_drop_idx_regular_post_search_data.rb | 11 +++++++++++ ...329_update_private_message_on_post_search_data.rb | 12 ------------ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20200820232017_drop_idx_regular_post_search_data.rb diff --git a/db/migrate/20200820232017_drop_idx_regular_post_search_data.rb b/db/migrate/20200820232017_drop_idx_regular_post_search_data.rb new file mode 100644 index 00000000000..c61920c6a7c --- /dev/null +++ b/db/migrate/20200820232017_drop_idx_regular_post_search_data.rb @@ -0,0 +1,11 @@ +class DropIdxRegularPostSearchData < ActiveRecord::Migration[6.0] + def up + execute <<~SQL + DROP INDEX CONCURRENTLY IF EXISTS idx_regular_post_search_data + SQL + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/post_migrate/20200818084329_update_private_message_on_post_search_data.rb b/db/post_migrate/20200818084329_update_private_message_on_post_search_data.rb index 225a4a4cb1e..cab2c49ebf4 100644 --- a/db/post_migrate/20200818084329_update_private_message_on_post_search_data.rb +++ b/db/post_migrate/20200818084329_update_private_message_on_post_search_data.rb @@ -34,13 +34,6 @@ 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 CONCURRENTLY IF EXISTS idx_regular_post_search_data - SQL - # Delete post_search_data of orphaned posts execute <<~SQL DELETE FROM post_search_data @@ -69,11 +62,6 @@ 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