IntermediateSpark · 14 min · 19 challenges

Joins: Intermediate

It's 6 a.m. at Uber and a city's surge report is late. The Spark job joins a day of trips to the driver table, filtered down to that city's 2MB of active drivers. Spark shuffled every trip anyway, because it planned the join from the driver table's full size. This lesson shows you why, and how one function call fixes it.

The Four Join Strategies

Daily Life
Interviews
A join in your code names a type, such as inner or left outer. Catalyst's physical planning then decides how each join runs on the cluster, choosing one of 4 strategies. The strategy decides whether rows cross the network, how many of them cross, and how much memory one task needs. 2 queries that return identical rows can differ by an hour of runtime because the planner chose differently.

The 4 strategies side by side

StrategyPlan operatorWhat movesWhen Spark picks it
Broadcast hash joinBroadcastHashJoinThe small side is copied to every executor; the large side stays where it was readEquality key, and a side the join type lets Spark build is estimated at or under the broadcast threshold
Shuffle hash joinShuffledHashJoinBoth sides are shuffled by key; each task hashes its share of the smaller sideEquality key, and either sort-merge is not preferred and the smaller side is under about 2GB, or the key type cannot be sorted
Sort-merge joinSortMergeJoinBoth sides are shuffled by key, then sorted by key inside each partitionEquality key on sortable types, with no side small enough to broadcast
Nested loop joinBroadcastNestedLoopJoin or CartesianProductEvery row of one side is tested against every row of the otherNo equality key, as in a range or inequality condition

The broadcast hash join is the strategy the planner tries before anything else, because it adds no shuffle and no stage boundary. The sort-merge join is the default for 2 large inputs. Each side passes through an exchange that hash-partitions it on the join key into spark.sql.shuffle.partitions partitions, 200 by default, so equal keys from both sides land in the same task, which sorts both of its inputs by key before matching them. Spark's documentation for spark.sql.join.preferSortMergeJoin, which defaults to true, gives the reason it is preferred: it uses less memory than a shuffle hash join and works efficiently when both tables are large.

The shuffle hash join shuffles both sides the same way and skips the sort. Each task builds a hash table from its partition of the smaller side, so that table has to fit in the task's memory. With default settings and no hint, Spark picks it only when the join key's type cannot be sorted. The nested loop join is the last resort. With no equality between the sides there is no key to hash or sort on, so rows are compared pair by pair: Spark broadcasts one side when it can (BroadcastNestedLoopJoin), and an inner join with neither side small enough runs as a CartesianProduct.

The order the planner checks

With no hint, Spark asks these questions of each join, in order
  • 1. Is there an equality key? If the condition has no a = b between the 2 sides, only nested loop strategies remain.
  • 2. Can a side be broadcast? If a side the join type lets Spark build has an estimate at or under spark.sql.autoBroadcastJoinThreshold, 10MB by default, Spark plans a broadcast hash join.
  • 3. Is a shuffle hash join allowed? Only if spark.sql.join.preferSortMergeJoin is false and the smaller side is at least 3 times smaller than the other and estimated under the threshold times spark.sql.shuffle.partitions, about 2GB by default, or if the key cannot be sorted.
  • 4. Otherwise, sort-merge. Every equality join on sortable keys that reaches this question gets a sort-merge join.

The join type limits the build side

In an outer join, an unmatched row from the preserved side must still come out, padded with NULLs. If the preserved side were the broadcast copy, every task would hold all of its rows but see only a slice of the other side, so no task could tell whether a row went unmatched everywhere. A broadcast hash join therefore builds only the side that is not preserved:
Join typeSide Spark may broadcast
innerEither; the smaller estimate wins
left outer, left semi, left antiRight only
right outerLeft only
full outerNeither, so no broadcast hash join

