Structure-Guided Query Evaluation: Towards Bridging the Gap from Theory to Practice

Georg Gottlob, Matthias Lanzinger, Davide Mario Longo, Cem Okulmus, Reinhard Pichler, Alexander SelzerarXiv 2023 · DOI

Abstract

Modern database management systems (DBMSs) often struggle with complex join queries involving many relations, frequently encountering "intermediate result explosion" that leads to system timeouts. This paper introduces YanRe, a system that bridges the gap between database theory and practice by implementing structure-guided evaluation. By rewriting SQL queries into sequences of semi-joins based on Yannakakis’ algorithm, YanRe significantly improves performance on challenging join workloads. Empirical evaluations on PostgreSQL, DuckDB, and Spark SQL demonstrate substantial reductions in timeouts and execution times, particularly for queries that can be answered without full materialization.

Introduction

While modern DBMSs are highly optimized for standard workloads, they possess a significant "blind spot" for queries involving numerous relations (e.g., 10–30 tables). The traditional approach of decomposing large joins into sequences of two-way joins often generates massive intermediate tables that are ultimately discarded, consuming excessive memory and time. This paper addresses this "computational nightmare" by applying decades-old theoretical insights—specifically Yannakakis’ algorithm—to mainstream database systems.

The YanRe Approach

The authors present YanRe, a proof-of-concept system that performs structure-guided evaluation as an external wrapper for existing databases. YanRe operates through three primary steps:

  1. Structural Analysis: Representing the SQL query as a hypergraph and identifying a "join tree" using the GYO-algorithm.
  2. SQL Rewriting: Translating the query into a sequence of SQL statements that perform a "bottom-up" pass of semi-joins to prune dangling tuples before the final join.
  3. Zero-Materialization Answerable (0MA) Queries: Identifying a class of queries—often involving aggregates like MIN or MAX—where the final join can be skipped entirely. If a query is "guarded" by a specific table, the answer can be derived using only semi-joins, resulting in near-instant execution.

Experimental Evaluation

The study utilized the MusicBrainz dataset and a benchmark of 435 challenging synthetic join queries. These queries ranged from 1 to 29 joins across up to 30 tables, specifically designed to stress-test join optimizers beyond the simple queries found in standard benchmarks like TPC-H.

Key Results

The structure-guided approach yielded striking improvements across all tested systems. As shown in the performance distribution, YanRe significantly reduced the number of timeouts and shifted query execution times toward faster buckets.

Distribution of query execution times (in seconds) across different DBMS configurations. The 'TO' bar represents timeouts.

In PostgreSQL, timeouts for 0MA aggregation queries dropped from 91 to just 2, while DuckDB saw timeouts for the same queries eliminated entirely. Even for full enumeration queries, the reduction in timeouts was substantial. For instance, on a complex query (08ad), DuckDB's execution time was reduced from 151.9 seconds to 42.1 seconds, with the pruning phase requiring only 2.4 seconds.

Aggregate performance statistics comparing baseline DBMS performance with YanRe-enhanced evaluation.

As summarized in the aggregate statistics, YanRe consistently reduced mean execution times and timeouts. For example, in Spark SQL, the number of timeouts was slashed from 87 to 29. Beyond aggregate statistics, the system significantly reduced "shuffle" operations and peak memory consumption in distributed environments like Spark SQL, making complex joins much more stable.

Conclusion

This work demonstrates that theoretical algorithms can be effectively integrated into modern database workflows without modifying the engine's kernel. While YanRe introduces overhead for simple queries, it provides a powerful solution for the "hard cases" that currently paralyze mainstream DBMSs. Future work includes refining the handling of cyclic queries and pursuing deeper, native integration into DBMS kernels to minimize the overhead of SQL rewriting.

Summary updated

BibTeX
@misc{gottlob2023structure,
  author = {Georg Gottlob and Matthias Lanzinger and Davide Mario Longo and Cem Okulmus and Reinhard Pichler and Alexander Selzer},
  title = {{Structure-Guided Query Evaluation: Towards Bridging the Gap from Theory to Practice}},
  year = {2023},
  eprint = {2303.02723},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.02723},
}
Figure