The full answer
Dynamic partition pruning (DPP) lets Spark skip partitions of a large partitioned table using values that are only known when the query runs, typically the result of a filter on a small table it is joined to. Without it, a filter on the dimension table doesn't reduce what is read from the fact table, because the partition values aren't known when the query is planned.
The problem it solves
SELECT d.quarter, SUM(s.amount)
FROM sales s -- huge, partitioned by date_id
JOIN dates d ON s.date_id = d.date_id
WHERE d.quarter = 'Q1' -- filter only on the small table
GROUP BY d.quarter;
Static partition pruning only works when the filter is on the partition column itself, such as WHERE s.date_id BETWEEN .... Here the filter is on dates, so a plan without DPP reads every partition of sales and throws most rows away in the join.
How DPP fixes it
- Spark evaluates the filtered
datesside first. - It takes the distinct
date_idvalues that survive (those in Q1). - It applies them as a partition filter on the
salesscan, so only matching partition directories are listed and read.
When the small side is broadcast for the join, Spark reuses the same broadcast result for the pruning, so the extra work is almost free. In the physical plan you see a SubqueryBroadcast dynamicpruning node and, on the fact table's scan, PartitionFilters: [... dynamicpruningexpression(date_id IN dynamicpruning#..)].
Benefits
- Far less data read and fewer tasks: often a large fraction of a fact table's partitions are skipped in star-schema queries.
- Less shuffle and memory downstream, since fewer rows reach the join.
- No code change: it is on by default (
spark.sql.optimizer.dynamicPartitionPruning.enabled) since Spark 3.0.
When it applies
- The large table is partitioned by the join key.
- The join is an equi-join.
- The other side has a selective filter.
- The join type allows pruning that side (inner joins and left semi joins are the common cases).
- With default settings, the filtering side is broadcast so its result can be reused.
Related techniques For tables that aren't partitioned by the join key, Spark's runtime Bloom filters reduce the rows read from the other side of a shuffle join, and Delta Lake on Databricks adds dynamic file pruning, which skips individual files using their column statistics.
Last updated 16 October 2026
Sources