Skip to main content
PYSPARK โ€ข LESSON 243

Broadcast Hash Join Optimization

How can we eliminate expensive cluster shuffles when joining a massive fact table with a small dimension table?

Expertโฑ 3 Minutesโญ 820 XP
๐Ÿค” THE QUESTION

How can we eliminate expensive cluster shuffles when joining a massive fact table with a small dimension table?

๐Ÿ’ก WHAT IS IT?

broadcast(df_small) copies the small dataset to all executor nodes, turning a shuffle join into a fast local hash join.

๐ŸŽฏ WHAT IS IT USED FOR?

Accelerating star-schema warehouse joins by 5x-10x when dimension tables are under 100MB.

๐Ÿ’ป EXAMPLE
df_joined = df_large_facts.join(broadcast(df_small_dim), "country_code")

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Broadcast Hash Join Optimization.

  • โœ“ broadcast() hint
  • โœ“ BroadcastHashJoin execution
  • โœ“ Shuffle elimination