Alper Sarı

PostgreSQL 18 B-tree Skip Scan: Recheck Index Order Before Adding Another Index

A multicolumn B-tree index has traditionally been most useful when a query constrains its leading columns. PostgreSQL 18 adds skip-scan support for more cases: the planner may repeatedly probe a multicolumn index for distinct values of a leading column when that can avoid a full scan.

Suppose an index is ordered by (tenant_id, created_at). A query that filters only on created_at might have appeared to need a separate index. Skip scan can sometimes use the existing index by iterating over the distinct leading values and searching the later column. This is most attractive when the first column has relatively few distinct values. When it has many, repeated probes can cost more than a sequential scan or another index.

This is a planner opportunity, not a guarantee that the old index now serves every query. Check the plan on PostgreSQL 18 with current statistics and realistic row counts. Look for index scan choices, rows removed by filters, buffer reads, and estimated-versus-actual rows. Try the query with representative parameter values; skew across tenants or date ranges can change the planner’s decision.

Do not immediately delete a later-column index because a test query used skip scan once. Compare write overhead, index size, cache residency, and tail latency across the full workload. An index that accelerates one reporting query can make every insert and update more expensive.

The PostgreSQL 18 release notes describe skip-scan lookups as a way to use multicolumn B-tree indexes in more cases. The optimizer’s choice still depends on available statistics and estimated cost.