<?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=Column_pruning</id>
	<title>Column 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=Column_pruning"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Column_pruning&amp;action=history"/>
	<updated>2026-12-06T00:07:32Z</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=Column_pruning&amp;diff=134&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=Column_pruning&amp;diff=134&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:37Z</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            = Column pruning&lt;br /&gt;
| also_known_as   = Projection pushdown, projection pruning, schema pruning (for nested fields)&lt;br /&gt;
| field           = Query optimization&lt;br /&gt;
| key_parts       = Optimizer rule that removes unused columns, a connector that accepts a required schema, a columnar file format&lt;br /&gt;
| implementations = [[Apache Spark]], [[Apache Parquet]], [[Apache Iceberg]], [[Delta Lake]], [[Trino]], [[DuckDB]]&lt;br /&gt;
| related         = [[Predicate pushdown]], [[Partition pruning]], [[Aggregate pushdown]], [[Apache Parquet]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (Optimizer.scala, SchemaPruning.scala, SupportsPushDownRequiredColumns.java, DataSourceScanExec.scala, FileScan.scala, SQLConf.scala), Spark JIRA SPARK-4502, the Apache Parquet file format docs, and the Apache Iceberg 1.12.0 spec and Spark source}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Column pruning&amp;#039;&amp;#039;&amp;#039; is a query optimization in which an engine reads only the columns that a query uses, and drops every other column as early as possible in the plan, ideally before the data leaves storage. When the pruning reaches the data source, it is also called &amp;#039;&amp;#039;&amp;#039;projection pushdown&amp;#039;&amp;#039;&amp;#039;. In [[Apache Spark]], column pruning combines an optimizer rule, a connector interface and the columnar layout of formats such as [[Apache Parquet]]; &amp;#039;&amp;#039;&amp;#039;nested column pruning&amp;#039;&amp;#039;&amp;#039; extends it to individual fields inside struct columns.&lt;br /&gt;
&lt;br /&gt;
== Why does column pruning matter? ==&lt;br /&gt;
In a columnar file format, each column is stored separately, so a reader can skip the bytes of the columns it does not need. Apache Parquet stores the values of each column of a row group together in a column chunk, so a query that selects a few columns of a wide table reads only the chunks of those columns in each row group.&amp;lt;ref name=&amp;quot;parquet&amp;quot;&amp;gt;{{Cite web |url=https://parquet.apache.org/docs/file-format/ |title=File Format |publisher=Apache Parquet |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Column pruning is the step that tells the reader which columns those are.&lt;br /&gt;
&lt;br /&gt;
Column pruning also reduces the work after the scan. Fewer columns mean smaller rows in memory, in [[shuffle]] files and in broadcasts.&lt;br /&gt;
&lt;br /&gt;
== How does column pruning work in Apache Spark? ==&lt;br /&gt;
Column pruning in Spark happens in two places.&lt;br /&gt;
&lt;br /&gt;
The optimizer rule &amp;lt;code&amp;gt;ColumnPruning&amp;lt;/code&amp;gt; &amp;quot;attempts to eliminate the reading of unneeded columns from the query plan.&amp;quot; It walks the logical plan and inserts or narrows projections, so each operator receives only the columns that operators above it need.&amp;lt;ref name=&amp;quot;optimizer&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/Optimizer.scala |title=Optimizer.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The pruned column list then reaches the data source. A Data Source V2 connector accepts it by implementing &amp;lt;code&amp;gt;SupportsPushDownRequiredColumns&amp;lt;/code&amp;gt; (since Spark 3.0.0), whose &amp;lt;code&amp;gt;pruneColumns(StructType requiredSchema)&amp;lt;/code&amp;gt; method receives the schema the query needs. The interface allows partial pruning: a source may prune top-level columns but not nested fields.&amp;lt;ref name=&amp;quot;sprc&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/SupportsPushDownRequiredColumns.java |title=SupportsPushDownRequiredColumns.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Built-in file sources receive the required schema directly and pass it to the Parquet or ORC reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
df = spark.read.parquet(&amp;quot;/data/events&amp;quot;)          # a wide table&lt;br /&gt;
(df.filter(&amp;quot;event_type = &amp;#039;click&amp;#039;&amp;quot;)&lt;br /&gt;
   .select(&amp;quot;user_id&amp;quot;, &amp;quot;event_ts&amp;quot;)&lt;br /&gt;
   .explain(&amp;quot;formatted&amp;quot;))&lt;br /&gt;
# The scan&amp;#039;s ReadSchema lists only user_id, event_ts and event_type.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is nested column pruning? ==&lt;br /&gt;
Nested column pruning (also called schema pruning) reads only the struct fields a query uses, instead of the whole struct column. For a column &amp;lt;code&amp;gt;customer struct&amp;lt;id: bigint, name: string, address: struct&amp;lt;...&amp;gt;&amp;gt;&amp;lt;/code&amp;gt;, the query &amp;lt;code&amp;gt;SELECT customer.id FROM orders&amp;lt;/code&amp;gt; reads only &amp;lt;code&amp;gt;customer.id&amp;lt;/code&amp;gt; from the file.&lt;br /&gt;
&lt;br /&gt;
In Spark, nested pruning for file scans is done by the &amp;lt;code&amp;gt;SchemaPruning&amp;lt;/code&amp;gt; rule, which applies to Parquet and ORC and is controlled by &amp;lt;code&amp;gt;spark.sql.optimizer.nestedSchemaPruning.enabled&amp;lt;/code&amp;gt; (default true, since 2.4.1).&amp;lt;ref name=&amp;quot;schemapruning&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/SchemaPruning.scala |title=SchemaPruning.scala (v4.3.0) |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; The feature was introduced through SPARK-4502, &amp;quot;Spark SQL reads unneccesary nested fields from Parquet&amp;quot;, fixed in Spark 2.4.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-4502 |title=SPARK-4502: Spark SQL reads unneccesary nested fields from Parquet |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two related settings prune nested fields in other parts of the plan; neither prunes the physical scan:&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.sql.optimizer.expression.nestedPruning.enabled&amp;lt;/code&amp;gt; (default true, since 3.0.0) prunes nested fields from expressions inside operators.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.sql.optimizer.serializer.nestedSchemaPruning.enabled&amp;lt;/code&amp;gt; (default true, since 3.0.0) prunes nested fields from object serializers.&lt;br /&gt;
&lt;br /&gt;
== How can you check that columns were pruned? ==&lt;br /&gt;
Each scan in &amp;lt;code&amp;gt;EXPLAIN FORMATTED&amp;lt;/code&amp;gt; output shows a &amp;lt;code&amp;gt;ReadSchema&amp;lt;/code&amp;gt; entry with the schema the scan actually reads, including the pruned nested fields.&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; For &amp;lt;code&amp;gt;SELECT customer.id FROM orders&amp;lt;/code&amp;gt;, a pruned scan shows &amp;lt;code&amp;gt;ReadSchema: struct&amp;lt;customer:struct&amp;lt;id:bigint&amp;gt;&amp;gt;&amp;lt;/code&amp;gt;, and an unpruned scan shows the full struct. After the query runs, the scan&amp;#039;s &amp;lt;code&amp;gt;size of files read&amp;lt;/code&amp;gt; metric in the Spark UI reports the bytes read.&amp;lt;ref name=&amp;quot;scanexec&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What stops column pruning? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Row-oriented formats.&amp;#039;&amp;#039;&amp;#039; CSV and JSON files store whole rows, so the reader must still parse every row even when it returns fewer columns.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Operators that need all columns&amp;#039;&amp;#039;&amp;#039;, such as &amp;lt;code&amp;gt;SELECT *&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;df.collect()&amp;lt;/code&amp;gt; on the full DataFrame, or a UDF that takes the whole row as input.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Nested pruning limits.&amp;#039;&amp;#039;&amp;#039; Nested pruning is limited to Parquet and ORC file scans, and to Data Source V2 sources that prune nested fields in &amp;lt;code&amp;gt;pruneColumns&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;schemapruning&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sprc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Column pruning in table formats ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[Apache Iceberg]]&amp;#039;&amp;#039;&amp;#039; projects columns by field ID, not by name: &amp;quot;Columns in Iceberg data files are selected by field id&amp;quot;, so pruning stays correct after columns are renamed or reordered.&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; Iceberg&amp;#039;s Spark scan builder implements &amp;lt;code&amp;gt;SupportsPushDownRequiredColumns&amp;lt;/code&amp;gt;.&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/SparkScanBuilder.java |title=SparkScanBuilder.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; data files are Parquet files, and the Delta protocol defines how Delta data types map to Parquet types, so a Delta scan in Spark reads through the Parquet reader and benefits from the same column pruning.&amp;lt;ref&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;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Predicate pushdown]]&lt;br /&gt;
* [[Partition pruning]]&lt;br /&gt;
* [[Aggregate pushdown]]&lt;br /&gt;
* [[Apache Parquet]]&lt;br /&gt;
* [[Data Source V2]]&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>