CSC 480 · Database Management
Our notes
3 min readStorage 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
| Organisation | How | Good for | Bad for |
|---|---|---|---|
| Heap (unordered) | append at the end | fast inserts, full scans | searching (scan everything) |
| Sorted (sequential) | ordered on a key | range queries, binary search | inserts (must keep order) |
| Hashed | hash function on a key picks the bucket | exact-match lookups | ranges, 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)
| Operation | Heap | Sorted | B+ tree index | Hash index |
|---|---|---|---|---|
| Exact match on key | N/2 average | log₂N | height (2-4) | about 1 |
| Range | N | log₂N + matches | height + matches | N |
| Insert | 1 | N/2 (shifting) | height | about 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
-
Best pick PostgreSQL documentation: Introduction to indexes
(opens postgresql.org in a new tab)
-
B+ tree
(opens en.wikipedia.org in a new tab)
Wikipedia, B+ tree, CC BY-SA 4.0 · licence
-
Database index
(opens en.wikipedia.org in a new tab)
Wikipedia, Database index, CC BY-SA 4.0 · licence
Watch
-
Lec-107: Why Indexing is used | Indexing Beginning | DBMS
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
Lec-110: Types Of Indexes | Most Important Video on Indexing
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
5.29 B+ Tree Insertion | B+ Tree Creation example | Data Structure Tutorials
19 min · ≈ 86 MB · about ₦48
(opens youtube.com in a new tab)
-
#03 - Database Storage: Files & Pages ✸ Neon Database Talk (CMU Intro to Database Systems)
1 h 22 min · ≈ 369 MB · about ₦207
(opens youtube.com in a new tab)
-
#08 - Tree Indexes: B+Trees (CMU Intro to Database Systems)
1 h 22 min · ≈ 369 MB · about ₦207
(opens youtube.com in a new tab)
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.