Source-linked AI summary

Leapfrog Triejoin: a worst-case optimal join algorithm

Todd L. Veldhuizen

arXiv:1210.0481v5cs.DBcs.DS

TL;DR

The paper asks whether leapfrog triejoin can match the worst-case guarantees of NPRR and remain optimal on finer-grained database-instance families. It analyzes the algorithm’s variable-oriented execution and proves near-optimal complexity, including stronger results for projection-constrained instances. The results position leapfrog triejoin as a simple, practical join algorithm with a concise optimality proof.

  • Problem

    The paper investigates whether LogicBlox’s leapfrog triejoin, motivated by favorable preliminary benchmarks against NPRR, has matching worst-case guarantees and stronger optimality for finer-grained instance classes.

  • Method

    The paper analyzes leapfrog triejoin as a variable-oriented backtracking algorithm that joins input relations simultaneously without producing intermediate results.

  • Results

    Leapfrog triejoin runs in O(Q∗log n), and is worst-case optimal for finer-grained families where NPRR is not, including projection-cardinality classes.

  • Takeaways & Limitations

    Leapfrog triejoin offers a useful addition to join-algorithm toolboxes because it is easy to understand, straightforward to implement, and practically used in LogicBlox.

  • Takeaways & Limitations

    The complexity analysis does not immediately encompass extensions such as ∃1 queries and requires suitable iterator-operation bounds for some nonmaterialized presentations.

Abstract

from arXiv · show

Recent years have seen exciting developments in join algorithms. In 2008, Atserias, Grohe and Marx (henceforth AGM) proved a tight bound on the maximum result size of a full conjunctive query, given constraints on the input relation sizes. In 2012, Ngo, Porat, R{é} and Rudra (henceforth NPRR) devised a join algorithm with worst-case running time proportional to the AGM bound. Our commercial Datalog system LogicBlox employs a novel join algorithm, \emph{leapfrog triejoin}, which compared conspicuously well to the NPRR algorithm in preliminary benchmarks. This spurred us to analyze the complexity of leapfrog triejoin. In this paper we establish that leapfrog triejoin is also worst-case optimal, up to a log factor, in the sense of NPRR. We improve on the results of NPRR by proving that leapfrog triejoin achieves worst-case optimality for finer-grained classes of database instances, such as those defined by constraints on projection cardinalities. We show that NPRR is \emph{not} worst-case optimal for such classes, giving a counterexample where leapfrog triejoin runs in $O(n \log n)$ time, compared to $Θ(n^{1.375})$ time for NPRR. On a practical note, leapfrog triejoin can be implemented using conventional data structures such as B-trees, and extends naturally to $\exists_1$ queries. We believe our algorithm offers a useful addition to the existing toolbox of join algorithms, being easy to absorb, simple to implement, and having a concise optimality proof.

1. INTRODUCTION

Join processing asks how large query results can be and how efficiently they can be enumerated. The paper analyzes leapfrog triejoin, showing near-optimal worst-case complexity and stronger optimality for finer-grained instance families.

  • Motivation and prior work: The AGM bound gives a tight maximum result size, while NPRR matches it with worst-case running time O(Q∗).For equal relation sizes n in the triangle example, the bound is n3/2.
  • Motivation and prior work: Preliminary benchmarks motivated analysis after leapfrog triejoin performed dramatically better than NPRR on some test problems.Leapfrog triejoin was LogicBlox’s proprietary join algorithm at the time.
  • Leapfrog triejoin: Leapfrog triejoin joins all input relations simultaneously and uses a variable-oriented backtracking search without producing intermediate results.It binds variables in sequence to enumerate satisfying assignments.
  • Main result: Leapfrog triejoin achieves running time O(Q∗log n), where Q∗ is the fractional cover bound and n is the largest input-relation cardinality.A variant eliminates the logarithmic factor and achieves O(Q∗) time.
  • Practical significance: The authors present leapfrog triejoin as easy to understand, simple to implement, and a practical workhorse of LogicBlox.The paper emphasizes its concise optimality proof and conventional implementation approach.
  • Main result: The paper proves optimality over finer-grained instance families and reports an example where leapfrog triejoin takes O(n log n) versus Θ(n^1.375) for NPRR.These families can be defined by projection-cardinality constraints.

2. PRELIMINARIES AND BACKGROUND

