Catalyst Optimizer and Project Tungsten in Spark
knowledge of Spark SQL internals.
Catalyst transforms logical plans with rules, picks physical plans by cost; Tungsten optimizes execution with off-heap memory and codegen.
What's really being asked
Whether you understand that Spark SQL does not execute queries literally but compiles them through an optimizer, and whether you can separate plan-level optimization (Catalyst) from execution-level optimization (Tungsten).
The full answer
Catalyst is Spark SQL's extensible query optimizer. It first parses a query or DataFrame into an unresolved logical plan, resolves column and table references against the catalog to produce an analyzed logical plan, then applies a library of rule-based transformations such as predicate pushdown, projection pruning, constant folding, and Boolean simplification to produce an optimized logical plan. From that it generates one or more physical plans and uses cost-based optimization to choose among them, for example selecting a broadcast hash join over a sort-merge join when one side is small. Project Tungsten then makes the chosen plan run fast at the execution layer. It manages memory off-heap in compact binary format to cut garbage-collection pressure, exploits cache-aware data structures, and uses whole-stage code generation to fuse multiple operators into a single compiled JVM function, avoiding virtual-call overhead.
The mistakes people make
Saying Catalyst executes the query, or that Tungsten optimizes the logical plan. Tungsten is about CPU and memory efficiency, not plan rewriting.
What usually comes next
What is the difference between rule-based and cost-based optimization? How does whole-stage codegen reduce overhead? When does Adaptive Query Execution re-optimize at runtime?
A concrete example
A join filters one table by date. Catalyst pushes the date predicate down so the scan reads fewer rows, prunes unused columns, and picks a broadcast join because the dimension table is tiny. Tungsten then code-generates the filter and join into one tight loop operating on off-heap binary rows, so the query runs far faster than an interpreted plan would.
Interview question
How do the responsibilities of Catalyst and Project Tungsten differ in Spark SQL?
- a.Both rewrite logical plans, but Tungsten runs first
- b.Catalyst optimizes and selects query plans; Tungsten optimizes memory and CPU during executionCorrect
- c.They are two names for the same code-generation module
- d.Catalyst manages off-heap memory; Tungsten chooses join strategies
Why? this is the answer
Catalyst works at the plan level (rule and cost-based optimization), while Tungsten improves execution efficiency via off-heap memory and whole-stage codegen. The other options swap or merge their roles.
Just read this? Test yourself on what you have been reading.
Read the original → databricks.com
- #spark
- #catalyst-optimizer
- #tungsten
- #query-optimization
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles