Course contents 12 / 35

12 / 35 · Distributed Computation

Distributed joins

Decide where matching rows meet and estimate the traffic of colocated, broadcast and repartitioned joins.

The report adds a product category to each sales line. The local join algorithms can match a line to a catalogue row once both are on one worker. Sales are placed by store, so the appropriate catalogue entry may be on another worker. The plan needs a rule for where the two inputs meet.

Keep rows together or copy the small side#

A colocated join runs locally if both inputs are already partitioned by compatible rules on the join key. If the fact and catalogue tables use the same hash of product_id and the same destination mapping, matching keys meet without moving either input for the join. A later stage can still require an exchange. Partitioning sales by product to help this join can make a report by store need more movement. (Greenplum 6, Distribution and skew)

The catalogue may be small enough to broadcast. Suppose its projected payload is 60 MB, initially divided among four workers with one copy of each row. Each worker keeps its part and sends it to the other three. The transferred payload is 3⋅60=1803 \cdot 60=180 MB in this model. Every worker can build a local lookup using the full catalogue and join its own sales. The catalogue copy and lookup structure must fit each worker’s budget. A 60 MB transfer representation does not determine the size of the in-memory structure. (Greenplum 6, Distribution and skew; Spark 3.5.8, Join strategy hints)

Figure

Three amounts of network payload

Three amounts of network payloadThe payload is zero with colocated data, 180 MB for a catalogue broadcast, and 450 GB plus 45 MB when both inputs are repartitioned under the uniform assumption.Colocated0Broadcast180 MBRepartition450 GB + 45 MB
The colocation case assumes the tables already share a compatible partitioner. The other rows use four destinations and the toy sizes in the text.

Repartition both inputs by the join key#

If the catalogue cannot be replicated within that budget, repartition both inputs by product_id. Each key is sent to one destination, so the worker there can run a local join. Use 600 GB of sales and the 60 MB catalogue to compare payloads. Assume four destinations, a uniform hash and initial placement independent of the target. One quarter of the bytes stay local in expectation. About 0.75⋅600=4500.75\cdot600=450 GB of sales and 0.75⋅60=450.75\cdot60=45 MB of catalogue data cross workers. If one table is already correctly partitioned, its movement can be avoided. These estimates omit compression and temporary I/O. (Schneider and DeWitt, 1989, §3)

A key can dominate its partition#

Hashing spreads different keys. It cannot divide a single key among multiple destinations under the stated rule. If half the sales payload belongs to one product, the destination for that product receives at least 300 GB of sales data, counting its existing local rows. A skew-aware plan can sometimes split the large matching group and duplicate the needed rows of the other side. It must still return each matching pair once. Broadcast avoids moving the sales by key, so it can preserve a useful balance already present in their store partitions. (Greenplum 6, Distribution and skew; Spark 3.5.8, Adaptive query execution)

Next#

A distributed plan now has local operators and boundaries that move data. The MapReduce model makes one such boundary part of the programming model and specifies which work can run again after a failure.

References#

  1. Greenplum Project. Distribution and Skew. Greenplum 6 documentation on colocated joins, data movement and skew.
  2. Apache Software Foundation. Performance Tuning. Spark 3.5.8 documentation on join strategies and skew optimization.
  3. Donovan A. Schneider and David J. DeWitt. A Performance Evaluation of Four Parallel Join Algorithms in a Shared-Nothing Multiprocessor Environment. University of Wisconsin TR836, 1989, §3 on parallel join algorithms and repartitioning.