CodeOath
← All posts
SQL65 min total · 16 parts

Understanding SQL Indexes and Query Performance

Contents — Part 5 of 16: Covering Indexes
Part 5 of 16 · ~1 min

Covering Indexes

A covering index includes every column a specific query needs — either as part of the indexed key or as extra non-key "included" columns some engines support — so the engine can answer the query entirely from the index itself, with zero key lookups back to the table:

CREATE INDEX idx_dept_covering ON Employees (dept, name, salary);

SELECT dept, name, salary FROM Employees WHERE dept = 'Sales';
-- Now every column the query needs is already inside the index —
-- no trip back to the table row is required at all.

This is a real, measurable optimization on hot queries, but it isn't free either — a covering index duplicates more data than a narrow one, and every extra column widens the index and adds to the write cost described later in this reference. It's worth reaching for on a query that runs constantly and needs to be as fast as physically possible, not as a default habit for every index.