[Paper Review] Sampling-Based Query Re-Optimization
This paper proposes a lightweight, sampling-based iterative re-optimization technique that improves query plan quality by detecting and correcting cardinality estimation errors made by traditional query optimizers. By using sampling to refine cardinality estimates post-optimization and re-running the optimizer, the method achieves significant performance improvements on 'difficult' queries with minimal overhead, converging in just a few iterations on average.
Despite of decades of work, query optimizers still make mistakes on "difficult" queries because of bad cardinality estimates, often due to the interaction of multiple predicates and correlations in the data. In this paper, we propose a low-cost post-processing step that can take a plan produced by the optimizer, detect when it is likely to have made such a mistake, and take steps to fix it. Specifically, our solution is a sampling-based iterative procedure that requires almost no changes to the original query optimizer or query evaluation mechanism of the system. We show that this indeed imposes low overhead and catches cases where three widely used optimizers (PostgreSQL and two commercial systems) make large errors.
Motivation & Objective
- To address persistent cardinality estimation errors in query optimizers caused by data correlations and multiple predicate interactions.
- To reduce the risk of selecting suboptimal query plans due to inaccurate selectivity estimates from histogram-based methods.
- To provide a low-cost, post-optimization mechanism that enhances plan quality without modifying the core optimizer or execution engine.
- To evaluate the effectiveness of sampling-based re-optimization on real-world 'difficult' queries where traditional optimizers fail.
- To demonstrate that iterative re-optimization using sampled statistics can converge quickly and significantly improve query performance.
Proposed method
- Proposes a post-processing loop that validates the final query plan using sampling-based cardinality estimates.
- If significant cardinality estimation errors are detected, the optimizer is re-invoked with refined sampling-based estimates to generate a new plan.
- The process iterates until the optimizer returns the same plan across consecutive rounds, indicating convergence.
- The method leverages sampling to capture data correlations and joint selectivities that histograms miss.
- Theoretical analysis bounds the expected number of iterations at O(√N), where N is the optimizer’s search space size.
- The approach is designed to be lightweight and compatible with existing systems, requiring minimal changes to the optimizer or execution engine.
Experimental results
Research questions
- RQ1Can sampling-based cardinality estimates detect and correct significant errors in query optimizer plans?
- RQ2How efficient is the iterative re-optimization process in terms of convergence speed and computational overhead?
- RQ3Does re-optimization with sampling lead to better query execution plans on 'difficult' queries with data correlations?
- RQ4How does the performance of this method compare to traditional histogram-based optimization on real-world benchmarks?
- RQ5Can this approach reduce the need for more expensive runtime re-optimization techniques?
Key findings
- The iterative re-optimization procedure converges in just a few rounds for most queries, with negligible performance overhead compared to query execution time.
- The method successfully detects and corrects large cardinality estimation errors in three widely used optimizers: PostgreSQL and two commercial systems.
- Significant performance improvements were observed on specific TPC-H queries, though most TPC-H queries did not change plans, indicating effectiveness on corner cases.
- Theoretical analysis shows expected convergence in O(√N) iterations, though practical convergence is much faster.
- The approach is complementary to runtime re-optimization, reducing the likelihood of needing more expensive dynamic re-planning.
- The method effectively handles data correlations that traditional histogram-based estimators fail to capture, especially in multi-predicate queries.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.