Covering Index (INCLUDE Columns)
Last updated: 2026-11-04
Covering Index (INCLUDE Columns)
A covering index adds extra read-only reference columns via INCLUDE. They do not participate in ordering, cannot be used for range lookups or unique constraints, but they are stored in full in the index leaf pages. When every column a query needs is available from the index, the planner can perform an Index Only Scan and never touch the heap, cutting IO dramatically. The distinction between index keys and INCLUDE columns shows up exactly here.
| Kind | index |
|---|---|
| Example Language | SQL |
📝 Syntax
CREATE INDEX <index_name> ON <table_name> ( <key_column> ) INCLUDE ( <included_column>, ... )
⚙️ Parameters
| index_name | Name of the new index. |
|---|---|
| table_name | The table to index. |
| index_key_column | The key column(s): they participate in ordering, serve equality and range lookups, and can back a unique constraint. |
| included_column | The INCLUDE columns: stored alongside the index but excluded from ordering, usable only as payload of an Index Only Scan, never for lookups. |
Returns:No return value. On success the command tag is CREATE INDEX.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
CREATE TABLE
INSERT 0 20000
CREATE INDEX
ANALYZE
-- First EXPLAIN: every needed column is in the index, so an Index Only Scan avoids the heap
Index Only Scan using idx_covering_email on idx_demo_covering (cost=0.29..8.30 rows=1 width=28)
Index Cond: (email = 'user42@example.com'::text)
Heap Fetches: 1
Index Searches: 1
Buffers: shared hit=1 read=2
Planning Time: 0.164 ms
Execution Time: 0.166 ms
-- Second EXPLAIN: selecting the non-included note column forces a heap visit, so it degrades to Index Scan
Index Scan using idx_covering_email on idx_demo_covering (cost=0.29..8.30 rows=1 width=38)
Index Cond: (email = 'user42@example.com'::text)
Index Searches: 1
Buffers: shared hit=3
Planning Time: 0.058 ms
Execution Time: 0.043 ms
(The EXPLAIN plans above come from a real PostgreSQL 18.6 run; actual time / Planning Time / Execution Time are indicative values and vary with machine load.)
📌 Key Points
- INCLUDE columns are payload only: they cannot serve equality or range lookups and cannot back a unique constraint — use a key column for that.
- An Index Only Scan needs the visibility map to mark pages all-visible, which normally requires VACUUM; that is why Heap Fetches is often non-zero.
- Covering indexes save the random IO of heap visits but cost more on writes, since every INSERT / UPDATE must also write the included columns into the index.
- INCLUDE arrived in PostgreSQL 11 and cannot merge several columns into a single structure the way some other databases' key clause does.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QHow does a covering index differ from putting every column in the key?
AKey columns participate in ordering and can be searched or sorted on, but they are expensive. INCLUDE columns are stored without ordering and can be returned along with the scan, but never searched. If you need lookup capability the column must be a key, which makes the index bigger and slower to maintain.
QWhy is my covering index not producing an Index Only Scan?
AUsually one of two things: the query also selects a column that is not INCLUDEd, so the plan degrades to Index Scan; or the table has not been vacuumed yet, so the visibility map is not set and Heap Fetches stays non-zero. Run VACUUM and check again.