1. Gyanastra
  2. Database Systems
  3. Static Hashing for Files
  4. Why Hash at All? The Problem It Solves
Free lesson, no account needed 4 min read

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:

OrganizationHow a record is foundTypical cost
Heap (unordered)Scan every blockbb block I/Os (worst and average)
Sequential (sorted on key)Binary search on blocks⌈log⁡2b⌉\lceil \log_2 b \rceil block I/Os
HashCompute address from the key1 block I/O (if no overflow)

Hashing aims for O(1)O(1) block accesses: the key itself tells you the address. No index, no search tree, no sorting.


The Core Vocabulary (define every symbol)

  • Search key kk: the attribute value used to place/find the record (e.g., EmpID).
  • Hash function hh: 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.
  • BB: the number of buckets in the file. This is fixed at file-creation time — that is what makes the hashing static.
  • ss: number of blocks per bucket (usually s=1s = 1; if a bucket spans ss blocks, capacity multiplies by ss). Not to be confused with bb = total blocks of the file in §1.
  • Bucket address: h(k) mod Bh(k) \bmod B, giving an integer in {0,1,…,B−1}\{0, 1, \dots, B-1\}.
  • rr: number of records currently stored in the file.
  • RR: number of records that fit in one block (blocking factor).
  • Capacity of the file: B×RB \times R records (for s=1s=1).
  • Load factor (loading factor) α=rB×R\alpha = \dfrac{r}{B \times R} — the fraction of slots used. (Some texts define α=r/B\alpha = r/B = 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 =h(k) mod B= h(k) \bmod B with buckets numbered 0…B−10 \ldots B-1 (0-based). Silberschatz–Korth–Sudarshan also use  mod B\bmod B but often write the bucket count as nn instead of BB; the formula is identical: h(k) mod nh(k) \bmod n. GATE almost always uses BB (or MM) with 0-based buckets. If a question numbers buckets 1…B1 \ldots B, the address is (h(k) mod B)+1(h(k) \bmod B) + 1 — same bucket, just relabelled.


The Static Hashing Method — Step by Step

Insertion of a record with key kk:

  1. Compute a=h(k) mod Ba = h(k) \bmod B.
  2. Go to bucket aa.
  3. If the bucket has a free slot, place the record there. Done — 1 block I/O.
  4. If the bucket is full, the record goes to an overflow location (see §4). This is an overflow record.

Search for key kk:

  1. Compute a=h(k) mod Ba = h(k) \bmod B.
  2. Read bucket aa (1 block I/O).
  3. Scan the records in the bucket. If found → done.
  4. 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 BB 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).


Pages 1–2 of 2