Abstract
Efficient join processing is one of the most fundamental and well-studied tasks in database research. In this work, we examine algorithms for natural join queries over many relations and describe a novel algorithm to process these queries optimally in terms of worst-case data complexity. Our result builds on recent work by Atserias, Grohe, and Marx, who gave bounds on the size of a full conjunctive query in terms of the sizes of the individual relations in the body of the query. These bounds, however, are not constructive: they rely on Shearer's entropy inequality which is information-theoretic. Thus, the previous results leave open the question of whether there exist algorithms whose running time achieve these optimal bounds. An answer to this question may be interesting to database practice, as it is known that any algorithm based on the traditional select-project-join style plans typically employed in an RDBMS are asymptotically slower than the optimal for some queries. We construct an algorithm whose running time is worst-case optimal for all natural join queries. Our result may be of independent interest, as our algorithm also yields a constructive proof of the general fractional cover bound by Atserias, Grohe, and Marx without using Shearer's inequality. This bound implies two famous inequalities in geometry: the Loomis-Whitney inequality and the Bollobás-Thomason inequality. Hence, our results algorithmically prove these inequalities as well. Finally, we discuss how our algorithm can be used to compute a relaxed notion of joins.
Introduction
In the world of Relational Database Management Systems (RDBMS), the "join" is a fundamental operation. For decades, databases have processed joins by breaking them down into a series of binary operations—joining two tables at a time to create an intermediate result, then joining that with the next table.
However, there is a hidden trap in this approach. For certain "cyclic" queries (like finding triangles in a graph), traditional binary join plans can produce massive intermediate results that are much larger than the final output. While theoretical work by Atserias, Grohe, and Marx (the AGM bound) established tight upper bounds on how large a join result can possibly be, their proof relied on non-constructive information theory. This paper fills that gap by introducing the first constructive algorithm for natural join queries that is mathematically guaranteed to be worst-case optimal.
Methodology
The authors propose a novel recursive algorithm that departs from the standard "join-project" plans used in systems like PostgreSQL or SQL Server. The algorithm effectively makes different tactical choices on a per-tuple basis depending on the data distribution.
Key Techniques
- Heavy vs. Light Partitioning: The algorithm identifies "heavy" keys (those with high fanout that could cause an explosion in result size) and "light" keys separately. It then applies different strategies to each to ensure the total work never exceeds the theoretical worst-case bound.
- Query Plan Trees (QP-trees): Instead of a linear join order, the algorithm builds a specialized tree structure that dictates how to decompose the attributes of the query.
- Total Ordering of Attributes: The algorithm requires a specific global ordering of all attributes in the query, which allows it to build efficient search trees or hash indices that can be traversed in $O(1)$ or $O(\log N)$ time.
- Fractional Covers: The algorithm uses the concept of a "fractional edge cover" from graph theory to determine the optimal bounds, turning query optimization into a linear programming problem.
Theoretical Framework
As a theoretical computer science contribution, the evaluation is based on Data Complexity, measuring how the running time scales as the number of tuples ($N$) in the relations grows, while the query itself remains fixed.
The authors demonstrate that the "two-at-a-time" join philosophy is fundamentally incapable of reaching optimal efficiency for all queries. By constructing specific database instances designed to "break" traditional RDBMS, they show that while a standard database would take $\Omega(N^2)$ time, their optimal algorithm finishes in $O(N^{3/2})$ or even $O(N)$ time.
Interestingly, the algorithm itself serves as a constructive proof for several famous geometric inequalities, such as the Loomis-Whitney and Bollobás-Thomason inequalities, which bound the volume of a high-dimensional object based on its lower-dimensional projections. This reveals a deep link between database theory and discrete geometry: a join query is essentially trying to reconstruct a high-dimensional "object" from its "projections" (the input tables).
Key Results
- Worst-Case Optimality: The authors prove their algorithm evaluates any natural join query $q$ in time $O(U + \sum N_i)$, where $U$ is the AGM bound (the maximum possible output size for that query) and $\sum N_i$ is the input size.
- The Triangle Gap: For a triangle join $R(A,B) \bowtie S(B,C) \bowtie T(A,C)$ where each table has $N$ rows, traditional RDBMS take $O(N^2)$ time. This algorithm achieves the optimal $O(N^{3/2})$.
- Generalization: The algorithm is shown to be optimal not just for standard joins, but also for "relaxed joins" (where a tuple only needs to match a subset of the relations).
Limitations and Future Work
While the algorithm is optimal regarding the data size ($N$), the constant factors involving the query size (number of attributes and relations) can be large. For very large queries, the preprocessing of the QP-tree might become expensive. Furthermore, the algorithm requires specialized indexing and a recursive execution engine that differs significantly from the "iterator model" used in most current database engines.
Future research directions include exploring how these techniques can be integrated into existing RDBMS and how to handle more complex constraints like functional dependencies more efficiently.
Summary updated