Skip to content
PHP2Shell: The PHP Bug
Akshay Thakare

Adaptive Query Execution (AQE) in Spark

How Spark 3 re-plans a query at runtime: coalescing shuffle partitions, switching to broadcast joins and splitting skewed partitions.

Apache SparkAdvanced2 min readUpdated 11 Oct 2026

The problem AQE solves

A static plan is chosen before any data is read, using estimates. Estimates are often wrong after filters and joins. AQE re-optimises between stages, using the real sizes of shuffle outputs.

Python.py
spark.conf.set("spark.sql.adaptive.enabled", "true")   # default since Spark 3.2

What it does

FeatureWithout AQEWith AQE
Coalesce partitions200 shuffle partitions, many nearly emptyMerges small partitions into fewer tasks
Join strategySort-merge join chosen from estimatesSwitches to a broadcast join if one side turns out small
Skew joinOne partition holds most of a hot key, so one task runs for an hourSplits the skewed partition into several tasks

Settings worth knowing

Python.py
spark.conf.set("spark.sql.adaptive.coalescePartitions.enabled", "true")
spark.conf.set("spark.sql.adaptive.advisoryPartitionSizeInBytes", "128m")
spark.conf.set("spark.sql.adaptive.skewJoin.enabled", "true")

What AQE does not fix

  • Skew in a groupBy aggregation on one huge key. Salt the key or pre-aggregate.
  • Reading too much data. Partition pruning and column pruning still matter.
  • Too many small input files. AQE works on shuffles, not on the initial scan.

Finished this note?

Share