0
0
DBMS Theoryknowledge~10 mins

Hash indexes in DBMS Theory - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Hash indexes
Start: Query with search key
Apply hash function to key
Compute hash value (bucket address)
Access bucket in hash index
Check bucket for matching record
Yes No
Return record
The flow shows how a hash index uses a hash function on a search key to find the bucket address, then accesses that bucket to find the matching record or report it missing.
Execution Sample
DBMS Theory
Search key = 42
Hash function: h(key) = key mod 5
Buckets: 0 to 4
Find bucket for key 42
Check bucket for record
This example shows how a hash function maps a search key to a bucket number to quickly locate the record.
Analysis Table
StepActionInputHash Function ResultBucket AccessedRecord Found?
1Receive search key42---
2Apply hash function4242 mod 5 = 2--
3Access bucket--Bucket 2-
4Search bucket for key--Bucket 2Yes
5Return record---Record with key 42
💡 Record found in bucket 2, search ends successfully
State Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
search_keyN/A42424242
hash_valueN/A2222
bucket_accessedN/AN/ABucket 2Bucket 2Bucket 2
record_foundN/AN/AN/AYesYes
Key Insights - 2 Insights
Why do we use a hash function on the search key?
The hash function converts the search key into a bucket number to quickly locate where the record might be stored, as shown in step 2 of the execution table.
What happens if the record is not found in the bucket?
If the record is not in the bucket, the search ends with no result. This is shown by the 'No' branch in the concept flow after checking the bucket.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the hash value computed for the search key 42?
A2
B5
C42
D0
💡 Hint
Check Step 2 in the execution table where the hash function result is shown.
At which step does the system access the bucket in the hash index?
AStep 4
BStep 1
CStep 3
DStep 5
💡 Hint
Refer to the 'Bucket Accessed' column in the execution table.
If the hash function changed to h(key) = key mod 3, which bucket would key 42 map to?
ABucket 1
BBucket 0
CBucket 2
DBucket 3
💡 Hint
Calculate 42 mod 3 and compare with the bucket numbers.
Concept Snapshot
Hash indexes use a hash function to convert a search key into a bucket address.
The bucket stores pointers to records with keys mapping to it.
Searching involves computing the hash, accessing the bucket, and checking for the record.
This method provides fast direct access but works best for equality searches.
Full Transcript
Hash indexes help databases find records quickly by using a hash function on the search key. The hash function converts the key into a bucket number. The system then looks inside that bucket to find the record. If the record is there, it returns it; if not, it reports no match. This process is fast because it avoids scanning many records. The example shows searching for key 42 using a hash function that takes the key modulo 5, resulting in bucket 2. The record is found in bucket 2, so the search ends successfully.