Tuning and Disabling AQE

Every AQE default encodes a guess about workloads: 64MB makes a sensible task, 10MB fits in memory, and a partition 5 times the median is skew. Tune each threshold from a measured stage of your own job, change a single setting per run, and record the number that justified it.

SettingDefaultWhat it decidesMove it when
`spark.sql.adaptive.coalescePartitions.initialPartitionNum`Unset, uses `spark.sql.shuffle.partitions`Reducer count before any mergePartitions stay large after coalescing
`spark.sql.adaptive.advisoryPartitionSizeInBytes`64MBCoalesce target, and the size skewed partitions split intoLater stages expand rows (lower) or do light work on a busy cluster (higher)
`spark.sql.adaptive.coalescePartitions.parallelismFirst`trueWhether the core count shrinks the targetTiny tasks crowd a shared cluster (false)
`spark.sql.adaptive.coalescePartitions.minPartitionSize`1MBSmallest merged partitionThousands of near-empty tasks remain
`spark.sql.adaptive.autoBroadcastJoinThreshold`Unset, uses `spark.sql.autoBroadcastJoinThreshold`Largest side converted to broadcast at runtimeShuffle bytes unpack past your memory budget
`spark.sql.adaptive.skewJoin.skewedPartitionFactor`5Multiple of the median that marks skewHot partitions sit at 3 to 4 times the median and still stall
`spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes`256MBSize a skewed partition must also exceedSmall jobs stall on 150MB hot partitions

A tuned nightly job, setting by setting

The nightly title job runs on a shared 400-core cluster. Its largest shuffle moves 240GB, its stages after each shuffle do light per-row work, and its catalog shuffle compresses 7:1 against a 175MB per-executor budget for broadcasts.

spark.conf.set("spark.sql.adaptive.coalescePartitions.initialPartitionNum", 2000)
spark.conf.set("spark.sql.adaptive.coalescePartitions.parallelismFirst", "false")
spark.conf.set("spark.sql.adaptive.advisoryPartitionSizeInBytes", "128MB")
spark.conf.set("spark.sql.adaptive.autoBroadcastJoinThreshold", "25MB")
SettingValueThe measurement behind it
initialPartitionNum2000240GB over 2,000 partitions is about 123MB each, near the 128MB target, and smaller shuffles merge down from there
parallelismFirstfalseLight per-row work, so packing costs little and frees slots for other jobs
advisoryPartitionSizeInBytes128MBTasks of 64MB finished in under 10 seconds, leaving scheduling overhead visible
autoBroadcastJoinThreshold25MBA 175MB budget divided by the 7:1 ratio

When to switch a piece off

Disabling is rare because the measured plan beats the estimated one in most stages of most jobs. Each case below turns off a single piece and keeps the rest, and each names what you would measure to justify it.

Do
  • Tune a single AQE setting per run and keep the stage metric that justified it
  • Size the runtime broadcast threshold from decompressed row bytes
  • Pin a stage's partition count with an explicit repartition when its cost per byte is known
  • Set initialPartitionNum so the largest shuffle starts near the coalesce target
Avoid
  • Turn off all of AQE to fix a single stage
  • Copy another team's thresholds without measuring your own stages
  • Raise the broadcast threshold without checking executor and driver memory
  • Expect AQE to split uniformly large partitions or hot aggregation keys

After a team sets parallelismFirst to false, a feature stage in their nightly job drops from 400 tasks to 31 and runs 6 times longer, while every other stage gets faster. What is the narrowest fix?

About this lesson

This section is part of the Adaptive Query Execution: Advanced lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.