Imagine you have a large phone book and want to find a person's phone number quickly. How does a hash index help speed up this search in a database?
Think about how a locker system uses a code to find the exact locker without checking all lockers.
A hash index applies a hash function to the search key, which calculates the exact location where the data is stored. This direct access avoids scanning through all records, making retrieval very fast.
Which of the following is a known limitation of hash indexes in databases?
Think about whether you can find all phone numbers between 1000 and 2000 using a hash index.
Hash indexes are excellent for exact match queries but do not support range queries well because the hash function distributes keys randomly, losing any order information.
You have a database table with millions of user records. You want to quickly find a user by their unique ID. Which indexing method is best suited?
Consider which index type is optimized for exact matches on unique keys.
A hash index is ideal for exact match lookups on unique keys like user IDs because it provides direct access to the record without scanning or traversing a tree.
Hash indexes use hash functions to map keys to locations. What happens when two different keys produce the same hash value?
Think about what happens if two people have the same locker number in a locker system.
When two keys produce the same hash value, a collision occurs. The database must use techniques like chaining or open addressing to store both keys without losing data.
Consider a database with frequent exact match queries and occasional range queries on a large dataset. Which indexing strategy balances performance best?
Think about which index type is best for each query type and how combining them might help.
Hash indexes excel at exact matches but fail at range queries. B-tree indexes support both but are slower for exact matches. Combining both indexes allows optimized performance for each query type.