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!