<?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=Partition_pruning</id>
	<title>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=Partition_pruning"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=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=Partition_pruning&amp;diff=166&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=Partition_pruning&amp;diff=166&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:47Z</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            = Partition pruning&lt;br /&gt;
| also_known_as   = Partition elimination, partition filtering&lt;br /&gt;
| field           = Query optimization&lt;br /&gt;
| key_parts       = Partition columns or transforms, partition filters, catalog or table metadata, runtime filters&lt;br /&gt;
| implementations = [[Apache Spark]], [[Apache Iceberg]], [[Delta Lake]], [[Apache Hive]], [[Trino]]&lt;br /&gt;
| related         = [[Partition]], [[Dynamic partition pruning]], [[Predicate pushdown]], [[Column pruning]], [[Bucketing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SQLConf.scala, FileSourceStrategy.scala, DataSourceScanExec.scala, FileScan.scala, PartitionPruning.scala, SupportsRuntimeFiltering.java, SupportsRuntimeV2Filtering.java), Spark JIRA SPARK-11150 and SPARK-35779, the Apache Iceberg 1.12.0 spec and Spark source, and the Delta Lake protocol at v4.4.1}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Partition pruning&amp;#039;&amp;#039;&amp;#039; is a query optimization in which an engine uses the filters of a query to skip whole partitions of a table, so that the files in partitions that cannot match are never listed or read. In [[Apache Spark]] it comes in two forms: &amp;#039;&amp;#039;&amp;#039;static partition pruning&amp;#039;&amp;#039;&amp;#039;, where the filter on a partition column is known when the query is planned, and &amp;#039;&amp;#039;&amp;#039;[[dynamic partition pruning]]&amp;#039;&amp;#039;&amp;#039;, where the filter values are only known at run time, usually from the other side of a join. Table formats such as [[Apache Iceberg]] and [[Delta Lake]] do the pruning from their metadata instead of from directory names.&lt;br /&gt;
&lt;br /&gt;
== What does partition pruning skip? ==&lt;br /&gt;
Partition pruning works at the coarsest level of data skipping. It removes whole [[partition|table partitions]] before any file is opened, while [[predicate pushdown]] into the file format skips row groups and pages inside the files that remain. For built-in file sources, Spark sorts the filters of a scan into partition filters, which prune directories; bucket filters, which prune bucket files; data filters, which are pushed to the file reader; and filters that must be evaluated again after the scan.&amp;lt;ref name=&amp;quot;fss&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/datasources/FileSourceStrategy.scala |title=FileSourceStrategy.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Static partition pruning ==&lt;br /&gt;
Static partition pruning applies when a query filters a partition column with a value known at planning time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- sales is partitioned by sale_date&lt;br /&gt;
SELECT store_id, SUM(amount)&lt;br /&gt;
FROM sales&lt;br /&gt;
WHERE sale_date &amp;gt;= DATE&amp;#039;2026-11-01&amp;#039;&lt;br /&gt;
GROUP BY store_id;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a Hive-style table, each partition is a directory such as &amp;lt;code&amp;gt;sale_date=2026-11-01/&amp;lt;/code&amp;gt;, and Spark lists only the directories whose values satisfy the filter. For tables stored in a Hive metastore, &amp;lt;code&amp;gt;spark.sql.hive.metastorePartitionPruning&amp;lt;/code&amp;gt; (default true, since 1.5.0) pushes partition predicates into the metastore, so that Spark fetches only the matching partition metadata.&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;
Spark uses a filter for partition pruning when it is deterministic and refers only to partition columns; an expression over a partition column, such as &amp;lt;code&amp;gt;year(sale_date) = 2026&amp;lt;/code&amp;gt;, still qualifies.&amp;lt;ref name=&amp;quot;fss&amp;quot; /&amp;gt; A filter on a different column does not, even when it is related: &amp;lt;code&amp;gt;WHERE sale_ts &amp;gt;= TIMESTAMP &amp;#039;2026-11-01 00:00:00&amp;#039;&amp;lt;/code&amp;gt; on a table partitioned by a separate &amp;lt;code&amp;gt;sale_date&amp;lt;/code&amp;gt; column prunes nothing, because Spark does not know how the two columns relate. Iceberg&amp;#039;s hidden partitioning addresses this case (see below).&lt;br /&gt;
&lt;br /&gt;
== Dynamic partition pruning ==&lt;br /&gt;
{{Main|Dynamic partition pruning}}&lt;br /&gt;
Dynamic partition pruning (DPP) prunes partitions using values that Spark learns while the query runs. In a join of a partitioned fact table with a filtered dimension table, Spark uses the join keys that survive the dimension filter as a partition filter on the fact table. DPP was added in Spark 3.0.0 (SPARK-11150) and is on by default through &amp;lt;code&amp;gt;spark.sql.optimizer.dynamicPartitionPruning.enabled&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&amp;lt;ref&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;&lt;br /&gt;
&lt;br /&gt;
Data Source V2 connectors take part in runtime pruning through &amp;lt;code&amp;gt;SupportsRuntimeFiltering&amp;lt;/code&amp;gt; (since Spark 3.2.0) and &amp;lt;code&amp;gt;SupportsRuntimeV2Filtering&amp;lt;/code&amp;gt; (since 3.4.0), which let a scan drop planned input partitions using predicates Spark infers during execution.&amp;lt;ref name=&amp;quot;rtf&amp;quot;&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;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-35779 |title=SPARK-35779: Support dynamic filtering for v2 tables |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Static vs dynamic partition pruning ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Static partition pruning !! Dynamic partition pruning&lt;br /&gt;
|-&lt;br /&gt;
! When the filter is known&lt;br /&gt;
| At planning time, from a literal or constant expression&lt;br /&gt;
| At run time, from the result of another part of the query&lt;br /&gt;
|-&lt;br /&gt;
! Typical query&lt;br /&gt;
| &amp;lt;code&amp;gt;WHERE sale_date = &amp;#039;2026-11-01&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;JOIN dim_date d ON f.sale_date = d.date WHERE d.is_holiday&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Shown in Spark plans as&lt;br /&gt;
| A plain predicate in &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;dynamicpruningexpression(...)&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt;, fed by a subquery or a reused broadcast&lt;br /&gt;
|-&lt;br /&gt;
! Setting&lt;br /&gt;
| Always on for partition columns&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.dynamicPartitionPruning.enabled&amp;lt;/code&amp;gt; (default true)&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== What to look for in a Spark plan ==&lt;br /&gt;
&amp;lt;code&amp;gt;EXPLAIN FORMATTED&amp;lt;/code&amp;gt; prints the metadata of each scan. For a built-in file source, the scan node lists &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PushedFilters&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DataFilters&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ReadSchema&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;scanexec&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/DataSourceScanExec.scala |title=DataSourceScanExec.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/datasources/v2/FileScan.scala |title=FileScan.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Static pruning worked&amp;#039;&amp;#039;&amp;#039; if the partition predicate appears in &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt;, for example &amp;lt;code&amp;gt;PartitionFilters: [isnotnull(sale_date#12), (sale_date#12 &amp;gt;= 2026-11-01)]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Static pruning did not happen&amp;#039;&amp;#039;&amp;#039; if &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt; is empty and the predicate shows up only in &amp;lt;code&amp;gt;DataFilters&amp;lt;/code&amp;gt; or in a &amp;lt;code&amp;gt;Filter&amp;lt;/code&amp;gt; above the scan. Common causes are a filter on a column that is not a partition column, a non-deterministic filter, or a table that Spark does not see as partitioned.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Dynamic pruning was planned&amp;#039;&amp;#039;&amp;#039; if &amp;lt;code&amp;gt;PartitionFilters&amp;lt;/code&amp;gt; contains &amp;lt;code&amp;gt;dynamicpruningexpression(...)&amp;lt;/code&amp;gt;. Spark represents a planned dynamic filter with the &amp;lt;code&amp;gt;DynamicPruningExpression&amp;lt;/code&amp;gt; marker.&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;&lt;br /&gt;
&lt;br /&gt;
After the query runs, the scan node in the Spark UI&amp;#039;s SQL tab shows the metrics &amp;lt;code&amp;gt;number of files read&amp;lt;/code&amp;gt; and, for partitioned tables, &amp;lt;code&amp;gt;number of partitions read&amp;lt;/code&amp;gt;, which measure pruning directly.&amp;lt;ref name=&amp;quot;scanexec&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/web-ui.html |title=Web UI (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Partition pruning in table formats ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[Apache Iceberg]]&amp;#039;&amp;#039;&amp;#039; prunes from metadata rather than directory names. Each data file records the partition values it belongs to, and partitions are derived from source columns by transforms such as &amp;lt;code&amp;gt;day&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;bucket[N]&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;truncate[W]&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;icebergspec&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/format/spec.md |title=Iceberg Table Spec (apache-iceberg-1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A filter on the source column, such as &amp;lt;code&amp;gt;WHERE sale_ts &amp;gt;= TIMESTAMP &amp;#039;2026-11-01 00:00:00&amp;#039;&amp;lt;/code&amp;gt; on a table partitioned by &amp;lt;code&amp;gt;day(sale_ts)&amp;lt;/code&amp;gt;, therefore prunes partitions without the query naming a partition column; this is called hidden partitioning. Iceberg&amp;#039;s Spark batch scan also implements &amp;lt;code&amp;gt;SupportsRuntimeV2Filtering&amp;lt;/code&amp;gt;, so it takes part in dynamic partition pruning.&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;
&amp;#039;&amp;#039;&amp;#039;[[Delta Lake]]&amp;#039;&amp;#039;&amp;#039; records the partition values of each data file in the &amp;lt;code&amp;gt;partitionValues&amp;lt;/code&amp;gt; field of its &amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; action in the transaction log, so a reader prunes partitions by filtering the log instead of listing directories.&amp;lt;ref name=&amp;quot;deltaprotocol&amp;quot;&amp;gt;{{Cite web |url=https://github.com/delta-io/delta/blob/v4.4.1/PROTOCOL.md |title=Delta Transaction Log Protocol (v4.4.1) |publisher=Delta Lake |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The same &amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; actions can carry per-file column statistics, which Delta uses to skip files inside a partition.&amp;lt;ref name=&amp;quot;deltaprotocol&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Partition]]&lt;br /&gt;
* [[Dynamic partition pruning]]&lt;br /&gt;
* [[Predicate pushdown]]&lt;br /&gt;
* [[Column pruning]]&lt;br /&gt;
* [[Bucketing]]&lt;br /&gt;
* [[Runtime filter]]&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>