<?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=Catalyst_optimizer</id>
	<title>Catalyst optimizer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Catalyst_optimizer"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Catalyst_optimizer&amp;action=history"/>
	<updated>2026-12-06T00:07:35Z</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=Catalyst_optimizer&amp;diff=131&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=Catalyst_optimizer&amp;diff=131&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:36Z</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            = Catalyst optimizer&lt;br /&gt;
| also_known_as   = Catalyst, Spark SQL optimizer&lt;br /&gt;
| field           = Query optimization&lt;br /&gt;
| introduced      = 2014, with Spark SQL (described in a SIGMOD 2015 paper)&lt;br /&gt;
| key_parts       = Trees and rules, analyzer, logical optimizer (rule batches), physical planner (strategies), code generation&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Logical plan and physical plan]], [[Whole-stage code generation]], [[Adaptive Query Execution]], [[Cost-based optimizer (Spark)]], [[Predicate pushdown]], [[Project Tungsten]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the SIGMOD 2015 paper &amp;quot;Spark SQL: Relational Data Processing in Spark&amp;quot;, the v4.3.0 tag of apache/spark (Optimizer.scala, SparkStrategies.scala, SQLConf.scala, StaticSQLConf.scala, docs/sql-ref-syntax-qry-explain.md, docs/sql-performance-tuning.md), the Spark 3.0.0 release notes, the Delta Lake quickstart, the Apache Iceberg 1.12.0 Spark configuration page and plan change logs and EXPLAIN output from a PySpark 4.3.0 run}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Catalyst optimizer&amp;#039;&amp;#039;&amp;#039; is the extensible query optimizer of Spark SQL in [[Apache Spark]]; it turns every SQL query and DataFrame or Dataset program into an optimized physical plan by applying rules to trees in four phases: analysis, logical optimization, physical planning and code generation.&amp;lt;ref name=&amp;quot;paper&amp;quot;&amp;gt;{{Cite web |url=https://people.csail.mit.edu/matei/papers/2015/sigmod_spark_sql.pdf |title=Spark SQL: Relational Data Processing in Spark (SIGMOD 2015) |publisher=Armbrust et al., Databricks, MIT CSAIL and AMPLab UC Berkeley |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; SQL queries and DataFrame operations, including those written in Python and R, all go through Catalyst.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt; The paper that introduced Catalyst, &amp;quot;Spark SQL: Relational Data Processing in Spark&amp;quot;, was written by Michael Armbrust, Reynold Xin, Matei Zaharia and others at Databricks, MIT CSAIL and the AMPLab at UC Berkeley, and presented at SIGMOD in 2015; it gives May 2014 as the first release of Spark SQL.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Catalyst work? ==&lt;br /&gt;
Catalyst represents a query as a &amp;#039;&amp;#039;&amp;#039;tree&amp;#039;&amp;#039;&amp;#039; of immutable nodes, such as expressions (&amp;lt;code&amp;gt;Add&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Literal&amp;lt;/code&amp;gt;) and operators (&amp;lt;code&amp;gt;Filter&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Join&amp;lt;/code&amp;gt;). A &amp;#039;&amp;#039;&amp;#039;rule&amp;#039;&amp;#039;&amp;#039; is a function from one tree to another, usually written with Scala pattern matching; for example, a rule can fold &amp;lt;code&amp;gt;Add(Literal(1), Literal(2))&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;Literal(3)&amp;lt;/code&amp;gt;. Rules are grouped into &amp;#039;&amp;#039;&amp;#039;batches&amp;#039;&amp;#039;&amp;#039;, and each batch runs until the tree stops changing (a fixed point) or a set number of times.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The paper describes four phases. In the physical planning phase Catalyst may generate several plans and compare them by cost; the other phases are purely rule-based.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Phase !! Input !! Output !! Examples of what happens&lt;br /&gt;
|-&lt;br /&gt;
| 1. Analysis || Unresolved logical plan from the SQL parser or the DataFrame API || Resolved (analyzed) logical plan || Look up tables in the catalog, resolve column names, assign unique attribute IDs, apply type coercion&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2. Logical optimization || Analyzed logical plan || Optimized logical plan || Constant folding, predicate pushdown, column pruning, boolean simplification&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;opt&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;
| 3. Physical planning || Optimized logical plan || Physical plan (&amp;lt;code&amp;gt;SparkPlan&amp;lt;/code&amp;gt;) || Pick join strategies, pick hash or sort aggregation, push filters into data source scans&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;strategies&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/SparkStrategies.scala |title=SparkStrategies.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4. Code generation || Physical plan || Java bytecode for parts of the query || [[Whole-stage code generation]] compiles chains of operators into one function&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In Spark 4.3.0 the logical optimizer is a long list of named batches, for example &amp;quot;Operator Optimization before Inferring Filters&amp;quot;, &amp;quot;Infer Filters&amp;quot;, &amp;quot;Join Reorder&amp;quot; (used by the [[Cost-based optimizer (Spark)|cost-based optimizer]]) and &amp;quot;RewriteSubquery&amp;quot;.&amp;lt;ref name=&amp;quot;opt&amp;quot; /&amp;gt; Since Spark 3.0.0, [[Adaptive Query Execution]] adds a further round of optimization at run time, using runtime statistics.&amp;lt;ref name=&amp;quot;r300&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-0-0.html |title=Spark Release 3.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which Catalyst rules can be seen in EXPLAIN? ==&lt;br /&gt;
Rules do not appear by name in &amp;lt;code&amp;gt;EXPLAIN&amp;lt;/code&amp;gt; output, but their effects do. &amp;lt;code&amp;gt;EXPLAIN EXTENDED&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;df.explain(mode=&amp;quot;extended&amp;quot;)&amp;lt;/code&amp;gt;) prints the parsed, analyzed and optimized logical plans and the physical plan, so a rule&amp;#039;s work shows as a difference between two of them.&amp;lt;ref name=&amp;quot;explain&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-explain.html |title=EXPLAIN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The examples below are from PySpark 4.3.0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Rule (Spark 4.3.0 class name) !! What it does !! How it shows in EXPLAIN&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ConstantFolding&amp;lt;/code&amp;gt; || Evaluates constant expressions at planning time || &amp;lt;code&amp;gt;(id % cast(2 as bigint))&amp;lt;/code&amp;gt; in the analyzed plan becomes &amp;lt;code&amp;gt;(id % 2)&amp;lt;/code&amp;gt; in the optimized plan&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;PushDownPredicates&amp;lt;/code&amp;gt; || Moves filters below projections and joins, toward the data || A &amp;lt;code&amp;gt;Filter&amp;lt;/code&amp;gt; written after a join appears under the join, on each input&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;InferFiltersFromConstraints&amp;lt;/code&amp;gt; || Derives new filters from join conditions and existing filters || A join on &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;id &amp;gt; 10&amp;lt;/code&amp;gt; on one side gets &amp;lt;code&amp;gt;id &amp;gt; 10 AND isnotnull(id)&amp;lt;/code&amp;gt; on both sides&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ColumnPruning&amp;lt;/code&amp;gt; || Removes columns that no later operator needs || A Parquet scan lists only the needed columns, for example &amp;lt;code&amp;gt;FileScan parquet [id#42L]&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;BooleanSimplification&amp;lt;/code&amp;gt; || Simplifies boolean expressions || &amp;lt;code&amp;gt;y &amp;gt; 3 AND true&amp;lt;/code&amp;gt; becomes &amp;lt;code&amp;gt;y &amp;gt; 3&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Data source pushdown (physical planning) || Hands filters to the data source || &amp;lt;code&amp;gt;PushedFilters: [IsNotNull(id), GreaterThan(id,10)]&amp;lt;/code&amp;gt; on a &amp;lt;code&amp;gt;FileScan parquet&amp;lt;/code&amp;gt; node; see [[Predicate pushdown]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To see the rules by name, set &amp;lt;code&amp;gt;spark.sql.planChangeLog.level&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;WARN&amp;lt;/code&amp;gt;. Spark then logs each rule that changes the plan, with the plan before and after. For the query &amp;lt;code&amp;gt;spark.range(10).selectExpr(&amp;quot;id + (1 + 2) as y&amp;quot;).filter(&amp;quot;y &amp;gt; 3 and true&amp;quot;)&amp;lt;/code&amp;gt;, PySpark 4.3.0 logged &amp;lt;code&amp;gt;ConstantFolding&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;BooleanSimplification&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;PushDownPredicates&amp;lt;/code&amp;gt; among the optimizer rules, along with analyzer rules such as &amp;lt;code&amp;gt;ResolveReferences&amp;lt;/code&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;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
spark.conf.set(&amp;quot;spark.sql.planChangeLog.level&amp;quot;, &amp;quot;WARN&amp;quot;)&lt;br /&gt;
df = spark.range(10).selectExpr(&amp;quot;id + (1 + 2) AS y&amp;quot;).filter(&amp;quot;y &amp;gt; 3 AND true&amp;quot;)&lt;br /&gt;
df.explain(mode=&amp;quot;extended&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Individual rules can be turned off with &amp;lt;code&amp;gt;spark.sql.optimizer.excludedRules&amp;lt;/code&amp;gt;, a comma-separated list of rule names (since 2.4.0). Spark does not guarantee that every listed rule is excluded, because some rules are needed for correctness.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extending Catalyst ==&lt;br /&gt;
Catalyst was built to be extended. The paper names new data sources, including ones that accept pushed-down filters, user-defined types and new optimization rules as extension points.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt; In Spark 4.3.0, the static setting &amp;lt;code&amp;gt;spark.sql.extensions&amp;lt;/code&amp;gt; takes a list of classes that add rules, planner strategies, parsers and functions to every session.&amp;lt;ref name=&amp;quot;static&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/StaticSQLConf.scala |title=StaticSQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Table formats use this hook: [[Delta Lake]] is enabled with &amp;lt;code&amp;gt;spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension&amp;lt;/code&amp;gt;,&amp;lt;ref name=&amp;quot;delta&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/latest/quick-start.html |title=Quickstart (Delta Lake documentation) |publisher=Delta Lake project, Linux Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; and [[Apache Iceberg]]&amp;#039;s SQL extensions with &amp;lt;code&amp;gt;org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;icecfg&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-configuration/ |title=Spark Configuration (Apache Iceberg 1.12.0 documentation) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What Catalyst is not ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Not the execution engine.&amp;#039;&amp;#039;&amp;#039; Catalyst decides what plan to run. How the chosen operators use memory and CPU is the work of [[Project Tungsten]] and the executors.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Not used by the RDD API.&amp;#039;&amp;#039;&amp;#039; Programs written with RDDs and arbitrary functions are run as written. Only DataFrame, Dataset and SQL operations, whose structure Spark understands, are optimized by Catalyst.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Logical plan and physical plan]]&lt;br /&gt;
* [[Whole-stage code generation]]&lt;br /&gt;
* [[Adaptive Query Execution]]&lt;br /&gt;
* [[Cost-based optimizer (Spark)]]&lt;br /&gt;
* [[Predicate pushdown]]&lt;br /&gt;
* [[Lazy evaluation]]&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>