The animation below sets the threshold to -1 in its first line, so 2 small tables join the way 2 large ones would. Watch orders and payments both leave their read tasks and cross the shuffle by order_id into 3 reducer tasks, where equal keys meet. Order 102 has no payment and payment 107 has no order, so the inner join returns 5 rows.

spark.conf.set("spark.sql.autoBroadcastJoinThreshold", -1)
orders.join(payments, "order_id").collect()
orders6 rows
order_id
region
101
West
102
East
103
West
104
North
105
East
106
South
payments6 rows
order_id
amount
101
25
103
40.5
104
12
105
60
106
33.25
107
18
Preparing the animation

Hints override the questions above. F.broadcast(df) or df.hint("broadcast") requests a broadcast, df.hint("merge") a sort-merge join, df.hint("shuffle_hash") a shuffle hash join and df.hint("shuffle_replicate_nl") a Cartesian product. When the sides carry different hints, Spark's documented priority runs in that same order, broadcast first. A hint the join type cannot honour is dropped with a warning in the driver log.

Multiple Choice

regions is 2MB and orders is 400GB, both read from Parquet, with default settings. Which strategy does Spark plan for this join?

report = regions.join(orders, "region_id", "left")
To predict a strategy, ask the 4 questions in order and check the join type against the side you hope to build. The next section takes question 2 apart.

The 10MB Broadcast Threshold

Daily Life
Interviews

Question 2 depends on one setting, spark.sql.autoBroadcastJoinThreshold. The default, 10485760 bytes, is 10MB. Setting it to -1 turns automatic broadcasting off. At planning time Spark compares each buildable side's estimated size with this number and broadcasts a side at or under it without being asked. The estimate is made before any data is read, so a wrong estimate means a wrong decision.

Where the estimate comes from

Spark starts at each scan with a size in bytes and carries it up the plan, changing it only where a rule says to. With cost-based optimization off, unless a row says otherwise:
Plan nodeEstimated size in bytes
Scan of Parquet or other filesTotal size of the files on disk
Catalog table with computed statisticsThe size stored by ANALYZE TABLE ... COMPUTE STATISTICS
Projection to fewer columnsThe input's estimate, scaled down by the narrower row width
FilterThe input's estimate, unchanged
Filter, with cost-based optimization and column statisticsThe input's estimate, scaled by the predicted fraction of rows kept

The plain filter row is the one that slows real jobs. A 4GB drivers table filtered to one city's active drivers might keep 2MB of rows, but its estimate stays at 4GB, reduced at most for the columns dropped. Spark sees a side far over 10MB, plans a sort-merge join, and shuffles every trip to meet 2MB of drivers. The error runs the other way too: a heavily compressed file gives a small estimate for rows that are much larger once decoded, which the next section returns to.

Multiple Choice

A Parquet campaigns table is 6GB on disk. A job filters it to 3MB of active campaigns and inner-joins it to a 500GB clicks table. Cost-based optimization is off and the threshold is the default. What does Spark plan?

Overruling the estimate with broadcast()

from pyspark.sql import functions as F
trips = spark.read.parquet("/warehouse/trips")
drivers = spark.read.parquet("/warehouse/drivers")
city_drivers = drivers.filter(
(F.col("city_id") == 17) & (F.col("status") == "active")
)
trips_with_drivers = trips.join(F.broadcast(city_drivers), "driver_id")

F.broadcast adds a hint to the plan. It does not read the data or check its size. A hint outranks the threshold, so it still applies when automatic broadcasting is set to -1, and city_drivers.hint("broadcast") has the same effect.

Loading the challenge

The animation sets the threshold to -1 to stand in for an estimate too large to qualify, so the hint is the only reason active gets broadcast. Watch the 3 active products reach both orders tasks while no order row moves. Product 5120 is the inactive fax machine, so its order finds no match and drops out.

spark.conf.set("spark.sql.autoBroadcastJoinThreshold", -1)
active = products.filter(F.col("active") == 1)
orders.join(F.broadcast(active), "product_id").collect()
orders6 rows
order_id
product_id
1
4017
2
2210
3
4017
4
3305
5
5120
6
2210
products4 rows
product_id
product_name
active
4017
Desk lamp
1
2210
Notebook
1
3305
Headphones
1
5120
Fax machine
0
Preparing the animation

Raise the threshold or hint the join

✓Raising the threshold
  • Applies to every join in every query the session runs
  • Trusts each estimate, including the ones that are too small
  • Lets a side grow past the size you tested with no change in code
✗Hinting one join
  • Applies only to the DataFrame you wrapped
  • Overrides an estimate you have checked and found too large
  • Keeps broadcasting after that side grows, until someone removes it

Spark can also refuse a hint. If the join type cannot build the side you marked, as with the left side of a left outer join, Spark drops the hint with a warning and plans the join without it. The code still reads F.broadcast, so the plan is where you confirm what happened.

Run the cell below. It broadcasts the in-stock products and totals units sold per category. Then change F.col("in_stock") to ~F.col("in_stock") and run it again: the join and the hint stay the same while the rows on the broadcast side change. On seed tables this small, Spark would broadcast products even without the hint.

from pyspark.sql import functions as F

order_items = spark.table("order_items")
products = spark.table("products")

stocked = products.filter(F.col("in_stock") & F.col("category").isNotNull())

units_by_category = (
    order_items
    .join(F.broadcast(stocked), "product_id")
    .groupBy("category")
    .agg(F.sum("quantity").alias("units_sold"))
    .orderBy("category")
)
units_by_category.show()
The hint guarantees a broadcast. It says nothing about whether broadcasting is wise at the size you aimed it at, and that limit is the next section's subject.

The Real Broadcast Ceiling

Daily Life
Interviews

spark.sql.autoBroadcastJoinThreshold accepts any number of bytes, and F.broadcast accepts any DataFrame. Neither checks whether the cluster can carry what it asks for. The real limit comes from where a broadcast's bytes have to sit, and in practice it lands between 1 and 2GB of decoded rows, far below the hard cap Spark itself enforces.

8GB
largest table Spark will broadcast
300s
default spark.sql.broadcastTimeout

Where a broadcast's bytes sit

executors
Small side read tasks
driver
Driver collects rows
driver
Driver builds hash table
executor memory
Copy on executor 1
executor memory
Copy on executor 2
executor memory
Copy on executor 40
executors
Large side tasks probe

The small side's rows travel to the driver, become one hash table there, and that table is copied whole to every executor before any task of the large side can probe it.

Every step holds the whole table. The driver receives each row of the small side as a task result, so the collected bytes count against spark.driver.maxResultSize, which defaults to 1GB. They must also fit in the driver's own memory, which is 1GB too unless --driver-memory raises it. The driver then builds the hash table while still holding the rows it came from. Each executor keeps its own complete copy while its tasks run, in the same memory those tasks use.

A 1.5GB dimension on 40 executors

WhereWhat it holdsSize
Driver, collectingEvery row of the dimension1.5GB
Driver, buildingThe rows plus the hash table built from themAbout 3GB at the peak
Each executorOne full copy of the hash table1.5GB
All 40 executors40 copies60GB of memory
NetworkOne copy delivered to each executor60GB moved
Compare that with the shuffle it replaces. If the large side is 200GB, a sort-merge join moves about 201.5GB through the shuffle, so this broadcast still moves fewer bytes. At 1.5GB the limit that bites is memory: the driver needs about 3GB free at one moment, and every executor gives up 1.5GB to a table that stays resident while its tasks run. Make the dimension 6GB and the bytes turn against it as well: 240GB of copies against a shuffle of roughly 206GB, plus a 6GB build on a single machine.

Disk bytes and memory bytes

