Steps

A distributed query is processed in stages: (1) query decomposition into an algebra expression, (2) data localisation, in which global relations are replaced by their fragments and fragments that cannot contribute are removed, (3) global optimisation, which chooses the order of operations and the sites, and (4) local optimisation at each site.

Cost Model

In a local system the cost is mostly disk I/O. In a distributed system the cost is dominated by communication: the amount of data transferred and the number of messages. Cost ≈ (number of messages x start-up cost) + (bytes sent x transfer time per byte), so strategies mainly try to reduce the bytes moved.

Strategies for a Join

To join R at site 1 with S at site 2 and give the result at site 1:

  • Ship whole: send S to site 1, or R to site 2, and join there. It is simple but costly if the relation is large.
  • Semijoin: send only the join attribute values of R to site 2, find the tuples of S that match (S ⋉ R) and send only these back; then join at site 1. It pays off when only a small part of S matches, because dangling tuples are never shipped.
  • Bloom join: a compact bit-vector (Bloom filter) of R's join values is sent instead of the values.

Other rules: apply selections and projections before shipping, and send the smaller relation.

Definition: Semijoin. An operation R ⋉ S that returns the tuples of R that have a matching tuple in S, used in distributed queries to reduce the data sent between sites.

Table 3.4: Join strategies

Strategy What is shipped Best when
Ship whole A complete relation Relations are small
Semijoin Join column, then matching tuples Few tuples match
Bloom join Bit vector, then matching tuples Join column is large

Example 3.4: Semijoin against shipping the whole relation

Problem: R at site 1 has 1000 tuples of 100 bytes with a 10-byte join attribute. S at site 2 has 800 tuples of 100 bytes. The result is needed at site 1, and only 80 tuples of S match R. Compare shipping S with a semijoin.

Solution:

  1. Ship whole: send S to site 1 = 800 x 100 = 80,000 bytes.
  2. Semijoin step 1: send the join column of R to site 2 = 1000 x 10 = 10,000 bytes.
  3. Step 2: site 2 sends the 80 matching tuples = 80 x 100 = 8,000 bytes.
  4. Semijoin total = 10,000 + 8,000 = 18,000 bytes.

Result: The semijoin moves 18,000 bytes against 80,000, a saving of 62,000 bytes (77.5 percent).

r_tuples, r_join_bytes = 1000, 10
s_tuples, s_bytes = 800, 100
matching = 80
ship_whole = s_tuples * s_bytes
step1 = r_tuples * r_join_bytes
step2 = matching * s_bytes
semijoin = step1 + step2
print("Ship whole:", ship_whole, "bytes")
print("Semijoin  :", step1, "+", step2, "=", semijoin, "bytes")
print("Saving    :", ship_whole - semijoin, "bytes",
      f"({(ship_whole - semijoin) / ship_whole:.1%})")

Output

Ship whole: 80000 bytes
Semijoin  : 10000 + 8000 = 18000 bytes
Saving    : 62000 bytes (77.5%)

Common mistakes

  • Optimising only for disk I/O and ignoring the communication cost.
  • Using a semijoin when most tuples match, so that it adds extra messages.
  • Shipping the large relation to the small one.
  • Not applying selections and projections before shipping.

Key takeaways

  • Communication cost dominates in distributed query processing.
  • Stages: decomposition, localisation, global and local optimisation.
  • A semijoin ships the join column and only the matching tuples.
  • Reduce data early and ship the smaller relation.

Practice questions

  1. What dominates the cost in a distributed query?
  2. What does a semijoin avoid shipping?
  3. What is data localisation?

Answers to the practice questions

  1. Communication, meaning the data transferred and the messages sent.
  2. Tuples that have no match (dangling tuples).
  3. Replacing global relations by their fragments and removing the irrelevant ones.

Sources

  • Official BCA syllabus Advanced Database Systems, course code 25BCA406DS04, Unit III