Lecture: Lecture 14 - Physical Access to Data
Related: DBMS Architecture and Query Processing, Buffer Manager and Page Replacement, Clustered and Unclustered Indexes

The problem

SQL describes what result is needed. The DBMS still has to decide how to locate the relevant tuples on disk. Disk access is much slower than memory access, so the physical arrangement of pages and records strongly affects query performance.

The optimizer chooses a plan. The access method manager turns that plan into requests for database pages. A specialized access method understands one physical structure and asks the buffer manager to load the required pages.

Sequential structures

A heap file stores tuples in insertion order. It is simple and efficient for reading the entire file, but deletion and variable-size updates can leave unused space. An ordered sequential structure stores tuples according to a sort key. It supports ordered searches, sorting, grouping and some joins, but an insertion into the middle must preserve the order using free space, in-page reorganization or an overflow file.

Tree structures

A tree has one root, intermediate nodes and leaf nodes. Its large fan-out keeps the height small. A B-Tree and B+-Tree are balanced, meaning all leaves are equally far from the root, so access time is predictable.

A B+-Tree links its leaves in key order. To answer Grade BETWEEN 30 AND 40, the DBMS finds the first matching leaf and follows the links until it passes 40. This is why B+-Trees are especially useful for range queries and ordered output.

Hash structures

A hash function maps a key value to a block number. Hashing is direct and efficient for equality, such as StudentId = 50. Different keys can map to the same block, creating a collision. Hashing does not preserve key order, so it is inefficient for ranges and sorted scans.

Bitmap indexes

A bitmap index has one column for each distinct value and one row for each tuple. A cell is 1 when that tuple has that value and 0 otherwise. Bitwise operations can combine predicates quickly. This works well for low-cardinality attributes such as department or status. With many distinct values, the matrix becomes large.

Choosing a structure

Query needSuitable structure
Read most or all rowsHeap or sequential file
Search and return values in orderOrdered file or B+-Tree
Exact equality on a keyHash index or B+-Tree
Range of ordered valuesB+-Tree
Boolean conditions on a few categoriesBitmap index

Retrieval questions

Why is a B+-Tree better than hashing for a range? Its linked leaves preserve key order, while hashing sends values to locations without an order.

What is a collision? Two different hash keys map to the same block, so the structure needs a way to store both.

Why is a heap file useful for a full scan? Records can be read page by page without maintaining a sorted arrangement.