Yannakakis+: Practical Acyclic Query Evaluation with Theoretical Guarantees

Qichen Wang, Bingnan Chen, Binyang Dai, Ke Yi, Feifei Li, Liang Lin

TL;DR

Researchers have finally modernized the 40-year-old Yannakakis algorithm, creating Yannakakis+. This new approach bridges the gap between beautiful theoretical guarantees and messy real-world performance, delivering an average 2.41x speedup (and up to 47,000x) across major SQL engines like DuckDB and PostgreSQL.

What Problem Does This Paper Address?

In the world of database theory, the Yannakakis algorithm (1981) is a legend. It provides a "worst-case optimal" way to evaluate acyclic conjunctive queries—the bread and butter of analytical workloads. Theoretically, it ensures that queries run in time proportional to the input plus the output ($O(N+M)$), preventing the "intermediate result explosion" that plagues standard join plans.

However, in the world of database practice, almost no one uses it. Why? Because the algorithm has a high "hidden constant factor." In "nice" datasets (where joins follow simple primary-key/foreign-key relationships), standard SQL engines are actually faster. The original Yannakakis algorithm is too rigid: it insists on performing two full passes of semi-joins to remove "dangling tuples" (data that won't appear in the final result) before doing any actual joining. This overhead often outweighs the benefits unless the data is extremely "noisy" or involves complex many-to-many joins.

Methods

The authors introduce Yannakakis+, which retains the theoretical safety of the original but adds "practical muscles." The core innovations include:

  1. Early Aggregation & Join Pushdown: Unlike the original, which waits until the very end to aggregate data, Yannakakis+ pushes aggregations and joins as early as possible. This drastically reduces the size of data being passed between steps.
  2. Reduced Semi-Joins: The algorithm identifies "relation-dominated" queries where semi-joins can be skipped entirely without losing theoretical guarantees.
  3. A Two-Round Framework:
    • Round 1: A post-order traversal that performs early joins and aggregations.
  4. Round 2: A reduction phase that iteratively merges "dangling-free" and "reducible" relations.
  5. Pure Relational Implementation: Crucially, Yannakakis+ generates a standard Directed Acyclic Graph (DAG) of relational operators. This means it can be implemented as a "plug-in" rewriter on top of existing engines like DuckDB, PostgreSQL, and SparkSQL without modifying their kernels.
  6. Tailored Cost-Based Optimizer: Since there are many ways to build a join tree, the authors built an optimizer that uses cardinality estimation to pick the most efficient plan within the Yannakakis+ family.

Datasets

The authors evaluated their system using five diverse benchmarks:

  • SGPB (Sub-Graph Pattern Benchmark): Complex graph queries on SNAP datasets (bitcoin, epinions, dblp, etc.).
  • LSQB: A social network benchmark with numerous joins.
  • TPC-H: The industry standard for decision support systems.
  • JOB (Join Order Benchmark): Real-world-inspired queries on the IMDB dataset.
  • CEB (Cardinality Estimation Benchmark): Millions of queries designed to test optimizer accuracy.

Key Insights and Ideas

  • The "Dangling Tuple" Risk is Real: Standard engines like DuckDB can be 50x slower when primary key constraints are removed, because they get bogged down by intermediate results. Yannakakis+ provides a safety net against this.
  • Theory vs. Practice is a False Choice: By relaxing the strict "semi-join first" rule of the original algorithm, you can achieve the same $O(N+M)$ complexity while matching or beating the speed of highly optimized commercial engines.
  • Aggregations are the Secret Sauce: In analytical queries, the final output ($M$) is often much smaller than the input ($N$). Pushing aggregations down isn't just a "nice to have"—it's what makes the algorithm competitive on modern hardware.

Key Results

The experimental results are striking:

  • Universal Improvement: Yannakakis+ outperformed native query plans in 160 out of 162 tested queries.
  • Massive Speedups: While the average speedup was 2.41x, the maximum speedup reached a staggering 47,059x on specific complex graph queries where standard optimizers failed.
  • Efficiency over Original: Yannakakis+ is consistently 2x to 5x faster than the original 1981 Yannakakis algorithm.
  • Robustness: The performance gains held steady across different SQL engines (DuckDB, PostgreSQL, SparkSQL, and Alibaba's AnalyticDB), proving the "plug-in" approach works.

Limitations and Future Work

  • Optimization Overhead: While the planner usually takes less than 100ms, very complex queries with hundreds of relations might see a bottleneck in the plan enumeration phase (running GYO/GHD algorithms).
  • Kernel Integration: The current version is an external rewriter. The authors note that deeper integration into a database kernel (using things like Bloom filters instead of "soft" semi-joins) could unlock even more performance.
  • Beyond Acyclic: While the paper touches on using Generalized Hypertree Decompositions (GHD) for cyclic queries, the primary focus remains on the acyclic case. Extending these practical optimizations to highly cyclic queries is a natural next step.

Summary updated

BibTeX
@inproceedings{wang2025yannakakis,
  author = {Qichen Wang and Bingnan Chen and Binyang Dai and Ke Yi and Feifei Li and Liang Lin},
  title = {{Yannakakis+: Practical Acyclic Query Evaluation with Theoretical Guarantees}},
  booktitle = {Proc. ACM Manag. Data},
  year = {2025},
  url = {https://openreview.net/forum?id=DpsBZA3hW8},
}
Figure