---
title: "Covering Indexes: INCLUDE Versus Adding Key Columns"
description: "Two ways to make an index answer a query without touching the table. They differ in ordering, index size, and what the engine can seek on."
url: https://sqlpress.com/blog/covering-indexes-include-versus-key/
category: SQL Fundamentals
tags: ["indexing", "query-optimization", "schema-design"]
author: "Elias Rowe"
published: 2026-11-08T00:00:00.000Z
measured: false
---

# Covering Indexes: INCLUDE Versus Adding Key Columns

## Key takeaways

- A covering index answers a query from the index alone, avoiding the lookup back into the table for every matching row.
- Key columns participate in ordering and seeking; INCLUDE columns are payload only, stored in the leaf pages and returned but never searched.
- Adding a column as a key when you only need it in the output makes the index larger at every level of the tree and constrains its ordering for no benefit.
- Covering is never free in either form: the column is duplicated into every index that carries it, and in PostgreSQL updating it also costs the row its heap-only-tuple eligibility.

## Test environment

- System: PostgreSQL 18
- System: SQL Server 2022
- System: MySQL 8.4
- Workload: Illustrative (examples verified, nothing timed)
- Notes: INCLUDE support and its absence in InnoDB are the engine-specific claims made here.

A key column is carried at every level of the index tree; an included column exists
only in the leaf. Both remove the same table lookup, so the choice between them
looks cosmetic — and it decides how much every unrelated lookup pays.

## What is the difference between INCLUDE and key columns?

**Key columns** are what the index is sorted by. They participate in seeking,
ordering, and uniqueness, and they appear in every level of the B-tree, including
the internal nodes that route a search.

**Included columns** — `INCLUDE (…)` in PostgreSQL 11 and later and in SQL Server —
are stored only in the leaf pages. They can be returned, but they cannot be
searched, they do not affect ordering, and they do not count toward the key.

```sql title="two-ways.sql"
-- Key columns: searchable, ordered, present at every tree level.
CREATE INDEX orders_customer_status_total_idx
  ON orders (customer_id, status, total_amount);

-- Included column: payload only, leaf pages only.
CREATE INDEX orders_customer_status_idx
  ON orders (customer_id, status) INCLUDE (total_amount);
```

Both let `SELECT total_amount FROM orders WHERE customer_id = ? AND status = ?`
finish without touching the table — and [which predicates the key can serve at all
follows from its column order](/blog/composite-index-column-order/). They are not
equivalent.

## Why the difference matters

The first version sorts by `total_amount` within each `(customer_id, status)` pair.
That is useful if you ever filter or order by it — and dead weight if you do not.
Because it is a key column, it is carried in the internal nodes too, making the
tree wider and, past a point, deeper. A deeper tree costs an extra page read on
every single lookup, including the ones that never reference the column.

The second version keeps the tree narrow. The value is present exactly where it is
needed, in the leaf, and nowhere else.

There is also a hard constraint, and the two engines draw it differently. SQL Server
does not count included columns toward its index key limits — 32 key columns and
1,700 bytes — so a wide output-only column that could never be a key can still be
carried. PostgreSQL counts `INCLUDE` columns toward its own 32-column limit, so the
exemption there is about tree navigation rather than about the limit.

## The cost neither version avoids

Covering is not free in either form. The column is duplicated: it exists in the
table and again in every index that includes it. Every update to that column now
writes to both places, and in PostgreSQL an update that modifies any column
referenced by an index disqualifies the row from the heap-only-tuple optimization,
which has its own throughput cost.

The failure mode is an index that covers a wide `SELECT` — six or eight included
columns to satisfy one query — and turns into a second copy of the table with the
write amplification to match. Cover the columns the query actually returns, not the
ones it might.

## Engine differences

**PostgreSQL** has supported `INCLUDE` on B-tree indexes since version 11. Covering
only pays off when the visibility map allows an index-only scan; without it the heap
fetch happens anyway and the extra columns bought nothing.

**SQL Server** treats included columns as the standard tool for eliminating key
lookups back to the table, and its documentation recommends moving every
non-searching column out of the key for exactly that reason.

**InnoDB** has no `INCLUDE`. Every column in a secondary index is a key column, and
every secondary index [implicitly carries the primary key](/blog/innodb-clustered-index/),
so an index on `(customer_id, status)` already covers a query that also selects
the primary key.
That implicit behavior is why covering in MySQL is often accidental.

## Which columns belong in INCLUDE and which in the key?

If the column is filtered on, ordered by, or needs to be unique, it is a key
column. If it only appears in the `SELECT` list, it is an included column. If it is
neither, leave it out and accept the table lookup — an index that covers everything
is a table with extra steps.

## FAQ

### What is the difference between INCLUDE and key columns in an index?

Key columns are what the index is sorted by. They participate in seeking, ordering and uniqueness, and they appear at every level of the B-tree, including the internal nodes that route a search. Included columns are stored only in the leaf pages: they can be returned by a query but never searched, and they do not affect ordering. SQL Server also excludes them from its index key size limits; PostgreSQL still counts them toward its 32-column limit.

### Does MySQL support INCLUDE columns in an index?

InnoDB has no INCLUDE. Every column in a secondary index is a key column, and every secondary index implicitly carries the primary key. An index on customer_id and status therefore already covers a query that also selects the primary key, which is why covering in MySQL is often accidental rather than designed. PostgreSQL added the INCLUDE clause in version 11; SQL Server has it as included or nonkey columns.

### Why doesn't my PostgreSQL covering index avoid reading the table?

In PostgreSQL, covering only pays off when the visibility map allows an index-only scan. Without that the heap fetch happens anyway, and the included columns bought nothing while still costing index size and extra writes. Included columns live in the leaf pages, so they are available exactly when the query can be satisfied from the index alone.

### What is the write cost of a covering index?

A covered column is duplicated: it exists in the table and again in every index that includes it, so every update to that column writes to both places. In PostgreSQL an update to any indexed column also disqualifies the row from the heap-only-tuple optimization, which carries its own throughput cost. An index covering six or eight columns becomes a second copy of the table with matching write amplification.

## Sources

- [PostgreSQL 18 documentation — Index-Only Scans and Covering Indexes](https://www.postgresql.org/docs/18/indexes-index-only-scans.html) (docs)
- [SQL Server documentation — Create indexes with included columns](https://learn.microsoft.com/en-us/sql/relational-databases/indexes/create-indexes-with-included-columns) (docs)
- [MySQL 8.4 Reference Manual — Clustered and Secondary Indexes](https://dev.mysql.com/doc/refman/8.4/en/innodb-index-types.html) (docs) — InnoDB has no INCLUDE; secondary indexes always carry the primary key.
- [PostgreSQL 18 documentation — CREATE INDEX](https://www.postgresql.org/docs/18/sql-createindex.html) (docs) — INCLUDE columns sit in leaf tuples, not in the upper-level entries used for tree navigation.
- [PostgreSQL 11 release notes](https://www.postgresql.org/docs/release/11.0/) (release notes) — The INCLUDE clause of CREATE INDEX was added in this release.
- [PostgreSQL 18 documentation — Heap-Only Tuples (HOT)](https://www.postgresql.org/docs/18/storage-hot.html) (docs) — An update that modifies a column referenced by an index is not eligible for HOT.
