---
title: "Partial Indexes: What They Let You Avoid Indexing"
description: "A partial index is valuable because of the rows it leaves out. The useful question is not whether it is faster, but what it stops the database from maintaining."
url: https://sqlpress.com/blog/partial-indexes-what-they-exclude/
category: PostgreSQL
tags: ["indexing", "query-optimization", "schema-design"]
author: "Elias Rowe"
published: 2026-11-15T00:00:00.000Z
measured: false
---

# Partial Indexes: What They Let You Avoid Indexing

## Key takeaways

- A partial index only contains rows matching its predicate, so rows outside it cost nothing to insert, update, or delete as far as that index is concerned.
- The planner must be able to prove the query predicate implies the index predicate, which is a stricter requirement than the two conditions looking similar.
- The strongest case is a small, hot working set inside a large table — a status that most rows pass through and leave.
- A unique partial index expresses conditional uniqueness — one active subscription per customer, any number of cancelled ones — which standard SQL has no other way to state.

## Test environment

- System: PostgreSQL 18
- System: SQL Server 2022
- System: SQLite 3.47
- Workload: Illustrative (examples verified, nothing timed)
- Notes: Predicate-implication behavior is described for PostgreSQL; SQL Server filtered indexes and SQLite are covered only as the equivalent features. The fifty-million-row jobs table is illustrative of the shape of the problem, not a measurement.

Partial indexes are usually introduced as a way to make an index smaller. That is
true and it is the less interesting half. The size reduction is a consequence; the
mechanism is that rows failing the predicate are not in the index at all, so they
generate no index maintenance.

## The shape of the good case

A `jobs` table holds fifty million rows. Forty-nine and a half million are
`completed` and will never be read again. The queue worker only ever asks for the
`pending` ones.

```sql title="partial.sql"
CREATE INDEX jobs_pending_idx
  ON jobs (created_at)
  WHERE status = 'pending';
```

The index contains a few thousand entries instead of fifty million. It fits in
cache, it is a shallow tree, and — the part that matters more — a job that is
inserted, processed, and completed touches this index exactly twice: once on
insert, once when it leaves `pending`. Every subsequent update to that row is
invisible to the index.

A full index on `(status, created_at)` would carry all fifty million entries and
would be updated on every write to an indexed column, forever.

## Which engines have it

That mechanism is not universal, and whether it is available at all decides how
much of what follows applies to you. PostgreSQL and SQLite both support partial
indexes with a `WHERE` clause, though they match them differently: PostgreSQL
proves the implication, while SQLite documents that it has no theorem prover and
matches by two simple syntactic rules instead. SQL Server calls them filtered
indexes and allows a narrower set of predicates. MySQL and MariaDB have no
equivalent feature; the nearest approximation is a functional index on an
expression that collapses uninteresting rows to `NULL`, which is a workaround
rather than the same thing.

## Why is a partial index not being used?

The planner will only use a partial index if it can prove the query's `WHERE`
clause implies the index predicate. Proof, not resemblance.

```sql title="proof.sql"
-- Uses the index: the predicate matches exactly.
WHERE status = 'pending' AND created_at < now()

-- Uses the index: 'pending' is provably one of these.
WHERE status IN ('pending') AND created_at < now()

-- Depends on the plan: a generic plan has no constant to reason about.
WHERE status = $1 AND created_at < now()
```

The third case is the common surprise, and it is conditional rather than absolute.
The documentation states it more strongly than the behavior warrants — it says
parameterized query clauses "do not work with a partial index" — and that holds for
a generic plan, which is built once for all parameter values, has no constant to
reason about, and cannot use the index at all. A custom plan is built from the
values supplied for that execution, so the planner sees `'pending'` and the proof
succeeds.

With `plan_cache_mode` at its default of `auto`, a prepared statement gets custom
plans for its first five executions and then a generic plan if its cost is not
enough higher to make replanning worthwhile — so the same statement behind an ORM
can use the index at first and quietly stop. `plan_cache_mode = force_custom_plan`
keeps the proof available, at the price of planning every execution.

