Talk with our engineers by joining the new Onehouse community Slack!

Spark SQL join slow: How to find the cause and what to do when tuning runs out

Spark SQL join slow? Find the cause, tune what matters. A sketch of a query plan in which Orders and Customers tables each feed an Exchange node labeled shuffle and a Sort node labeled spill, then meet in a SortMergeJoin. Beside it, a task time chart shows three short tasks and one long task marked skew under a magnifying glass, captioned: one task holds up the join.

TL;DR

A slow Spark SQL join usually has one of six causes: a missed broadcast, a skewed key, a badly sized shuffle, duplicate keys that multiply rows, a range join that falls back to a nested loop, or too much data read before the join. Confirm the cause with EXPLAIN FORMATTED, the SQL / DataFrame tab and the join stage's Summary Metrics, then fix it in order of cost: a hint, statistics, AQE settings, a query rewrite, a table layout that avoids the shuffle. In our Spark 4.3.0 tests on 500 million rows, a BROADCAST hint cut one join from 18.5 s to 1.6 s, while salting a skewed join gained nothing over leaving it alone. What tuning cannot remove is the sort, row-at-a-time execution and scanning a whole table to find matches, and that is where the engine matters.

A slow Spark SQL join almost always comes down to one of six causes, and each leaves a different trace in the query plan or the Spark UI. This guide starts from the symptom, shows how to confirm the cause, and orders the fixes from the cheapest (a hint) to the most invasive (a new table layout or a different engine). It covers SQL JOIN and DataFrame df.join() together, because both compile to the same physical plan.

Every plan and number below comes from our own runs on Apache Spark™ 4.3.0: four executors with 4 cores and 5 GB each, 500 million orders rows (29 GiB of Parquet), 500 million shipments, 5 million customers and 2 million sellers. Timings are medians of three runs. Treat them as illustrative: your numbers will differ.

Why a Spark SQL join is slow

Unless one table is small enough to copy to every executor, Spark has to bring matching keys together. It hashes the join key on both sides, writes every row to shuffle files, fetches those files over the network and, by default, sorts both sides before merging them. That shuffle and sort is the main cost of a join.

Most slow joins are one of these cases:

What you see in the plan or the Spark UI Likely cause
SortMergeJoin with an Exchange under both inputs, and one input is small Missed broadcast
One task runs far longer than the rest, and its shuffle read is many times the median Skewed join key
Most tasks in the join stage are slow, and the stage reports spill Badly sized shuffle partitions
The join outputs far more rows than either input Duplicate keys on both sides
BroadcastNestedLoopJoin or CartesianProduct in the plan Range join or missing join condition
The scan reads far more rows than the join keeps Too much data read before the join
None of the above: time is spread across shuffle, sort and join The cost of the join itself

How Spark chooses a join strategy

Spark has five physical joins. For an equi-join (a.key = b.key), the planner works down this list and takes the first one that applies:

  1. Broadcast hash join, if one side’s estimated size is at or below spark.sql.autoBroadcastJoinThreshold (10 MB by default). The small side is copied to every executor and the big side is never shuffled.
  2. Shuffled hash join, only if spark.sql.join.preferSortMergeJoin is set to false (it defaults to true) and one side is much smaller than the other.
  3. Sort-merge join, the default for two large tables. Both sides are shuffled and sorted.

A join with no equality condition, such as a range join, can only run as a broadcast nested loop join or a Cartesian product. A join hint is checked before any of these rules.

Diagram of where rows travel in an Apache Spark join. Left, a broadcast hash join: the small table is collected by the driver and sent to three executors as a hash table, and the big table rows stay where they were read, with no shuffle. Right, a shuffle sort-merge join: partitions of both tables cross an Exchange hashpartitioning(key, 200) step into three partitions, where each side is sorted and then merged, with two shuffles.
A broadcast join moves one small table. A sort-merge join moves and sorts every row of both tables.

The decision rests on size estimates, which come from statistics. For a plain Parquet table, Spark uses the file sizes. A partitioned table in a Hive-style catalog has no size until it is analyzed, so Spark assumes the maximum, which EXPLAIN COST prints as 8.0 EiB. A filter shrinks an estimate only when column statistics exist and spark.sql.cbo.enabled (off by default) is on. For how hash and sort-merge joins trade memory against CPU, see shuffle hash join vs. sort-merge join.

Reading the plan and the Spark UI

Start with EXPLAIN FORMATTED (or df.explain(mode="formatted")). This query joins 500 million orders to the sellers in one tier:

