diff options
Diffstat (limited to 'lib/gitlab/database/reindexing/concurrent_reindex.rb')
-rw-r--r-- | lib/gitlab/database/reindexing/concurrent_reindex.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/gitlab/database/reindexing/concurrent_reindex.rb b/lib/gitlab/database/reindexing/concurrent_reindex.rb index fd3dca88567..a6fe7d61a4f 100644 --- a/lib/gitlab/database/reindexing/concurrent_reindex.rb +++ b/lib/gitlab/database/reindexing/concurrent_reindex.rb @@ -59,6 +59,13 @@ module Gitlab raise ReindexError, "failed to reindex #{index}: #{message}" end + # Some expression indexes (aka functional indexes) + # require additional statistics. The existing statistics + # are tightly bound to the original index. We have to + # rebuild statistics for the new index before dropping + # the original one. + rebuild_statistics if index.expression? + yield replacement_index ensure begin @@ -96,6 +103,14 @@ module Gitlab end end + def rebuild_statistics + logger.info("rebuilding table statistics for #{index.schema}.#{index.tablename}") + + connection.execute(<<~SQL) + ANALYZE #{quote_table_name(index.schema)}.#{quote_table_name(index.tablename)} + SQL + end + def replacement_index_name @replacement_index_name ||= "#{TEMPORARY_INDEX_PREFIX}#{index.indexrelid}" end |