<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Dynamic_partition_pruning</id>
	<title>Dynamic partition pruning - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Dynamic_partition_pruning"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Dynamic_partition_pruning&amp;action=history"/>
	<updated>2026-12-06T00:07:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Dynamic_partition_pruning&amp;diff=143&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Dynamic_partition_pruning&amp;diff=143&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:40Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Dynamic partition pruning&lt;br /&gt;
| also_known_as   = DPP, runtime partition pruning&lt;br /&gt;
| field           = Query optimization&lt;br /&gt;
| key_parts       = Partitioned fact table, filtered dimension table, equi-join key on a partition column, broadcast reuse or a pruning subquery&lt;br /&gt;
| implementations = [[Apache Spark]] (since 3.0.0), [[Apache Iceberg]] and other Data Source V2 connectors through runtime filtering&lt;br /&gt;
| related         = [[Partition pruning]], [[Runtime filter]], [[Broadcast join]], [[Predicate pushdown]], [[Star schema]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (PartitionPruning.scala, PlanDynamicPruningFilters.scala, CleanupDynamicPruningFilters.scala, DynamicPruning.scala, joins.scala, predicates.scala, SQLConf.scala, SupportsRuntimeV2Filtering.java), Spark JIRA SPARK-11150, and the Apache Iceberg 1.12.0 Spark source}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Dynamic partition pruning&amp;#039;&amp;#039;&amp;#039; (DPP) is a query optimization in [[Apache Spark]] that skips partitions of a table using filter values that are only known while the query runs, typically the join keys that survive a filter on the other side of a join. It targets star-schema queries, where a large fact table partitioned by a key is joined to a small, filtered dimension table. DPP was added in Spark 3.0.0 (SPARK-11150) and is on by default.&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-11150 |title=SPARK-11150: Dynamic partition pruning |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why is dynamic partition pruning needed? ==&lt;br /&gt;
Static [[partition pruning]] needs the filter on the partitioned table itself. In a star-schema query the filter is on the dimension table, and the fact table is constrained only through the join:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- sales is partitioned by date_key; dim_date is small&lt;br /&gt;
SELECT d.calendar_month, SUM(s.amount)&lt;br /&gt;
FROM sales s&lt;br /&gt;
JOIN dim_date d ON s.date_key = d.date_key&lt;br /&gt;
WHERE d.is_holiday = true&lt;br /&gt;
GROUP BY d.calendar_month;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Without DPP, Spark reads every partition of &amp;lt;code&amp;gt;sales&amp;lt;/code&amp;gt; and discards non-holiday rows at the join. With DPP, Spark first evaluates the filtered &amp;lt;code&amp;gt;dim_date&amp;lt;/code&amp;gt;, collects its &amp;lt;code&amp;gt;date_key&amp;lt;/code&amp;gt; values, and scans only the &amp;lt;code&amp;gt;sales&amp;lt;/code&amp;gt; partitions with those keys.&lt;br /&gt;
&lt;br /&gt;
== How does dynamic partition pruning work in Apache Spark? ==&lt;br /&gt;
DPP is an optimizer rule, &amp;lt;code&amp;gt;PartitionPruning&amp;lt;/code&amp;gt;. When a join has an equality condition between a partition column on one side and a column on the other side, the rule inserts a &amp;lt;code&amp;gt;DynamicPruningSubquery&amp;lt;/code&amp;gt; filter on the partitioned side. The subquery holds the filtering side of the join, and Spark decides during physical planning how to run it.&amp;lt;ref name=&amp;quot;rule&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala |title=PartitionPruning.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
# If the join is planned as a [[broadcast join|broadcast hash join]], Spark reuses the broadcast of the filtering side as the pruning filter, so the dimension table is read only once.&lt;br /&gt;
# Otherwise, if the estimated benefit outweighs the cost of running the filtering side twice, Spark keeps a separate subquery.&lt;br /&gt;
# Otherwise, Spark drops the pruning filter.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PlanDynamicPruningFilters.scala |title=PlanDynamicPruningFilters.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the defaults, step 2 does not happen. &amp;lt;code&amp;gt;spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly&amp;lt;/code&amp;gt; is true, so DPP applies only when a broadcast exchange can be reused.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt; In practice DPP depends on the dimension side being small enough to broadcast.&lt;br /&gt;
&lt;br /&gt;
The benefit estimate compares the size of the partitioned side after pruning with the size of the filtering side. It uses column statistics when they exist (&amp;lt;code&amp;gt;spark.sql.optimizer.dynamicPartitionPruning.useStats&amp;lt;/code&amp;gt;, default true) and otherwise a fallback filter ratio (&amp;lt;code&amp;gt;spark.sql.optimizer.dynamicPartitionPruning.fallbackFilterRatio&amp;lt;/code&amp;gt;, default 0.5).&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== When does dynamic partition pruning apply? ==&lt;br /&gt;
The rule at Spark 4.3.0 inserts a pruning filter only when all of the following are true:&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
* The join condition contains an equality (&amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt;) between the two sides.&lt;br /&gt;
* The key on the pruned side traces back to a partition column of a file source or Hive table, or to an attribute that a Data Source V2 scan accepts for runtime filtering.&lt;br /&gt;
* The join type allows pruning that side. Inner and left semi joins can prune either side; a left outer join can prune only its right side, and a right outer join only its left side.&amp;lt;ref name=&amp;quot;joins&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala |title=joins.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* The filtering side is not a streaming plan, and it contains a predicate that is likely to be selective (a comparison, &amp;lt;code&amp;gt;IN&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LIKE&amp;lt;/code&amp;gt;, a string predicate and similar) or a small input that is already materialized.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala |title=predicates.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== When does dynamic partition pruning not apply? ==&lt;br /&gt;
Common reasons a star join gets no DPP:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The fact table is not partitioned on the join key.&amp;#039;&amp;#039;&amp;#039; DPP prunes partitions, not files or row groups. Joins on non-partition columns can use a [[runtime filter]] instead.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The dimension side has no selective filter.&amp;#039;&amp;#039;&amp;#039; Without a filter, every key survives, so there is nothing to prune.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The dimension side is not broadcast.&amp;#039;&amp;#039;&amp;#039; With &amp;lt;code&amp;gt;reuseBroadcastOnly&amp;lt;/code&amp;gt; at its default (true), a sort-merge join gets no DPP.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The join type is wrong for the side.&amp;#039;&amp;#039;&amp;#039; For example, the preserved side of an outer join (the left side of a left outer join) cannot be pruned.&amp;lt;ref name=&amp;quot;joins&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The filtering side is non-deterministic.&amp;#039;&amp;#039;&amp;#039; If the filtering plan is non-deterministic, Spark replaces the dynamic predicate with &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; before physical planning.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DPP is turned off&amp;#039;&amp;#039;&amp;#039; with &amp;lt;code&amp;gt;spark.sql.optimizer.dynamicPartitionPruning.enabled=false&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What does dynamic partition pruning look like in a plan? ==&lt;br /&gt;
In the physical plan, the scan of the partitioned table lists the dynamic filter in its &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt;, wrapped in &amp;lt;code&amp;gt;dynamicpruningexpression(...)&amp;lt;/code&amp;gt;. With broadcast reuse, the filter refers to a &amp;lt;code&amp;gt;SubqueryBroadcast&amp;lt;/code&amp;gt; node that reads the broadcast built for the join, and the reuse rule turns the duplicate broadcast exchange into a &amp;lt;code&amp;gt;ReusedExchange&amp;lt;/code&amp;gt; node.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/reuse/ReuseExchangeAndSubquery.scala |title=ReuseExchangeAndSubquery.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/DynamicPruning.scala |title=DynamicPruning.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/SubqueryBroadcastExec.scala |title=SubqueryBroadcastExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; After the query runs, the scan&amp;#039;s &amp;lt;code&amp;gt;number of partitions read&amp;lt;/code&amp;gt; metric in the Spark UI&amp;#039;s SQL tab shows how many partitions were read.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala |title=DataSourceScanExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dynamic partition pruning with table formats ==&lt;br /&gt;
Data Source V2 tables take part in DPP through the &amp;lt;code&amp;gt;SupportsRuntimeV2Filtering&amp;lt;/code&amp;gt; interface (since Spark 3.4.0), which lets a scan drop input partitions using the runtime predicate.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/SupportsRuntimeV2Filtering.java |title=SupportsRuntimeV2Filtering.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; [[Apache Iceberg]]&amp;#039;s Spark batch scan implements it, so DPP prunes Iceberg partitions, including hidden partitions derived from a source column.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkRuntimeFilterableScan.java |title=SparkRuntimeFilterableScan.java (apache-iceberg-1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dynamic partition pruning vs runtime filter ==&lt;br /&gt;
DPP and the Spark [[runtime filter]] both push information from one side of a join to the other at run time. DPP removes whole partitions at the scan and needs a partition column as the join key. The runtime filter, added in Spark 3.3.0, inserts a bloom filter on any join key to reduce the rows that go into a shuffle, and Spark does not add one where DPP already applies.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala |title=InjectRuntimeFilter.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Partition pruning]]&lt;br /&gt;
* [[Runtime filter]]&lt;br /&gt;
* [[Broadcast join]]&lt;br /&gt;
* [[Partition]]&lt;br /&gt;
* [[Predicate pushdown]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>