UNIHIVE

Study Hub UNIPORT CSC 480

CSC 480 · Database Management

Storage structures and access strategies

Disks and pages, the buffer, file organisations (heap, sorted, hashed), primary, secondary and clustered indexes, B+ trees, hashing, cost of access, and how indexes help queries.

Our notes

3 min read

Storage hierarchy

Cache and RAM (fast, volatile) → SSD/disk (persistent, much slower) → backup media. Databases read and write in blocks (pages), typically 4-16 KB. The cost of a query is mostly the number of page reads.
The buffer manager keeps recently used pages in memory (replacement policies like LRU), so repeated reads avoid the disk.

Records and pages

Fixed- or variable-length records are packed into pages; a record is located by a record id (page number + slot).

File organisations

OrganisationHowGood forBad for
Heap (unordered)append at the endfast inserts, full scanssearching (scan everything)
Sorted (sequential)ordered on a keyrange queries, binary searchinserts (must keep order)
Hashedhash function on a key picks the bucketexact-match lookupsranges, ordering

Indexes

An index is an extra structure that finds rows by a search key without scanning the whole table (like the index at the back of a textbook).

  • Primary index: on the ordering key of a sorted file.
  • Clustered index: the table's rows are stored in index order (InnoDB stores each table clustered by its primary key).
  • Secondary index: on another attribute; points to rows (there can be many).
  • Dense (an entry for every record) or sparse (an entry per page).
  • Composite index: on several columns (dept_code, level); usable for queries on the leading column(s).

B+ trees

The standard index structure. Balanced tree; all data pointers at the leaf level; leaves linked for range scans; each node is one page holding many keys (high fan-out), so the tree is shallow.
Worked example. With 200 keys per node, a tree of height 3 indexes up to 200³ = 8 million keys: any one is found in 3 page reads (often 1-2, since upper levels stay in the buffer).
Insertions split full nodes; deletions merge or redistribute; the tree stays balanced.

Hashing

Static hashing uses a fixed number of buckets (overflow chains when full). Extendible and linear hashing grow the number of buckets as data grows. Hash indexes give about one page read for an exact match but cannot do ranges.

Access cost comparison (N pages)

OperationHeapSortedB+ tree indexHash index
Exact match on keyN/2 averagelog₂Nheight (2-4)about 1
RangeNlog₂N + matchesheight + matchesN
Insert1N/2 (shifting)heightabout 1

Example. A 100,000-page table: a heap search averages 50,000 page reads; binary search on a sorted file about 17; a B+ tree of height 3 about 3.

Using indexes wisely

Index columns used in WHERE, JOIN and ORDER BY on large tables (mat_no, course_code). Indexes slow inserts and updates and use space, so avoid indexing everything. Queries that wrap the column in a function (WHERE YEAR(date) = 2025) or start a LIKE with % usually cannot use the index. EXPLAIN shows whether the optimiser uses one.

Exams usually ask: compare heap, sorted and hashed files; primary, secondary, clustered, dense and sparse indexes; B+ tree structure, search and insertion with splits; static versus dynamic hashing; estimate page reads for a query.

Common mistake: saying more indexes always make a database faster. Reads may speed up, but every insert, update and delete must also update each index.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 480 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.