Cookbook recipe

Covering indexes with INCLUDE

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

A query filters on one column but also needs two more for output. Adding them as INCLUDE columns lets an index-only scan return everything without touching the heap. Diagnose it Add payload columns with INCLUDE, not…

Investigation Path

A query filters on one column but also needs two more for output. Adding them as INCLUDE columns lets an index-only scan return everything without touching the heap.

Diagnose it

Add payload columns with INCLUDE, not to the key:

CREATE INDEX idx_orders_customer
  ON orders (customer_id)
  INCLUDE (status, total);

Why it happens

Key columns affect ordering and uniqueness and bloat the b-tree. INCLUDE columns are stored only in leaf pages as payload, so the index can satisfy the SELECT list without a heap visit while keeping the key narrow.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes