Partial Index (Index with a WHERE Predicate)

Last updated: 2026-11-04

Partial Index (Index with a WHERE Predicate)

A partial index stores only the rows that satisfy its WHERE predicate, which makes it far smaller than a full index. It pays off when queries only ever touch a subset of the table — say unarchived orders or passing grades. The catch: the query predicate must imply the index predicate, otherwise the planner will not use it.

Kindindex
Example LanguageSQL

📝 Syntax

CREATE INDEX <index_name> ON <table_name> ( <column> ) WHERE <index_predicate>

⚙️ Parameters

index_nameName of the new index.
table_nameThe table to index.
column_nameThe indexed column; entries are created only for rows satisfying the WHERE predicate.
index_conditionThe predicate deciding which rows enter the index. Query predicates must imply it for the index to be chosen.

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

-- EXPLAIN: the query predicate score >= 80 implies the index predicate, so the index is used
Aggregate  (cost=84.33..84.34 rows=1 width=8)
  ->  Bitmap Heap Scan on idx_demo_partial  (cost=4.60..84.23 rows=40 width=0)
        Recheck Cond: ((customer_id = 7) AND (score >= 80))
        Heap Blocks: exact=39
        Buffers: shared hit=39 read=2
        ->  Bitmap Index Scan on idx_partial_high  (cost=0.00..4.59 rows=40 width=0)
  Index Cond: (customer_id = 7)
  Index Searches: 1
  Buffers: shared hit=2
Planning Time: 0.389 ms
Execution Time: 0.210 ms

-- Query result
 count 
-------
    39
(1 row)

(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

QWhy does the planner ignore my partial index?
AUsually the query predicate does not imply the index predicate. The index holds only rows with score >= 80; a query without that restriction could match rows the index does not contain, so the planner gives up. Add the same condition to the query.
QHow does a unique partial index differ from a plain partial index?
AA unique partial index enforces uniqueness only on the rows it covers. The classic case is requiring unique e-mail addresses only for live rows: CREATE UNIQUE INDEX ON users (email) WHERE deleted_at IS NULL, which lets historical rows keep duplicate addresses.
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%

🙏 帮我们做得更好

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

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