TL;DR
This paper tackles the challenge of optimizing database queries by explicitly considering the impact of bitvector filters, a common technique for pruning data. They demonstrate that ignoring these filters can lead to significantly suboptimal query plans and propose a novel algorithm that dramatically reduces the search space for optimal plans, resulting in substantial performance improvements.
What Problem Does This Paper Address?
Database systems frequently use "bitvector filters" (like Bloom filters) to quickly discard rows that won't satisfy join conditions. This is crucial for speeding up complex decision support queries, which often involve many joins. However, traditional query optimizers, which are responsible for finding the most efficient way to execute a query, often treat these filters as an afterthought. They generate a query plan first and then apply bitvector filters, or they might use heuristics that don't fully account for how these filters change the cost of different join orders. This can lead to a situation where the "best" plan found by the optimizer is actually far from optimal once bitvector filters are considered. The paper highlights that naively incorporating bitvector filters into existing optimization frameworks can lead to an exponential explosion in the number of plans to consider, making optimization intractable.
Methods
The core of this work lies in analyzing how bitvector filters, when assumed to have no false positives, simplify the query optimization problem for specific query structures.
- Theoretical Analysis: The authors focus on "right deep trees" (a common plan structure for decision support queries) and analyze star and snowflake schemas with primary-key-foreign-key (PKFK) joins. They prove that, under certain assumptions, the optimal join order can be found by considering only a linear number of candidate plans, a significant reduction from the previously exponential complexity. This is achieved by leveraging properties of bitvector filters and demonstrating that many different join orders become equivalent in cost.
- Algorithm Development: Based on this analysis, they propose a bitvector-aware query optimization algorithm. This algorithm prioritizes branches in snowflake queries and uses heuristics to construct a join order that accounts for the impact of bitvector filters. They also extend this to handle more general queries with multiple fact tables and arbitrary join graphs.
- Cost-Based Filter Selection: Recognizing that bitvector filters themselves have an overhead, they introduce a cost-based approach to selectively apply filters, estimating the benefit versus the cost.
- Implementation: The proposed algorithm was implemented in Microsoft SQL Server as a transformation rule within its existing Volcano/Cascades-style optimizer.
Datasets
The evaluation used standard industry benchmarks:
- TPC-DS (100GB): A widely used benchmark for decision support systems.
- JOB (7GB): Another benchmark for decision support queries.
- CUSTOMER workload: A customer-specific workload.
These datasets cover various configurations, including B+ trees and columnstores, and represent complex join graphs and high average joins per query.
Key Insights and Ideas
- Bitvector filters simplify optimization: Counter-intuitively, bitvector filters (especially those without false positives) can reduce the complexity of finding optimal join orders for certain query patterns, transforming an exponential search space into a linear one.
- Ignoring filters is costly: Failing to account for bitvector filters during query optimization can lead to selecting plans that are significantly worse than those that do.
- Right-deep trees benefit greatly: The proposed technique is particularly effective for queries where right-deep trees are already a preferred plan structure (e.g., low-selectivity queries), as it finds better join orders within that space.
- Heuristics can be powerful: By analyzing the structure of snowflake queries and the behavior of bitvector filters, the authors developed effective heuristics for prioritizing and ordering branches to construct optimal plans.
Key Results
- Reduced Plan Space: For star and snowflake queries with PKFK joins, the optimal plan can be found from a linear number of candidate plans, down from an exponential number.
- Performance Improvements:
- Workload-level CPU execution time reduction of 22%-64% compared to the original Microsoft SQL Server.
- Up to two orders of magnitude reduction in CPU execution time for individual queries.
- For the JOB benchmark, the technique achieved a 64% reduction in CPU execution time.
- The number of tuples processed by join operators was reduced by 52% for the JOB benchmark.
- Low Optimization Overhead: The query optimization time with their technique was, on average, one-third of the original Microsoft SQL Server.
- Wide Applicability: Bitvector filters are used in a very high percentage of queries (97%-100%) in the tested benchmarks, confirming the broad impact of this optimization approach.
Limitations and Future Work
- Assumptions: The theoretical analysis relies on the assumption of bitvector filters having no false positives. While they discuss how to handle false positives in practice (e.g., cost-based selection), the core theoretical simplification depends on this.
- Cost Function: The paper uses an intermediate result size-based cost function (
Cout), which is a good approximation but doesn't capture all physical execution details. - Plan Space: The analysis primarily focuses on right-deep trees without cross products.
- Future Work: The authors suggest extending the analysis to other plan spaces, query patterns, operators beyond hash joins, and more complex cost modeling. They also highlight the challenge of achieving "full integration" of bitvector filter awareness into commercial database optimizers.
Summary updated