The threshold compares an estimate built from file sizes, and files are compressed and encoded. A Parquet table can grow several times over when decoded into rows, so 300MB on disk can become more than 1GB of hash table. Raising the threshold to 2GB lets through tables whose decoded size nobody has checked. The number that gives a broadcast's real size is the data size the Spark UI reports for its broadcast exchange, covered in the next section.
✓A broadcast that is too big
  • The driver runs out of memory while collecting or building, and the query fails
  • Collected rows pass spark.driver.maxResultSize, and the job is aborted
  • The build outlasts spark.sql.broadcastTimeout, and the query fails
✗A sort-merge join that is too big
  • Stages take longer as more bytes cross the shuffle
  • Each task handles only its own partition of each side
  • Growth usually costs time before it costs the job

Why the ceiling sits at 1 to 2GB

Under around 1GB of decoded rows, a broadcast fits a driver given a few GB of memory, stays inside a raised spark.driver.maxResultSize, and costs each executor a small slice of its memory. Between 1 and 2GB it runs on a cluster configured for it and fails on one that is not, and a small error in the assumed size tips it over. Past 2GB, the build on one driver and the copy on every executor leave the job one memory shortfall away from failing, and on wide clusters the copies rival the shuffle they replace, as the 6GB case showed. Setting the threshold to 5GB does not move the ceiling: the driver and executors still have to hold whatever it lets through.

✓Do
  • Measure a broadcast as decoded rows from a real run, not as files on disk
  • Keep each broadcast under around 1GB
  • Raise driver memory and maxResultSize together for a broadcast near 1GB
✗Don't
  • Set the threshold to gigabytes to rescue one slow join
  • Treat a file's size on disk as the size of its hash table
  • Leave a hint on a dimension that grows every month without checking it again
Multiple Choice

A dimension is 900MB of Parquet on disk. To make it broadcast, someone sets the threshold to 1GB. What is the main risk?

A broadcast either fits everywhere it has to be or fails the query, so the size worth knowing is the one measured from a real run. The next section reads the plan to find out what Spark decided.

Verifying with explain()

Daily Life
Interviews

Code shows what you asked Spark to do. The physical plan shows what it decided, and they can differ: a hint can be dropped, an estimate can fall on the other side of 10MB, and a join you expected to broadcast can arrive as a sort-merge. explain() prints the physical plan without running the query, so you can check before spending an hour of cluster time.

trips_with_drivers = trips.join(F.broadcast(city_drivers), "driver_id")
trips_with_drivers.explain()

Here is that plan, trimmed, beside the plan for the same join without the hint, where the estimate sent it to sort-merge. Read each tree from the bottom up: the scans are the leaves, :- marks a node's first child and +- its last.

