SQL Indexes & B-Tree Internals: Architecture & Optimization

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.

B+ Tree Index Internal Data Structure showing Root, Branches, and Leaves

Figure 4.3: Anatomy of a Balanced B+ Tree index showing root page, branch routing, and leaf page row pointers.


Clustered Index vs Secondary (Non-Clustered) Index

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.

Creating Indexes in SQL

-- 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);

The Covering Index Optimization

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!

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!