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.

Kindindex
Example LanguageSQL

📝 Syntax

CREATE INDEX <index_name> ON <table_name> ( <key_column> ) INCLUDE ( <included_column>, ... )

⚙️ Parameters

index_nameName of the new index.
table_nameThe table to index.
index_key_columnThe key column(s): they participate in ordering, serve equality and range lookups, and can back a unique constraint.
included_columnThe 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