Skip to content

Added cop to blacklist the use of hash indexes

yorickpeterse-staging requested to merge rubocop-hash-index into master

What does this MR do?

This adds a Rubocop rule to prevent creating hash indexes using code such as add_concurrent_index :table, :column, using: :hash.

Why was this MR needed?

In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9546 a contributor added a hash index, which reminded me I was supposed to blacklist this a long time ago. Hash indexes are not recorded in the WAL and are discouraged by PostgreSQL. From the docs:

Caution Hash index operations are not presently WAL-logged, so hash indexes might need to be rebuilt with REINDEX after a database crash if there were unwritten changes. Also, changes to hash indexes are not replicated over streaming or file-based replication after the initial base backup, so they give wrong answers to queries that subsequently use them. For these reasons, hash index use is presently discouraged.

Does this MR meet the acceptance criteria?

Merge request reports