The query optimizer in a Database Management Systems (DBMS), translates declarative queries into efficient execution plans. Conventional bottom-up optimization consists of two main stages: Query Rewrite (QRW) and Cost-Based Optimization (CBO). However, applying a rewrite rule during QRW may not always be beneficial; the best choice may depend on the (estimated) execution cost of the original and rewritten expressions. Fully exploiting such cost-dependent rules necessitates interleaving QRW with frequent CBO invocations, thereby incurring substantial overhead and often impractical optimization times. To mitigate this inefficiency, we introduce a novel cost-based rewrite framework for bottom-up optimizers. The core of our approach is a multi-level caching mechanism for intermediate CBO results aimed at eliminating redundant computation. Furthermore, we establish and exploit upper cost bounds to intelligently prune the search space during optimization. We also contribute methodological solutions for caching and reusing intermediate plan results within a bottom-up optimizer architecture. The framework has been implemented in the GaussDB optimizer. Experiments show that it significantly reduces overall optimization time, demonstrating the effectiveness of our approach.
翻译:数据库管理系统(DBMS)中的查询优化器将声明式查询转换为高效的执行计划。传统的底向上优化包含两个主要阶段:查询重写(QRW)和基于成本的优化(CBO)。然而,在QRW阶段应用重写规则并非总是有益的;最佳选择可能取决于原始表达式和重写表达式的(估计)执行成本。充分利用此类依赖成本的规则需要将QRW与频繁的CBO调用交错进行,从而产生大量开销,并时常导致优化时间不可接受。为缓解这一低效问题,我们为底向上优化器引入了一种新型的基于成本的重写框架。我们方法的核心是一种针对中间CBO结果的多级缓存机制,旨在消除冗余计算。此外,我们建立并利用成本上界来智能地剪枝优化过程中的搜索空间。我们还贡献了关于在底向上优化器架构中缓存和重用中间计划结果的方法论解决方案。该框架已在GaussDB优化器中实现。实验表明,它显著减少了整体优化时间,证明了我们方法的有效性。