2017-08-11 08:16:08 -04:00
|
|
|
# Hash Indexes
|
|
|
|
|
2019-08-12 06:29:10 -04:00
|
|
|
PostgreSQL supports hash indexes besides the regular btree
|
2017-08-11 08:16:08 -04:00
|
|
|
indexes. Hash indexes however are to be avoided at all costs. While they may
|
|
|
|
_sometimes_ provide better performance the cost of rehashing can be very high.
|
|
|
|
More importantly: at least until PostgreSQL 10.0 hash indexes are not
|
|
|
|
WAL-logged, meaning they are not replicated to any replicas. From the PostgreSQL
|
|
|
|
documentation:
|
|
|
|
|
|
|
|
> 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.
|
|
|
|
|
|
|
|
RuboCop is configured to register an offence when it detects the use of a hash
|
|
|
|
index.
|
|
|
|
|
|
|
|
Instead of using hash indexes you should use regular btree indexes.
|