Covering Indexes and Index-Only Scans Explained
Make queries faster with covering indexes: answer queries from the index alone, INCLUDE columns in PostgreSQL and SQL Server, and the visibility map.
Published November 27, 2026
An index usually helps the database find rows, but it still has to visit the table to fetch the columns you selected. A covering index contains every column the query needs, so the database never touches the table at all. For hot queries this can cut I/O dramatically, especially when the table rows are wide.
The concept
When a query uses a secondary index, each matching index entry leads to a lookup of the full row: a key lookup in InnoDB or SQL Server, a heap fetch in PostgreSQL. If the query returns 5,000 rows, that is up to 5,000 extra random page reads. When the index itself contains all referenced columns (in WHERE, SELECT, ORDER BY and JOIN), those lookups disappear. MySQL reports "Using index" and PostgreSQL shows "Index Only Scan".
You can make an index covering by adding columns to the key, or, in PostgreSQL 11+ and SQL Server, with an INCLUDE clause that stores extra columns only in the leaf entries without making them part of the sort key. INCLUDE columns keep the tree smaller and do not affect uniqueness.
Without a covering index
With a covering index
The I/O difference
PostgreSQL and the visibility map
PostgreSQL index entries do not store transaction visibility information, so an index-only scan must confirm each row is visible to the current transaction. It checks the visibility map: if a page is marked all-visible, no heap visit is needed. Recently modified pages force heap fetches until VACUUM marks them visible again. EXPLAIN ANALYZE shows this as "Heap Fetches", and a high number means autovacuum is not keeping up.
Practical examples
Covering with INCLUDE (PostgreSQL / SQL Server)
Search on customer and date, return total without touching the table.
CREATE INDEX idx_orders_cust_created_incl
ON orders (customer_id, created_at DESC) INCLUDE (total, status);
EXPLAIN ANALYZE
SELECT created_at, total, status FROM orders
WHERE customer_id = 42 ORDER BY created_at DESC LIMIT 50;
-- Index Only Scan using idx_orders_cust_created_incl ... Heap Fetches: 0Covering in MySQL
MySQL has no INCLUDE; add columns to the end of the key. InnoDB secondary indexes already contain the primary key.
CREATE INDEX idx_orders_cover ON orders (customer_id, created_at, total, status);
EXPLAIN SELECT id, created_at, total, status FROM orders WHERE customer_id = 42;
-- Extra: Using indexFast COUNT with a narrow index
Counting via a small index reads far fewer pages than scanning the table.
CREATE INDEX idx_orders_status ON orders (status);
SELECT count(*) FROM orders WHERE status = 'pending'; -- index-onlyCommon mistakes
- SELECT * everywhere, which makes covering indexes impossible.
- Adding every column to an index to make it covering, creating a second copy of the table.
- Ignoring Heap Fetches in PostgreSQL plans and blaming the index instead of vacuum.
- Adding large TEXT or JSON columns to INCLUDE, bloating the index.
Key takeaways
- A covering index holds every column the query references.
- It removes per-row table lookups: "Using index" or "Index Only Scan".
- Use INCLUDE for non-key columns where supported.
- Select only the columns you need so covering is possible.
FAQ
Does the primary key count toward covering in InnoDB?
Yes. Every InnoDB secondary index entry includes the primary key, so selecting the primary key does not break coverage.
When are covering indexes not worth it?
For rarely run queries, write-heavy tables, or when the extra columns are large. Reserve them for hot, latency-sensitive queries.
Can a covering index be unique?
Yes. In PostgreSQL, CREATE UNIQUE INDEX ... (email) INCLUDE (name) enforces uniqueness on email only.