The preliminaries introduce the fractional edge cover bound and its linear-programming formulation for worst-case join-result size. The dual formulation provides constructive cross-product instances that attain the bound, while motivating finer-grained analyses.

  • Conventions: The analysis uses the RAM machine model, base-2 logarithms, finite database instances, and set rather than multiset query semantics.The implementation requires only totally ordered types, although the presentation uses subsets of N.
  • Fractional edge cover: The fractional edge cover bound is a tight upper bound on full conjunctive-query result size and can be computed from relation-cardinality constraints.The paper’s leapfrog triejoin complexity analysis is formulated using maximum query-result size Q∗.
  • Fractional edge cover: For Q(a,b,c)=R(a,b), S(b,c), T(a,c), the query hypergraph has variables as vertices and relation atoms as edges.An edge cover assigns weights to edges so every variable is covered.
  • Fractional edge cover: A fractional edge cover relaxes edge-cover weights to the interval from 0 to 1 and bounds log |Q| by the weighted sum of relation logarithms.Minimizing this expression yields the AGM bound.
  • Dual formulation: For equal relation sizes n, the triangle query has bound |Q| ≤ n3/2, attained by a cross-product result with three dimensions of size n1/2.The construction can be padded to attain the desired relation sizes while preserving a maximal query result.
  • Dual formulation: The dual linear program maximizes the logarithmic dimensions of a cross-product subject to projection-size constraints, yielding the same bound by linear-program duality.This dual form is constructive and supplies worst-case instances.
  • Motivation for refinement: Because worst-case AGM instances are cross-products rarely materialized in practice, AGM-optimality alone may not imply optimality for practical instance classes.This observation motivates finer-grained complexity analysis.

3. LEAPFROG TRIEJOIN

Leapfrog triejoin builds joins from iterator-based intersections, extending unary leapfrog join to trie-structured relations and backtracking over query variables. Its complexity is analyzed under fixed-query data complexity, with bounds based on the smallest relation and demonstrated advantages over pairwise joins.

  • Scope: Leapfrog triejoin targets ∃1 queries, while the paper's complexity analysis focuses on their full conjunctive fragment.The algorithm can be extended to ∃1 queries with additional machinery, but the main analysis concerns full conjunctive queries.
  • Unary leapfrog join: Unary leapfrog join simultaneously intersects sorted unary relations through linear iterators supporting key(), next(), seek(), and atEnd().The join itself exposes the same iterator interface, allowing it to serve as the building block for triejoin.
  • Unary leapfrog join: The search repeatedly advances an iterator at the smallest current key to the least upper bound of the largest key until all iterators meet or one reaches the end.Initialization sorts iterators by current key; search and seek operations locate successive intersection elements.
  • Complexity: O(Nmin log(Nmax/Nmin)) bounds unary leapfrog join, where Nmin and Nmax are the smallest and largest input cardinalities.The bound follows from advancing each iterator at most Nmin times and using the stipulated amortized iterator cost.
  • Complexity: In a three-way example, pairwise joins produce n intermediate results although the full intersection is empty, whereas leapfrog join determines emptiness in O(1) steps.This illustrates the benefit of simultaneous intersection over producing pairwise intermediate results.
  • Trie iterators: Trie iterators represent each tuple as a root-to-leaf path and expose linear child operations plus open() and up() for navigation.Relations need not be physically stored as tries; B-tree-like structures can provide the trie iterator interface.

4. COMPLEXITY ANALYSIS

The complexity analysis bounds leapfrog triejoin by the maximum query-result size, using renumbering and sum-min costs to prove worst-case optimality up to a logarithmic factor.

  • Proof strategy: O(n) iterator operations suffice at the first two trie levels for the example query.The third level is controlled by sums of min{|S_b(c)|, |T_a(c)|}.
  • Renumbering transform: Renumbering transforms relations without increasing their cardinalities and preserves enough structure to match the third-level work with query-result size.For the example, each S_b and T_a subtree is renumbered to consecutive c values, producing min{|S_b|, |T_a|} results.
  • Renumbering transform: Three renumbered results, (7, 4, 0), (7, 4, 1), and (7, 4, 2), equal the relevant sum-min quantity.This realizes one result for every leaf of the smaller relation.
  • Complexity bound: The example therefore runs in O(n3/2 log n) time, matching the n3/2 fractional edge-cover result-size bound up to a log factor.The fractional edge-cover bound limits the query result to n3/2.
  • General transform: A general renumbering replaces children at a chosen trie depth by consecutive integers, zeros later key values, and removes duplicate tuples.The resulting relation is called a renumbering of the original relation.
  • General theorem: For families closed under renumbering, leapfrog triejoin runs in O(q(n) log M(n)), where q(n) is the largest query result and M(n) the largest relation size.The theorem applies to full conjunctive queries satisfying the paper’s syntactic restrictions and a fixed variable ordering.
  • General theorem: The resulting corollary states that leapfrog triejoin is bounded by the fractional edge-cover bound up to a log factor.The broader theorem measures complexity using the maximum result size over the instance family.