An index the planner declines is more often [a row-estimate problem than an index
problem](/blog/index-not-used-estimate-not-index/). A partial index adds a second
and separate reason to be passed over, and it is the one the index definition
itself creates.

## Other uses that follow from the same mechanism

**Excluding nulls.** `WHERE deleted_at IS NULL` on a soft-delete table indexes only
live rows, and the query pattern almost always includes that condition anyway.

**Conditional uniqueness.** A unique partial index enforces uniqueness over a
subset — one active subscription per customer, while allowing any number of
cancelled ones. There is no other way to express that constraint in standard SQL.

```sql title="conditional-unique.sql"
CREATE UNIQUE INDEX one_active_subscription_per_customer
  ON subscriptions (customer_id)
  WHERE status = 'active';
```

## When is a partial index the wrong tool?

If the predicate matches most of the table, a partial index is a full index with
extra planning constraints. If the queries do not consistently carry the predicate,
the index will be used sometimes and ignored the rest of the time, and you now
maintain two indexes to cover one access pattern.

And if the excluded rows are genuinely queried — for reporting, for an admin view,
for a migration — you will end up adding the full index alongside it,
[ordered for whichever access pattern matters more](/blog/composite-index-column-order/),
at which point the partial one is redundant.

## Deciding in practice

Three questions, in order.

What fraction of the table matches the predicate? The smaller it is, the more
maintenance the index never performs, and the more the planning constraint is worth
accepting. When the predicate matches most of the table there is nothing left to
avoid, and the index should be a full one.

Do the queries that need it always carry the predicate as a literal or an inlinable
constant? If any important query parameterizes it, check the plan before committing
to the design rather than after; [what EXPLAIN ANALYZE reports for the statement
itself](/blog/explain-analyze-buffers/) names the index that was actually used.

Does the excluded set have its own access pattern? If it does, you are designing
two indexes, and it is better to know that at the start.

## FAQ

### What is a partial index in PostgreSQL?

A partial index contains only the rows that match its predicate. Rows failing the predicate are not in the index at all, so they cost nothing to insert, update or delete as far as that index is concerned. The smaller size is a consequence of that mechanism rather than the point of it: what the index does not have to maintain is the part that matters.

### Why is my PostgreSQL partial index not being used?

The planner uses a partial index only when it can prove that the query's WHERE clause implies the index predicate. Proof, not resemblance. Whether a parameterized query supplies that proof depends on which plan it gets: a custom plan is built from the actual parameter values and can prove the implication, while a generic plan is built without them and cannot. Under the default plan_cache_mode of auto, PostgreSQL uses custom plans for the first five executions of a prepared statement and then may switch to a generic one, so a partial index tuned for a specific literal can be used at first and stop being used later.

### When is a partial index the wrong choice?

When the predicate matches most of the table, a partial index is a full index with extra planning constraints. When the queries do not consistently carry the predicate, the index is used sometimes and ignored the rest of the time, leaving two indexes for one access pattern. And when the excluded rows are genuinely queried, the full index ends up alongside it and the partial one is redundant.

### Which databases support partial indexes?

PostgreSQL and SQLite support partial indexes with a WHERE clause. SQL Server calls them filtered indexes and allows a stricter set of predicates. MySQL and MariaDB have no equivalent; the nearest approximation is a functional index on an expression that collapses uninteresting rows to NULL, which is a workaround rather than the same feature.

## Sources

- [PostgreSQL 18 documentation — Partial Indexes](https://www.postgresql.org/docs/18/indexes-partial.html) (docs)
- [PostgreSQL 18 documentation — CREATE INDEX](https://www.postgresql.org/docs/18/sql-createindex.html) (docs)
- [PostgreSQL 18 documentation — PREPARE](https://www.postgresql.org/docs/18/sql-prepare.html) (docs) — plan_cache_mode, and the five-execution rule that decides custom versus generic plans.
- [SQL Server documentation — Create filtered indexes](https://learn.microsoft.com/en-us/sql/relational-databases/indexes/create-filtered-indexes) (docs) — The equivalent feature under a different name.
- [SQLite documentation — Partial Indexes](https://sqlite.org/partialindex.html) (docs) — Supported since 3.8.0; SQLite matches by two syntactic rules rather than by proof.
