Debunking the Myth of Join Ordering: Toward Robust SQL Analytics
Abstract Join ordering is traditionally considered the most critical and fragile component of database query optimization. A single incorrect cardinality estimate can lead to catastrophic performance degradation, turning sub-second queries into multi-hour tasks. This paper presents Robust Predicate Transfer (RPT), a novel technique that leverages Bloom filter-based pre-filtering to decouple query performance from join order. By ensuring that only tuples contributing to the final result are processed during the join phase, RPT achieves near-optimal performance across a wide range of join sequences, effectively mitigating the risks associated with traditional optimization strategies.
Introduction: The Join Order Problem In relational database systems, the sequence in which tables are joined—the join order—is a primary determinant of query execution time. Optimizers rely on cardinality estimation to predict the size of intermediate results and select the most efficient plan. However, these estimates are frequently inaccurate due to data correlations and complex predicates.
As shown in Figure 1, a typical analytical query can involve multiple tables with millions of rows. A "bad" join order in such a scenario can lead to massive intermediate data blowups, often referred to as the "diamond problem," where small inputs create massive intermediate results that eventually shrink back down. This fragility has made join ordering a "high-stakes gamble" in SQL analytics.
Robust Predicate Transfer (RPT) To address this, the authors introduce Robust Predicate Transfer (RPT). RPT is based on the Yannakakis algorithm, which provides theoretical efficiency guarantees for acyclic queries. RPT modernizes this approach by using lightweight Bloom filters for predicate transfer instead of expensive semi-joins.
The RPT process consists of two main phases:
- Semi-Join Phase: A "forward pass" and a "backward pass" distribute Bloom filters across the join graph. This pre-filtering ensures that every tuple remaining in the tables is guaranteed to participate in the final join result.
- Join Phase: The actual joins are performed on the significantly reduced tables (denoted with the superscript 'R'). Because the tables are already pruned, the specific order of joins becomes far less impactful on performance.
Algorithmic Contributions RPT introduces two key algorithms to ensure robustness and efficiency:
- LargestRoot Algorithm: This algorithm determines the schedule for passing Bloom filters. By starting the process from the largest table (typically the "fact" table in a data warehouse), it ensures that the biggest data sources are filtered first, maximizing reduction and minimizing construction time.
- SafeSubjoin Algorithm: While RPT provides ironclad guarantees for acyclic queries (which comprise 94% of the studied benchmarks), it uses the SafeSubjoin algorithm for cyclic queries. This identifies specific join sequences that are guaranteed not to explode in size, allowing the optimizer to steer clear of catastrophic plans even in complex scenarios.
Implementation and Results
The researchers integrated RPT into DuckDB, a high-performance analytical database. They implemented custom physical operators (CreateBF and ProbeBF) that utilize SIMD instructions for ultra-fast filtering. Evaluation across industry-standard benchmarks (TPC-H, TPC-DS, JOB, and DSB) demonstrated significant improvements:
- Massive Robustness Gains: In vanilla DuckDB, the gap between the best and worst random join orders (the Robustness Factor) was often 30x to 120x. With RPT, this gap dropped to just 1.1x to 1.3x on average.
- End-to-End Speedup: Beyond safety, RPT is faster. It improved overall query performance by an average of 1.5x compared to DuckDB’s default optimized plan.
- SIMD Efficiency: The custom Bloom filter implementation outperformed standard hash table probes by 2x to 7x.
Conclusion By making query performance nearly independent of join order for the majority of analytical queries, RPT challenges the long-standing focus on join ordering in database research. It offers a path toward simpler, more predictable, and more robust query optimizers that can handle real-world data complexities without the risk of catastrophic failure. Future work includes extending these guarantees to fully cyclic queries using hybrid approaches like Worst-Case Optimal Joins (WCOJ).
Summary updated