5. IMPROVING ON THE NPRR BOUND

The paper extends leapfrog triejoin’s worst-case optimality to projection-cardinality families, where NPRR can be asymptotically slower.

  • Projection bounds: Leapfrog triejoin is worst-case optimal for instance families constrained by input-relation projection cardinalities.Renumbering does not increase projection cardinalities, so these families are closed under the transform required by the complexity theorem.
  • Projection bounds: For one projection-constrained family, leapfrog triejoin runs in O(n log n) time because the query result has size at most n.The bound follows from the family’s projection constraints and Theorem 5.2.
  • NPRR comparison: NPRR is not worst-case optimal for projection-cardinality families.The paper presents a family where NPRR is asymptotically slower than leapfrog triejoin.
  • NPRR comparison: Θ(n1.375) is NPRR’s best running time on the counterexample, compared with O(n log n) for leapfrog triejoin.For threshold τ ≥ n3/8, NPRR takes Θ(n1.375); for τ < n3/8, it takes Θ(n1.625), so the best choice is Θ(n1.375).
  • NPRR comparison: This counterexample demonstrates that leapfrog triejoin can be asymptotically faster than NPRR and may help explain its faster practical benchmarks.The comparison is tied to the projection-constrained family containing the constructed instance.

6. DISCUSSION AND FUTURE WORK

The paper extends leapfrog triejoin to richer Datalog constructs and examines a hash-table variant that removes the logarithmic complexity factor. It also identifies practical trade-offs and limits of the analysis for these extensions.

  • 6.1 Removing the log factor: Hash-table representations replace leapfrog joins with scans and lookups, eliminating the logarithmic factor and achieving O(q(n)) time.The variant maintains hash tables for relation slices and scans the smallest relation.
  • 6.1 Removing the log factor: The hash-table variant may lose leapfrog join’s data-distribution advantage, which can require substantially fewer iterator operations than the smallest relation size.For three relations of size n, leapfrog join can use O(1) iterator operations in one example.
  • 6.1 Removing the log factor: The logarithmic factor reflects sparse access patterns, while dense trie access can achieve O(n3/2) time without that factor.The example uses R, S, and T represented as tries over [n1/2] × [n1/2].
  • 6.1 Removing the log factor: Hash tables introduce random memory access, whereas leapfrog triejoin often provides sequential access that better matches current memory hierarchies.
  • 6.2 Extension to ∃1 queries: The LogicBlox implementation extends leapfrog triejoin to disjunctions, functions, primitives, negation, projections, ranges, and nested formulas.Disjunctions and conjunctions can be represented as nonmaterialized views, allowing arbitrary nesting in most cases without intermediate materialization or DNF conversion.
  • 6.2 Extension to ∃1 queries: Theorem 4.2 does not immediately cover these extensions; some cases can be analyzed through hypothetical materialization, but projections do not satisfy the same iterator-cost condition.Lazy materialization is suggested as a way to limit the cost to materializing evaluated subexpressions.

Conclusions

The paper presents leapfrog triejoin as a variable-oriented join algorithm that is worst-case optimal up to a logarithmic factor across broad and useful instance families. It emphasizes simplicity, implementability, and improved optimality for finer-grained families.

  • Leapfrog triejoin achieves worst-case optimality up to a log factor over large and useful families of problem instances.
  • The algorithm improves on NPRR through simpler design and optimality for finer-grained families of problem instances.
  • Leapfrog triejoin provides the core evaluation algorithms of the LogicBlox Datalog system and is straightforward to implement.
Loading 1210.0481v5…