Worst-Case Optimal Join Algorithms

Derive the AGM triangle bound from a fractional edge cover and see how Leapfrog Triejoin avoids enumerating a large unfiltered intermediate.

Source
Anbloq
Language
English
Created
Updated
Chapters
3
Reading time
2 min
In this article3 chapters
  1. A fractional cover controls result size
  2. An intermediate can be much larger than the answer
  3. Intersecting candidates before descending

A fractional cover controls result size

For attributes \(V\), view the schema of each joined relation \(R_e\) as a hyperedge \(e\). A fractional edge cover gives nonnegative weights \(x_e\) satisfying \(\sum_{e\ni v}x_e\ge1\) for every attribute \(v\). The AGM inequality bounds the number of distinct output tuples under set semantics by

\[ \left|\Join_{e}R_e\right|\le\prod_e|R_e|^{x_e}. \]

For \(R(A,B),S(B,C),T(A,C)\), weight each edge by one half. Each attribute appears twice and is covered with total weight one. If each relation has at most \(N\) tuples, the bound is \(N^{3/2}\). It is attained when every attribute ranges over a domain of size \(d\) and the three relations contain all pairs, with \(N=d^2\).

For a binary equijoin, key frequencies determine how many matching pairs are produced. A merge join shows how ordered inputs skip nonmatching keys, leading to the question of intersecting several constraints at once.

An intermediate can be much larger than the answer

Take \(R=\{(a_i,b):1\le i\le N\}\) and \(S=\{(b,c_j):1\le j\le N\}\) for a single shared value \(b\). Their binary join contains \(N^2\) triples. If \(T=\{(a_i,c_i):1\le i\le N\}\), only \(N\) survive. A plan that enumerates the intermediate before checking \(T=\{(a_i,c_i):1\le i\le N\}\) can do quadratic work even though the worst-case bound on the full join is subquadratic.

Intersecting candidates before descending

Leapfrog Triejoin fixes a global attribute order and reads each relation through a compatible ordered trie. At each prefix it advances ordered iterators to find values allowed by all relations constraining the next attribute. With order \(A,C,B\), the example only descends through pairs present in \(T=\{(a_i,c_i):1\le i\le N\}\). Formal worst-case comparisons include assumptions about index access, query shape and logarithmic factors. Practical plan choices also depend on index construction and skew, as in cost-based optimization and distributed graph query processing.[1][2][3]

References

  1. Albert Atserias, Martin Grohe and Dániel Marx, Size Bounds and Query Plans for Relational Joins ↩
  2. Todd L. Veldhuizen, Leapfrog Triejoin: A Simple, Worst-Case Optimal Join Algorithm ↩
  3. Hung Q. Ngo et al., Worst-Case Optimal Join Algorithms ↩