What are they?

Hash indices are a type of index that uses a hash table to store the index. The hash table is a data structure that stores key-value pairs. The key is the value of the indexed column, and the value is the pointer to the record in the table.

These are meant to store the index in memory, and they are very fast for lookups. They are used in databases to speed up queries that involve equality comparisons.

The problem with them is that they are not very good for range queries. If you want to find all the records that have a value between 10 and 20, you can’t use a hash index. Why not? Well, the hashing function is designed to spread the keys evenly across the hash table. This would mean that in order to find all elements in a certain range, the reads would not be sequential, but random. This is not efficient.

Further, since the data is actually stored in RAM, what happens when the computer is turned off? We lose the index.

This is why a hash index is used in tandem with a WAL - Write Ahead Log. This is a log that is written to disk every time a change is made to the database. This way, if the computer is turned off, the database can be restored to the last known state, by merely replaying the log.