0
0
PostgreSQLquery~5 mins

Hash index for equality in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a hash index in PostgreSQL?
A hash index is a type of database index that uses a hash function to map keys to a location. It is optimized for fast equality comparisons, meaning it quickly finds rows where a column equals a specific value.
Click to reveal answer
beginner
When should you use a hash index in PostgreSQL?
Use a hash index when you need very fast lookups for equality comparisons (e.g., WHERE column = value). It is not suitable for range queries or sorting.
Click to reveal answer
beginner
How do you create a hash index on a column named 'username' in PostgreSQL?
You use the command: <br>CREATE INDEX idx_username_hash ON tablename USING hash (username);<br>This creates a hash index on the 'username' column.
Click to reveal answer
intermediate
What is a limitation of hash indexes in PostgreSQL compared to B-tree indexes?
Hash indexes only support equality comparisons and cannot be used for range queries or sorting. Also, before PostgreSQL 10, hash indexes were not WAL-logged, so they were not crash-safe.
Click to reveal answer
beginner
How does PostgreSQL use a hash index during a query?
When a query has a condition like WHERE column = value, PostgreSQL can use the hash index to quickly find the matching rows by hashing the value and looking up the location directly.
Click to reveal answer
What type of queries are hash indexes in PostgreSQL best suited for?
ARange queries (e.g., WHERE column > value)
BFull text search
CSorting results
DEquality comparisons (e.g., WHERE column = value)
Which command creates a hash index on the 'email' column of a table named 'users'?
ACREATE INDEX idx_email_hash ON users USING btree (email);
BCREATE INDEX idx_email_hash ON users USING hash (email);
CCREATE INDEX idx_email_hash ON users (email);
DCREATE HASH INDEX idx_email ON users (email);
Before PostgreSQL 10, what was a major drawback of hash indexes?
AThey were not crash-safe because they were not WAL-logged
BThey could not be created on text columns
CThey were slower than sequential scans
DThey supported only range queries
Can a hash index be used to speed up queries with 'WHERE column > value'?
ANo, hash indexes only support equality comparisons
BYes, hash indexes support all comparison operators
CYes, but only if combined with a B-tree index
DNo, but they support sorting
Which of the following is true about hash indexes in PostgreSQL?
AThey support full text search
BThey are the default index type
CThey use a hash function to map keys to locations
DThey automatically maintain sorted order
Explain what a hash index is and when you would use it in PostgreSQL.
Think about how hash indexes help find exact matches quickly.
You got /4 concepts.
    Describe the limitations of hash indexes compared to B-tree indexes in PostgreSQL.
    Consider what queries hash indexes cannot optimize.
    You got /4 concepts.