With F.broadcast
Physical plan line
BroadcastHashJoin [driver_id#14], [driver_id#31], Inner, BuildRight, false
:- Filter isnotnull(driver_id#14)
: +- FileScan parquet [trip_id#12,driver_id#14,fare#15]
+- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false)
+- Filter ((city_id#33 = 17) AND (status#34 = active) AND isnotnull(driver_id#31))
+- FileScan parquet [driver_id#31,city_id#33,status#34]
Without the hint
Physical plan line
SortMergeJoin [driver_id#14], [driver_id#31], Inner
:- Sort [driver_id#14 ASC NULLS FIRST], false, 0
: +- Exchange hashpartitioning(driver_id#14, 200), ENSURE_REQUIREMENTS
: +- Filter isnotnull(driver_id#14)
: +- FileScan parquet [trip_id#12,driver_id#14,fare#15]
+- Sort [driver_id#31 ASC NULLS FIRST], false, 0
+- Exchange hashpartitioning(driver_id#31, 200), ENSURE_REQUIREMENTS
+- Filter ((city_id#33 = 17) AND (status#34 = active) AND isnotnull(driver_id#31))
+- FileScan parquet [driver_id#31,city_id#33,status#34]

4 checks on every join line

  • Name the operator. The first word on the join line is the strategy: BroadcastHashJoin, ShuffledHashJoin, SortMergeJoin, BroadcastNestedLoopJoin or CartesianProduct.
  • Read the build side. BuildRight or BuildLeft names the child Spark turns into the hash table. In a broadcast hash join, that child is the side sent to every executor.
  • Find the broadcast exchange. BroadcastExchange should sit directly under the child the build side names. Its argument gives the key column the hash table is built on, by position.
  • Count the shuffles. Each Exchange hashpartitioning line is one shuffle. The broadcast plan above has none; the sort-merge plan has 2, one per side, each into 200 partitions.

Inner after the keys is the join type. Each Sort under the sort-merge join orders one side within its partitions, after that side's exchange. The isnotnull(driver_id...) filters are ones Catalyst added: an inner join can never match a NULL key, so those rows are dropped at the scan.

//

The line above the join

A recent Spark prints one more line at the top of the plan, beginning with AdaptiveSparkPlan. It wraps the plan and is covered in a later lesson. The join operators beneath it read the same way.

Catching a dropped hint

report = F.broadcast(regions).join(orders, "region_id", "left")
report.explain()

The code asks for regions to be broadcast, but a left outer join preserves its left side, so Spark cannot build regions and discards the hint with a warning on the driver. The plan's join line reads SortMergeJoin [region_id#3], [region_id#9], LeftOuter, with an Exchange hashpartitioning under each side. To get every order with its region, write orders.join(F.broadcast(regions), "region_id", "left"): that join type can build the right side, and the plan shows BroadcastHashJoin ... LeftOuter, BuildRight. To keep every region, including those with no orders, the original join is correct and sort-merge is its strategy.

The plan that ran

explain() prints the plan Spark intends to run. After a query has run, the SQL tab of the Spark UI draws the plan it executed as a graph of the same operators, with metrics on each. The BroadcastExchange node reports the data size actually broadcast, the measured number the previous section asked for, along with the time spent collecting the rows and the time spent building and broadcasting the table. Each Exchange node under a sort-merge join reports the bytes its side wrote to the shuffle.

Multiple Choice

Running explain() on events.join(users, "user_id") prints this join line: BroadcastHashJoin [user_id#4], [user_id#19], Inner, BuildLeft, false. Which DataFrame was broadcast?

Make the plan the last check before a join goes to production. The operator and its build side tell you which strategy will run, and the count of exchanges tells you how many shuffles the join will pay for. The final section uses those counts to order several joins.

Ordering a Multi-Table Join

Daily Life
Interviews

A chain of joins runs in the order you wrote it. a.join(b, ...).join(c, ...) builds the tree (a join b) join c, and the output of the first join becomes the left input of the next. Catalyst moves a join only to avoid a Cartesian product, when the written order would pair tables that share no key. It reorders by cost only when the tables have statistics and cost-based optimization is on with spark.sql.cbo.joinReorder.enabled set to true, a setting that is false by default. In every other case, the order on the page is the order the cluster pays for.

What a join's position costs

Take a click report. clicks holds 2 billion rows. campaigns holds 4,000 rows, of which 400 are active, and clicks on active campaigns are 10% of all clicks. users holds 80 million rows, far too large to broadcast. Both joins are inner joins, so both orders return the same rows.

OrderFirst joinNext joinRows shuffled
A: clicks, users, campaignsSort-merge with users: 2B + 80M rows shuffledBroadcast active campaigns: no shuffle, 2B rows in, 200M out2.08B
B: clicks, campaigns, usersBroadcast active campaigns: no shuffle, 2B rows in, 200M outSort-merge with users: 200M + 80M rows shuffled280M
7.4x
fewer rows shuffled in order B
1.8B
click rows that never reach a shuffle
Order B runs the filtering join first, so 9 of every 10 clicks are dropped in the scan stage before anything crosses the network, and the sort-merge join that follows shuffles a tenth of the clicks.

When the lookups that shrink or label the fact table can all broadcast, they run before any shuffle at all. In the animation, orders joins a broadcast customers and then a broadcast products: both small tables reach every task, the order rows never move, and both joins pipeline into the scan's stage.

(orders
.join(F.broadcast(customers), "customer_id")
.join(F.broadcast(products), "product_id")
.collect())
orders6 rows
order_id
customer_id
product_id
1
c1
11
2
c2
12
3
c1
13
4
c3
11
5
c2
13
6
c3
12
customers3 rows
customer_id
segment
c1
Retail
c2
Wholesale
c3
Retail
products3 rows
product_id
category
11
Kitchen
12
Garden
13
Toys
Preparing the animation
Multiple Choice

events holds 3 billion rows. It joins sessions (900 million rows, too large to broadcast) on session_id, and test_groups (2,000 rows) on user_id, an inner join that keeps 5% of events. Settings are the defaults. Which order shuffles the fewest rows?

4 rules for ordering

  • Filter before joiningEvery table, every timeApply each table's own filters before its first join. Catalyst pushes most single-table filters down, but a condition comparing columns of 2 tables waits until both have joined.
  • Most selective join firstShrink the large side earlyStart with the join that drops the most rows of the large table, usually an inner join to a filtered dimension. Broadcast, it shrinks the data before any shuffle.
  • Multiplying joins lastExpand as late as possibleA one-to-many join, such as orders to order items, raises the row count, and every later join carries the extra rows.
  • Same key, side by sideReuse the partitioningAfter a sort-merge join on order_id, the result is hash partitioned on order_id, so a following join on order_id shuffles only the new table.
Loading the challenge
//

Counting shuffles in a chain

Rule 4 shows in the shuffle count. Say none of the 4 tables orders, payments, shipments and customers is small enough to broadcast. payments and shipments join on order_id, while customers joins on customer_id:

Written orderShufflesWhat gets shuffled
orders, payments, shipments, customers5orders, payments and shipments once each; then the joined result and customers on customer_id
orders, payments, customers, shipments6orders and payments; the result and customers on customer_id; that result again and shipments on order_id
In the costlier order the joined result crosses the network 2 times instead of once, and on its last trip it carries the columns of 3 tables.

Run the cell below. It filters orders to completed orders before the first join, brings in the one-to-many order_items after that filter, and broadcasts only the 2 columns of products it needs.

from pyspark.sql import functions as F

orders = spark.table("orders")
order_items = spark.table("order_items")
products = spark.table("products")

completed = orders.filter(F.col("status") == "Completed").select("order_id")
categories = products.select("product_id", "category").filter(F.col("category").isNotNull())

revenue_by_category = (
    completed
    .join(order_items, "order_id")
    .join(F.broadcast(categories), "product_id")
    .groupBy("category")
    .agg(F.round(F.sum(F.col("quantity") * F.col("unit_price")), 2).alias("revenue"))
    .orderBy("category")
)
revenue_by_category.show()
Before writing a chain of joins, estimate the rows each join leaves, and put the joins that leave the fewest first. Then read the plan and confirm the exchanges land where you expected.
PUTTING IT ALL TOGETHER

> Back at Uber, the late surge report joins a day of trips to the driver table filtered to one city's 2MB of active drivers, then to a small city table and a rider table too large to broadcast. The slow run shuffled every trip because the filtered drivers still carried the 4GB estimate of the full table. The fix wraps the filtered drivers in F.broadcast, keeps the city table as an automatic broadcast, and moves the rider join to the end of the chain.

The estimate rules explain the slow run: a filter passes the drivers table's 4GB file-size estimate up unchanged, far over 10MB, so the planner chose sort-merge.
F.broadcast overrides that estimate, and the inner join type lets Spark build the drivers side.
2MB of drivers is far below the 1 to 2GB ceiling, so a copy on every executor costs little, while the rider table stays a sort-merge join because a copy of it would not fit.
explain() shows BroadcastHashJoin with BuildRight above the drivers scan and no Exchange on that join, and after the run the SQL tab's broadcast exchange reports the real size.
Running the drivers join first drops every trip outside the city inside the scan stage, so the rider sort-merge join shuffles only the trips that remain.
KEY TAKEAWAYS
Spark picks among 4 join strategies: broadcast hash, shuffle hash, sort-merge and nested loop. The join type limits which sides Spark may build, and within that limit the equality key and the size estimates pick the strategy.
A side is broadcast automatically when its estimated size is at or under spark.sql.autoBroadcastJoinThreshold, 10MB by default.
With cost-based optimization off, a filter never lowers the estimate, so a filtered dimension needs F.broadcast to be broadcast.
The join type fixes the side that can be built: a left outer join can broadcast only its right side, and a full outer join neither.
A broadcast sits whole on the driver during the build and on every executor, so the practical ceiling is 1 to 2GB of decoded rows.
explain() shows the operator with its build side, plus every Exchange; the SQL tab of the Spark UI shows what ran and the broadcast's real size.
Spark joins tables in the order written by default, so run the most selective joins first and keep same-key joins together.

How Spark picks a join strategy, when to overrule it with broadcast(), and how to confirm the plan it ran.

Category
Spark
Difficulty
intermediate
Duration
14 minutes
Challenges
19 hands-on challenges

Topics covered: The Four Join Strategies, The 10MB Broadcast Threshold, The Real Broadcast Ceiling, Verifying with explain(), Ordering a Multi-Table Join

Lesson Sections

  1. The Four Join Strategies

    A join in your code names a type, such as inner or left outer. Catalyst's physical planning then decides how each join runs on the cluster, choosing one of 4 strategies. The strategy decides whether rows cross the network, how many of them cross, and how much memory one task needs. 2 queries that return identical rows can differ by an hour of runtime because the planner chose differently. The 4 strategies side by side The order the planner checks The join type limits the build side In an outer j

  2. The 10MB Broadcast Threshold (concepts: Broadcast Join)

    Where the estimate comes from Spark starts at each scan with a size in bytes and carries it up the plan, changing it only where a rule says to. With cost-based optimization off, unless a row says otherwise: Overruling the estimate with broadcast() Raise the threshold or hint the join The hint guarantees a broadcast. It says nothing about whether broadcasting is wise at the size you aimed it at, and that limit is the next section's subject.

  3. The Real Broadcast Ceiling (concepts: Broadcast Join)

    Where a broadcast's bytes sit A 1.5GB dimension on 40 executors Compare that with the shuffle it replaces. If the large side is 200GB, a sort-merge join moves about 201.5GB through the shuffle, so this broadcast still moves fewer bytes. At 1.5GB the limit that bites is memory: the driver needs about 3GB free at one moment, and every executor gives up 1.5GB to a table that stays resident while its tasks run. Make the dimension 6GB and the bytes turn against it as well: 240GB of copies against a s

  4. Verifying with explain() (concepts: Broadcast Join)

    4 checks on every join line The line above the join A recent Spark prints one more line at the top of the plan, beginning with AdaptiveSparkPlan. It wraps the plan and is covered in a later lesson. The join operators beneath it read the same way. Catching a dropped hint The plan that ran Make the plan the last check before a join goes to production. The operator and its build side tell you which strategy will run, and the count of exchanges tells you how many shuffles the join will pay for. The

  5. Ordering a Multi-Table Join

    What a join's position costs Order B runs the filtering join first, so 9 of every 10 clicks are dropped in the scan stage before anything crosses the network, and the sort-merge join that follows shuffles a tenth of the clicks. 4 rules for ordering Counting shuffles in a chain In the costlier order the joined result crosses the network 2 times instead of once, and on its last trip it carries the columns of 3 tables. Before writing a chain of joins, estimate the rows each join leaves, and put the