Database Systems · Static Hashing for Files
Why Hash at All? The Problem It Solves
A file is stored on disk as a collection of blocks (pages). To find a record, the DBMS must know which block holds it. Three classic organizations:
| Organization | How a record is found | Typical cost |
|---|---|---|
| Heap (unordered) | Scan every block | block I/Os (worst and average) |
| Sequential (sorted on key) | Binary search on blocks | block I/Os |
| Hash | Compute address from the key | 1 block I/O (if no overflow) |
Hashing aims for block accesses: the key itself tells you the address. No index, no search tree, no sorting.
The Core Vocabulary (define every symbol)
- Search key : the attribute value used to place/find the record (e.g.,
EmpID). - Hash function : a function mapping a key to an integer. It must be uniform (spread keys evenly) and deterministic (same key → same value always).
- Bucket: one or more disk blocks that hold records. In the simplest model 1 bucket = 1 block.
- : the number of buckets in the file. This is fixed at file-creation time — that is what makes the hashing static.
- : number of blocks per bucket (usually ; if a bucket spans blocks, capacity multiplies by ). Not to be confused with = total blocks of the file in §1.
- Bucket address: , giving an integer in .
- : number of records currently stored in the file.
- : number of records that fit in one block (blocking factor).
- Capacity of the file: records (for ).
- Load factor (loading factor) — the fraction of slots used. (Some texts define = average records per bucket; both appear — see §6.)
Convention note (exam-relevant). Elmasri–Navathe and most GATE questions use 1 bucket = 1 block and address with buckets numbered (0-based). Silberschatz–Korth–Sudarshan also use but often write the bucket count as instead of ; the formula is identical: . GATE almost always uses (or ) with 0-based buckets. If a question numbers buckets , the address is — same bucket, just relabelled.
The Static Hashing Method — Step by Step
Insertion of a record with key :
- Compute .
- Go to bucket .
- If the bucket has a free slot, place the record there. Done — 1 block I/O.
- If the bucket is full, the record goes to an overflow location (see §4). This is an overflow record.
Search for key :
- Compute .
- Read bucket (1 block I/O).
- Scan the records in the bucket. If found → done.
- If not found and the bucket has an overflow chain, follow the chain, reading each overflow block until found or chain ends.
Deletion: find as above, remove the record; if it was in overflow, unlink it from the chain.
Key property: the number of buckets never changes. As records are added, buckets fill and overflow grows — this is the fatal weakness of static hashing (fixed in dynamic hashing: extendible and linear hashing, a separate topic).