EXPLAIN FORMATTED
SELECT o.order_id, o.amount, o.order_date, s.seller_name, s.region
FROM orders o
JOIN sellers s ON o.seller_id = s.seller_id
WHERE s.tier = 'gold';
== Physical Plan ==
AdaptiveSparkPlan (13)
+- Project (12)
   +- SortMergeJoin Inner (11)
      :- Sort (5)
      :  +- Exchange (4)
      :     +- Project (3)
      :        +- Filter (2)
      :           +- Scan parquet spark_catalog.shop.orders (1)
      +- Sort (10)
         +- Exchange (9)
            +- Project (8)
               +- Filter (7)
                  +- Scan parquet spark_catalog.shop.sellers (6)

(4) Exchange
Input [4]: [order_id#4L, seller_id#6L, order_date#8, amount#9]
Arguments: hashpartitioning(seller_id#6L, 200), ENSURE_REQUIREMENTS, [plan_id=31]

(11) SortMergeJoin
Left keys [1]: [seller_id#6L]
Right keys [1]: [seller_id#13L]
Join type: Inner
Join condition: None

The output is trimmed to the tree and two of its thirteen node entries. Read three things from it:

  • The join node. SortMergeJoin means both inputs are shuffled and sorted. BroadcastHashJoin means one is not.
  • Every Exchange. Each one is a shuffle. hashpartitioning(seller_id, 200) says the rows are split into 200 partitions by the join key. A BroadcastExchange is the cheap kind.
  • The estimates. EXPLAIN COST prints the size Spark assumed for each input. Here it shows sizeInBytes=58.6 MiB for sellers before and after the tier = 'gold' filter, although the filter keeps 20,000 of 2 million rows.

EXPLAIN shows the plan before the query runs. With adaptive query execution (AQE), the plan that ran can differ, so confirm it in the SQL / DataFrame tab of the Spark UI. There each node carries real row counts, an Exchange shows the shuffle bytes written, and an AQEShuffleRead node shows whether AQE merged small partitions or split skewed ones.

Spark UI SQL / DataFrame tab showing the executed plan of the sort-merge join. Two scans feed two Exchange nodes, two Sort nodes and a SortMergeJoin. Callout 1 marks the Exchange on orders and its metrics panel: 500,000,000 shuffle records written and 9.5 GiB shuffle bytes written. Callout 2 marks the second Exchange, on sellers. Callout 3 marks the 20,000 rows left after the sellers filter. Callout 4 marks the SortMergeJoin node, which outputs 5,000,587 rows.
The sort-merge plan in the SQL / DataFrame tab of the Spark UI (Spark 4.3.0, AQE off). (1) The Exchange on orders wrote 500 million records and 9.5 GiB to shuffle files. (2) A second Exchange shuffles sellers. (3) Only 20,000 seller rows survive the filter. (4) Both sides are sorted, then merged.

For task-level problems, open the join’s stage from the Stages tab and read the Summary Metrics table. Compare the median and max columns for Duration and for Shuffle Read Size / Records, and check whether the Spill rows are non-zero. Our Spark performance tuning guide walks through the same steps for a whole job.

Fixing a missed or failed broadcast

The plan above is a missed broadcast. After the filter, sellers is 20,000 rows, but Spark estimated 58.6 MiB, which is over the 10 MB threshold. We ran the query three ways:

Plan Duration Shuffle written
Sort-merge join (AQE off) 18.5 s 9.5 GiB
Default: AQE converts to a broadcast join at runtime 14.0 s 9.5 GiB
BROADCAST hint 1.6 s 0

AQE noticed the small side once its shuffle finished and switched to a broadcast hash join. By then all 500 million order rows were already in shuffle files, so the conversion saved the sort and little else. The Spark docs call this conversion “not as efficient as planning a broadcast hash join in the first place”. Planning it up front was about 12 times faster here.

1. Add a hint. It overrides the size estimate for one join:

SELECT /*+ BROADCAST(s) */
       o.order_id, o.amount, o.order_date, s.seller_name, s.region
FROM orders o
JOIN sellers s ON o.seller_id = s.seller_id
WHERE s.tier = 'gold';
from pyspark.sql.functions import broadcast

gold = spark.table("sellers").where("tier = 'gold'")
joined = spark.table("orders").join(broadcast(gold), "seller_id")
# same effect: .join(gold.hint("broadcast"), "seller_id")

The plan becomes a BroadcastHashJoin with no Exchange on orders:

== Physical Plan ==
AdaptiveSparkPlan (10)
+- Project (9)
   +- BroadcastHashJoin Inner BuildRight (8)
      :- Project (3)
      :  +- Filter (2)
      :     +- Scan parquet spark_catalog.shop.orders (1)
      +- BroadcastExchange (7)
         +- Project (6)
            +- Filter (5)
               +- Scan parquet spark_catalog.shop.sellers (4)

2. Raise the threshold. SET spark.sql.autoBroadcastJoinThreshold = 100MB gave the same plan and time with no hint. It applies to every join in the session, so size it against memory: the 20,000-row broadcast above took 65 MiB once built as a hash table.

3. Fix the statistics. A small partitioned table with no statistics is never broadcast, because its size is unknown. In our test, a 20,000-row stores table planned as a sort-merge join until we ran:

ANALYZE TABLE stores COMPUTE STATISTICS NOSCAN;

Its estimate went from 8.0 EiB to 195.5 KiB and the plan flipped to a broadcast join. Column statistics (FOR COLUMNS) let Spark estimate filters once spark.sql.cbo.enabled is true, with a limit: it assumes values are evenly spread. With three tiers it estimated one third of sellers for tier = 'gold', when the real share was 1%. Use the hint for filters like that.

When a broadcast fails. The table is collected on the driver first, so an oversized one shows up as driver memory pressure or a timeout after spark.sql.broadcastTimeout (300 seconds). Spark also refuses to broadcast more than 512 million rows or more than spark.sql.maxBroadcastTableSize (8 GiB). A table that hits these limits is too big: remove the hint and treat the join as a shuffle join.

Skewed join keys

Skew is one key holding a large share of the rows. Every row with that key hashes to the same partition, so one task does the work of many. Find the key first, and count NULL as a key:

SELECT customer_id, count(*) AS orders
FROM orders
GROUP BY customer_id
ORDER BY orders DESC
LIMIT 5;
+-----------+---------+
|customer_id|   orders|
+-----------+---------+
|          1|100006280|
|       NULL| 14997058|
|    2707695|      128|
|     757172|      124|
|    4449431|      124|
+-----------+---------+

One guest-checkout account holds 20% of the orders, and 3% have no customer at all. An inner join drops NULL keys before the shuffle. An outer join keeps them, and they all land in one partition where they can never match. Filter them out before an outer join and add them back with UNION ALL if you need them.

What AQE does by default. After the shuffle, AQE treats a partition as skewed when it is larger than 5 times the median partition (spark.sql.adaptive.skewJoin.skewedPartitionFactor) and also larger than 256 MB (spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes). It splits that partition into pieces of about 64 MB and joins each piece to a copy of the matching partition from the other side. For a plain join of orders to customers, it split the hot partition into 24 tasks, the plan showed SortMergeJoin(skew=true), and the query took 26.0 s against 39.7 s with skew handling switched off.

Where AQE stops. The rule gives up when a split would force an extra shuffle. That happens as soon as the next operator relies on the join’s partitioning, as in this common query:

SELECT c.customer_id, c.segment, count(*) AS orders, sum(o.amount) AS revenue
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
GROUP BY c.customer_id, c.segment;
Spark UI stage page for the join stage of the GROUP BY query: 101 completed tasks, 2.8 min of total task time, 2.7 GiB of memory spill and 579.9 MiB of disk spill. In the Summary Metrics table, callout 1 marks Duration with a median of 1 s and a max of 25 s. Callout 2 marks Spill (memory) and Spill (disk), which are zero at the median and 2.7 GiB and 579.9 MiB at the max. Callout 3 marks Shuffle Read Size / Records with a median of 46.1 MiB and 3,900,403 records and a max of 623.3 MiB and 101,949,546 records.
Summary Metrics for the join stage of that query with default settings (Spark 4.3.0). (1) The median task took 1 s and the slowest took 25 s. (2) Only that task spilled. (3) It read 101.9 million records, 26 times the median.

The hot partition was 623 MiB, far over both thresholds, and AQE left it whole. AQE also ignores skew under 256 MB, and in an outer join it can split only the preserved side. When we put the skewed table on the other side (customers LEFT JOIN orders), the query failed: the hot key’s task ran out of heap, because a sort-merge join buffers every right-side row of a key, and here that was 100 million rows.

We tried four fixes on the GROUP BY query:

Approach Duration Longest task
Default, skew left in place 39.0 s 24.4 s
spark.sql.adaptive.forceOptimizeSkewedJoin = true 40.2 s 12.7 s
Salting with 16 salts 44.0 s 5.8 s
Aggregate orders before the join 29.0 s 2.0 s
Join the hot key on a broadcast path 23.5 s 2.7 s

Neither standard fix beat doing nothing. Forcing the split added a third shuffle for the GROUP BY, and the hot key piled up again in that shuffle. Salting removed the skew but paid for it elsewhere: the 5 million customers became 80 million rows and total task time roughly doubled. The two rewrites that did less work were clearly faster.

The broadcast path joins the hot key to its single matching row and joins everything else as before:

SELECT customer_id, segment, count(*) AS orders, sum(amount) AS revenue
FROM (
  SELECT /*+ BROADCAST(c) */ c.customer_id, c.segment, o.amount
  FROM orders o
  JOIN customers c ON o.customer_id = c.customer_id
  WHERE o.customer_id = 1 AND c.customer_id = 1
  UNION ALL
  SELECT c.customer_id, c.segment, o.amount
  FROM orders o
  JOIN customers c ON o.customer_id = c.customer_id
  WHERE o.customer_id <> 1
)
GROUP BY customer_id, segment;

Salting is still the general tool when many keys are hot or the query cannot be rewritten. Add a random salt to the skewed side, copy each row of the other side once per salt, and join on both columns:

WITH o AS (
  SELECT customer_id, amount, CAST(rand() * 16 AS INT) AS salt
  FROM orders
),
c AS (
  SELECT c.customer_id, c.segment, s.salt
  FROM customers c
  CROSS JOIN (SELECT explode(sequence(0, 15)) AS salt) s
)
SELECT c.customer_id, c.segment, count(*) AS orders, sum(o.amount) AS revenue
FROM o
JOIN c ON o.customer_id = c.customer_id AND o.salt = c.salt
GROUP BY c.customer_id, c.segment;

It pays off when one task dominates the job far more than it did here. Databricks also has a SKEW hint. It is Databricks-only, and its own documentation says AQE handles skew without it. Our data skew guide covers detection in more depth.

Shuffle partitions and spill

spark.sql.shuffle.partitions sets how many pieces every join shuffle is cut into, and it stays at 200 whatever the data size. With too few partitions, each task holds more rows than its share of memory and its sort spills to disk. With too many, the same data arrives as a swarm of tiny shuffle blocks.

Size it from the data. Divide the shuffle size (the join stage’s Shuffle Read, or shuffle bytes written on the Exchange nodes) by a target of roughly 100 to 200 MB per partition. Our join of 500 million orders to 500 million shipments shuffles 13.2 GiB, so the default of 200 was already about right. Moving it tenfold in either direction made the join slower (the default row is the median of six runs):

Partitions Duration Spill (disk) Shuffle blocks
20 49.8 s 14.6 GiB 8,660
200 (default) 37.6 s 0 86,600
2,000 78.0 s 0 866,000

Three things to know before you change it:

  • AQE only merges. Partition coalescing combines small partitions up to the 64 MB advisory size (spark.sql.adaptive.advisoryPartitionSizeInBytes). It never splits an ordinary large partition, so the number you set is a ceiling. At 2,000 partitions AQE merged them back into 250 tasks, but the 866,000 small blocks had already been written, and the join stage’s task time tripled.
  • parallelismFirst is on. With spark.sql.adaptive.coalescePartitions.parallelismFirst at its default of true, AQE ignores the advisory size on small shuffles to keep parallelism high. The Spark docs recommend false on a busy cluster.
  • Memory per core decides when a task spills. Each running task gets roughly (executor heap minus 300 MB) × 0.6 ÷ cores of execution memory, about 720 MB for our 5 GB, 4-core executors. More memory per core is the other fix for spill.

Joins that multiply rows

A join on a key that repeats on both sides returns the product of the matches. When a “dimension” quietly holds several rows per key, the join becomes a row generator. In our test, promotions held 674,000 rows for 200,000 products, so joining 500 million orders to it returned 1,685,065,416 rows and took 14.6 s. Reducing promotions to one row per product first returned 500 million rows in 5.7 s.

The SQL / DataFrame tab shows the problem directly: the join node’s number of output rows is larger than its biggest input. You can also predict the output before running the join:

SELECT sum(o.n * p.n) AS join_output_rows, sum(o.n) AS order_rows
FROM (SELECT product_id, count(*) AS n FROM orders GROUP BY product_id) o
JOIN (SELECT product_id, count(*) AS n FROM promotions GROUP BY product_id) p
  ON o.product_id = p.product_id;
+----------------+----------+
|join_output_rows|order_rows|
+----------------+----------+
|      1685065416| 500000000|
+----------------+----------+

If the extra rows are a mistake, deduplicate the repeating side before the join. If they are wanted but aggregated away afterwards, aggregate before the join.

Two plan shapes multiply the work without any duplicate keys:

  • Accidental cross joins. A missing or always-true join condition plans as a CartesianProduct or BroadcastNestedLoopJoin. Spark allows this by default (spark.sql.crossJoin.enabled is true), so nothing fails. The query just runs for a very long time.
  • Range joins. A condition such as o.order_date BETWEEN c.start_date AND c.end_date has no equality, so Spark compares every pair of rows in a nested loop. Joining 21.2 million orders to 2,000 campaigns this way meant 42 billion comparisons and took 7.6 s.

The fix for a range join is to give Spark an equality to hash on. Here each campaign is expanded to one row per active day:

SELECT o.order_id, c.campaign_id
FROM orders o
JOIN (
  SELECT campaign_id,
         explode(sequence(start_date, end_date)) AS active_date
  FROM campaigns
) c ON o.order_date = c.active_date
WHERE o.order_month = '2026-03';

That returned the same 306,846,614 rows in 1.2 s as a BroadcastHashJoin. For wide ranges, join on a coarser bucket such as the month and keep the range condition as an extra filter. Databricks offers a range join optimization with a RANGE_JOIN hint that does the binning for you. It is Databricks-only.

Reading less before the join

Every row dropped before the shuffle is a row that is never written, fetched, sorted or probed.

  • Filter and select early. Spark pushes simple filters and column pruning into the scan. Check PushedFilters and ReadSchema on the scan node, and avoid SELECT * on a wide table ahead of a join, because the columns you carry are the bytes you shuffle.
  • Dynamic partition pruning. When the big table is partitioned by the join key and the other side is a filtered table small enough to broadcast, Spark turns the broadcast keys into a partition filter. Joining orders, partitioned by month, to one fiscal quarter read 3 of 24 partitions (63 million of 500 million rows) and ran in 1.0 s, against 2.3 s with pruning switched off. Look for dynamicpruningexpression in the scan’s PartitionFilters.
  • Runtime Bloom filters. For join keys that are not partition columns, Spark can build a Bloom filter from a small, filtered side and apply it to the big side’s scan, ahead of the shuffle. It is on by default but narrowly guarded: the filtered side must be estimated under 10 MB, the scan it applies to must be estimated at 10 GB or more, and the plan must contain a shuffle to save. A table with no statistics counts as zero bytes here. In a join of orders to customers and to one product category, Spark added no Bloom filter until we ran ANALYZE TABLE orders COMPUTE STATISTICS NOSCAN. After that, a might_contain filter cut orders from 500 million rows to 9.6 million before the shuffle, and the query took 8.3 s against 17.9 s with the filter disabled. For the mechanics, see runtime Bloom filters in Spark joins.
  • Small files. Thousands of small files on the scan side mean thousands of tasks and file opens before the join starts. Compact them.

Avoiding the shuffle through layout

If two large tables are joined on the same key again and again, pay for the shuffle once, at write time.

Bucketing. Write both tables bucketed on the join key with the same number of buckets, and Spark joins matching buckets directly. The plan has no Exchange on either input. We bucketed orders and shipments into 256 buckets on order_id:

(spark.table("orders")
    .repartition(256, "order_id")
    .write.format("parquet")
    .bucketBy(256, "order_id").sortBy("order_id")
    .saveAsTable("orders_b"))

The join of the two bucketed tables took 17.3 s, against 37.6 s for the same join with two shuffles. The repartition before the write keeps it to one file per bucket. Bucketing only works for tables written through saveAsTable, and both sides need the same key and bucket count.

Storage-partitioned joins. Apache Iceberg™ tables get the same effect from a bucket() partition transform. With both tables created PARTITIONED BY (bucket(64, order_id)), the plan had two Exchange nodes by default and none after one setting (the backticks are needed because of the hyphens in the name):

SET `spark.sql.iceberg.planning.preserve-data-grouping` = true;

We checked this on Spark 4.1.4 with Iceberg 1.12.0, since Iceberg does not publish a runtime for Spark 4.3 yet. The Spark-side switch, spark.sql.sources.v2.bucketing.enabled, is true by default, and the Spark docs list the settings for partial matches.

repartition() and persisting. repartition() on the key helps only when the result is reused: repartition once, persist, and join it several times on that key. Before a single join it moves the same shuffle one step earlier. Likewise, when several queries start from the same join, compute that join once and cache it or write it out.

When the join is still slow after tuning

With all of that fixed, a large join can still be the slowest part of the job, because three costs are built into how open-source Spark runs it:

  • The sort, and a slow alternative. A sort-merge join sorts both inputs before it matches a single row. Spark’s own shuffled hash join skips the sort but builds its hash table one row at a time, and it was not a reliable win. With a SHUFFLE_HASH hint, our join of 500 million orders to 500 million shipments took 54.4 s against 37.6 s for sort-merge at 200 partitions, and 60.5 s against 78.0 s at 2,000.
  • Row-at-a-time execution. Spark reads Parquet in column batches, then converts them to rows (the ColumnarToRow node in the plan) and hashes, shuffles, sorts and joins one row at a time. No setting changes that.
  • Scanning to find matches. To join a small batch of keys to a large table, Spark reads the whole table unless partition pruning or a Bloom filter happens to line up with the join key.

These are properties of the engine, so what is left is an engine-level change: a native, vectorized engine that runs the same Spark plans. Databricks Photon, Apache Gluten™ and Apache DataFusion™ Comet are options. Quanton is another.

Quanton is the Spark engine from Onehouse, available on its own at quanton.dev. It runs without the Onehouse platform, on your own Kubernetes, and existing Spark SQL and PySpark jobs run on it unchanged. Its design rests on storage-aware planning, where it reads Apache Iceberg and Apache Hudi™ table metadata to reshape the plan, and on optimizing the read, the compute and the write of a job together (engine architecture). Quanton has an open core, the first 100 GiB processed each month is free (FAQ), and switching a job back to open-source Spark is one configuration line.

For joins, it changes the three costs above:

  • Hash join by default. Quanton runs equi-joins as a vectorized shuffle hash join and rewrites the sort-merge joins that Spark plans (how it works). The trade-off is memory: the build side of each partition has to fit, and it spills when it does not.
  • Fewer rows into the join. For eligible queries, a partial aggregate runs before the join, so the join and its shuffle handle one row per group (partial aggregation before joins).
  • Lookups in place of scans. An index-aware join looks up the incoming keys in a table index and reads only the row groups that hold matches (index-aware joins). The trade-off is the index: it has to be built and kept up to date, so a first run can be slower while it builds.

The published numbers are Onehouse’s own. On a 10 TB workload of 99 queries, Quanton finished in 2,034 seconds against 12,200 seconds for open-source Spark on the same 11 nodes, and it is close to Databricks Photon on these TPC-DS-style reads (benchmarks). These results are derived from TPC-DS and are not audited TPC results. NetApp has also published a validation run from its own lab, part of joint NetApp and Onehouse engineering work: a 1 TB TPC-DS suite in 795 seconds on Quanton against 3,489 seconds on open-source Spark (NetApp report).

If your join is still slow after everything above, test the engine on your own workload. You can sign up and run Quanton on its own, without the Onehouse platform, or start from the benchmarks and their methodology.

FAQs

Why is my Spark SQL join slow even with AQE enabled?

AQE acts on statistics it collects after a shuffle has finished. It can switch to a broadcast join only once the big side is already in shuffle files, it merges small partitions but never splits an ordinary large one, and its skew handling skips several cases. Check the executed plan for each of the three.

How do I see which join strategy Spark used?

Run EXPLAIN FORMATTED or df.explain(mode="formatted") for the planned strategy. For the strategy that actually ran, open the query in the SQL / DataFrame tab of the Spark UI. With AQE on, the two can differ.

What is the default broadcast join threshold in Spark?

spark.sql.autoBroadcastJoinThreshold defaults to 10 MB in Spark 4.3.0. Spark compares it with the estimated size of each join input. Setting it to -1 disables automatic broadcast joins, and a BROADCAST hint ignores it.

Is the SKEW hint available in open-source Spark?

No. The SKEW hint, the RANGE_JOIN hint, spark.databricks.* settings and spark.sql.shuffle.partitions = auto are Databricks features. In open-source Spark, skew is handled by AQE’s skew join settings or by rewriting the query.

Read More:

Subscribe to the Blog

Be the first to hear about news and product updates

We are hiring diverse, world-class talent — join us in building the future