In databases containing millions of records, query performance is the difference between an application that loads in 5 milliseconds and one that crashes under load. An Index is an auxiliary data structure that allows the RDBMS storage engine to find rows in (O(\log N)) time, bypassing the costly Full Table Scan.
Figure 4.3: Anatomy of a Balanced B+ Tree index showing root page, branch routing, and leaf page row pointers.
| Feature | Clustered Index | Secondary (Non-Clustered) Index |
|---|---|---|
| Count Per Table | Only 1 per table (typically the Primary Key). | Multiple (dozens allowed). |
| Physical Storage | The leaf nodes ARE the actual table data rows! | Leaf nodes store key values + pointers to clustered keys. |
| Lookup Efficiency | Direct access in 3-4 disk block reads. | Secondary lookup + Index bookmark lookup to fetch extra columns. |
-- 1. Standard single-column index on email
CREATE INDEX idx_students_email ON students(email);
-- 2. Composite (Multi-Column) Index
-- Highly efficient for queries filtering by course AND gpa together!
CREATE INDEX idx_students_course_gpa ON students(course, gpa);
-- 3. Unique Index
CREATE UNIQUE INDEX idx_students_phone ON students(phone_number);
A Covering Index contains all columns requested by a SELECT query within the index structure itself. When a query is covered, the database reads the answer directly from the RAM buffer pool of the index without ever reading table data pages on disk!
Next, let us master transaction control and isolation levels using SQL Transactions & ACID!
An index is a specialized data structure (typically a balanced B+ Tree) maintained by the database that allows the query engine to locate matching rows in O(log N) time rather than scanning all N table records linearly on disk.
A Clustered Index dictates the physical on-disk sort order of the actual table rows (each table can have only ONE clustered index, typically the Primary Key). A Non-Clustered (Secondary) Index is a separate auxiliary structure containing index keys and pointers pointing back to the clustered row.
Indexes consume physical disk space and degrade the performance of INSERT, UPDATE, and DELETE statements because every write operation must also update all related index B-Trees.
Proceed to the next class in sequence to build production mastery of relational database architecture.
Continue to Class 46: Transactions & ACID → Previous: ← Views & Materialized Views | Full Syllabus
Diagnosing Index Scans, Index Seeks, and Table Scans.
How the primary key dictates physical table storage order.
Managing indexes across partitioned tables.
Why text search requires specialized Inverted Indexes.