concept Data & storage
Partition pruning versus row filtering
When a query range shares no values with a partition’s declared range, the database can skip that partition. An overlap keeps the partition in play, but individual rows can still fail the query’s filter.
What it means
A database can skip a whole partition when its declared bounds prove that none of its rows can satisfy the query predicate. If the bounds overlap the requested range, the partition stays under consideration. Row filtering answers the remaining question: which rows in that partition actually match? PostgreSQL 18: Partition pruning
Pruning is not an index scan. The bounds can rule out a partition without an index; how the database accesses a retained partition is a separate decision. PostgreSQL 18: Partition pruning
Try it
The synthetic table has one row for each integer x from 0 through 29. Its partitions are P0 [0,10), P1 [10,20), and P2 [20,30). Each range includes its lower bound but excludes its upper bound: 10 belongs to P1, not P0.
Partition pruning versus row filtering
Map synthetic ranges to partitions and evaluate compatible or incompatible predicates; show excluded partitions, retained partitions and residual row filtering.
Synthetic inputs only. This is not a measurement of your hardware or service.
A partition is excluded only when its half-open range has no intersection with the predicate. Rows inside retained partitions still need the predicate.
Exclude whole partitions; then filter retained rows
- Partitions excluded by range proof
- P0 · P2
- Partitions retained
- P1
- Rows satisfying the predicate
- 12 · 13 · 14 · 15 · 16 · 17
- Rows rejected inside retained partitions
- 10 · 11 · 18 · 19
| Partition | Inclusive lower | Exclusive upper |
|---|---|---|
| P0 | 0 | 10 |
| P1 | 10 | 20 |
| P2 | 20 | 30 |
Evaluated evidence
- Predicate proof supported by model
- plain-range
- Inclusive lower bound
- 12
- Exclusive upper bound
- 18
Synthetic complete integer rows0..29 and explicit plain-range proof. No indexes, optimizer, costs, null/default partitions or runtime pruning implementation are simulated.
About this model
Every input is local synthetic evidence. Numbers stay as raw text until this model validates them. The shown evaluated values come from the same result as the explanation.
Presets replace the entire scenario. Reset restores all starting fields, scenario selection and model state; it does not change the open or closed state of this help or article FAQ.
No external request, device command, stored-input history or measurement is performed.
Start with plain-range for Predicate proof supported by model, 12 for Inclusive lower bound, and 18 for Exclusive upper bound. That gives the predicate from 12 inclusive to 18 exclusive.
- Compare bounds. P0 ends before 12, and P2 starts at 20. Neither can contain a match, so the model prunes both without testing their rows. Only P1 overlaps the requested range.
- Filter rows inside P1. The matching values are 12, 13, 14, 15, 16, and 17. The filter rejects 10 and 11 because they are below 12. It also rejects 18 and 19 because the upper bound is exclusive. Those four rows are filtered out, not pruned with a partition.
Choose Cross a partition boundary to change the range to [9,11). Now 9 comes from P0 and 10 comes from P1. Both partitions must be retained even though only one row matches in each; P2 is still excluded.
Choose Inspect the evidence boundary to return to bounds 12 and 18 with unsupported-expression. The model has no rule establishing that this expression means the range from 12 inclusive to 18 exclusive. It retains all three partitions and reports unknown, without identifying matching or rejected rows. That is a limit of the model, not a prediction about an optimizer.
Enter bounds as whole-number decimal strings from -100 through 100. With plain-range, equal bounds describe an empty range and no partition is retained. Reversed bounds or a fractional entry such as 12.000000000000000001 are invalid: the model computes no result rather than swapping or rounding the bounds. Reset restores the default scenario and inputs, returns the step and virtual time to zero, and clears errors, history, and comparison.
In practice
When reading a PostgreSQL 18 plan, distinguish the rows a scan examines from the rows it emits after a filter. A small output count alone is not evidence that a whole partition was skipped. PostgreSQL 18: Using EXPLAIN
The simulation does not run SQL, choose a scan strategy, model planning or runtime pruning, or measure cost. Use the range comparison for the decision it supports: exclude a partition only if you can show that it cannot contain a match. For a partition that remains, use the predicate—not partition membership—to decide whether a row belongs in the result.
Frequently asked questions
Editorial questions based on the listed sources and explicitly labeled local examples.
Does pruning mean every retained row matches?
No. A partition can intersect the predicate while containing nonmatching rows. The example retains the 10–19 partition for a 12–17 query, then separately filters 10, 11, 18 and 19.
Is pruning an index scan?
No. Pruning proves whole partitions irrelevant from partition bounds and compatible predicates. A retained partition can still be accessed using a separate strategy, with or without an index.
What makes a predicate usable for pruning?
In this lab, it must be expressible as the supported integer range so it can be compared with the declared half-open partition bounds. An unsupported expression does not get an invented equivalence proof.
Does the example predict every optimizer plan?
No. The model does not parse SQL or emulate an optimizer’s planning/runtime phases. For unsupported predicates, it retains all partitions conservatively and marks pruning evidence unknown.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- Table partitioning
Partition pruning. Partition bounds can prove partitions irrelevant; retained partitions still require row evaluation. Pruning is not inherently an index scan.
Checked .
- PostgreSQL: Using EXPLAIN
Plan tree and scan/filter examples. A scan and its row filter are separate plan concepts: rows emitted by a node are not all rows examined.
Checked .