Performance

Covering Indexes: Avoiding the Heap

SQL Mastery Team
April 23, 2026
6 min read

Welcome to **Day 92**. This is a true "Senior Developer" concept: the **Covering Index**.

The Hidden Cost: The "Table Lookup"

When you use an index to find a row, the database:

1. Finds the value in the index.

2. Gets the physical location of the row on disk (The "Heap").

3. **Goes to the disk** to fetch the other columns you asked for (e.g., `SELECT name`).

Step 3 is the slowest part.

The Solution: INCLUDE

What if we put the data directly **inside** the index?

CREATE INDEX idx_user_email_name

ON users (email)

INCLUDE (name); -- Only in modern DBs like Postgres/SQL Server

How it works: The Index-Only Scan

Now, if you run `SELECT name FROM users WHERE email = '...'`, the database finds the email, sees the `name` is right there in the index, and **never touches the actual table**.

This is the absolute fastest way to retrieve data in any SQL database.

Your Task for Today

Identify your most frequent "Small" query. Can you turn it into an Index-Only scan by including the columns in the index?

*Day 93: Why 'SELECT *' Kills Performance on Large Tables.*

Ready to put your knowledge into practice?

Join SQL Mastery and learn through interactive exercises.