Large language model (LLM) has marked a pivotal moment in the field of machine learning and deep learning. Recently its capability for query planning has been investigated, including both single-modal and multi-modal queries. However, there is no work on the query optimization capability of LLM. As a critical (or could even be the most important) step that significantly impacts the execution performance of the query plan, such analysis and attempts should not be missed. From another aspect, existing query optimizers are usually rule-based or rule-based + cost-based, i.e., they are dependent on manually created rules to complete the query plan rewrite/transformation. Given the fact that modern optimizers include hundreds to thousands of rules, designing a multi-modal query optimizer following a similar way is significantly time-consuming since we will have to enumerate as many multi-modal optimization rules as possible, which has not been well addressed today. In this paper, we investigate the query optimization ability of LLM and use LLM to design LaPuda, a novel LLM and Policy based multi-modal query optimizer. Instead of enumerating specific and detailed rules, LaPuda only needs a few abstract policies to guide LLM in the optimization, by which much time and human effort are saved. Furthermore, to prevent LLM from making mistakes or negative optimization, we borrow the idea of gradient descent and propose a guided cost descent (GCD) algorithm to perform the optimization, such that the optimization can be kept in the correct direction. In our evaluation, our methods consistently outperform the baselines in most cases. For example, the optimized plans generated by our methods result in 1~3x higher execution speed than those by the baselines.
翻译:大语言模型(LLM)在机器学习和深度学习领域标志着关键转折点。近期,其查询规划能力(涵盖单模态与多模态查询)已得到初步探索,然而目前尚无研究涉及其查询优化能力。作为显著影响查询计划执行性能的关键步骤(甚至可称为最重要环节),此类分析与尝试不容缺失。另一方面,现有查询优化器通常基于规则或规则+成本驱动,即依赖人工创建规则实现查询计划重写/变换。鉴于现代优化器包含数百至数千条规则,若沿用相似思路设计多模态查询优化器,需逐一列举大量多模态优化规则,这将耗费大量时间且迄今未获妥善解决。本文探究了LLM的查询优化能力,并利用LLM设计出LaPuda——一种基于LLM与策略的新型多模态查询优化器。不同于枚举具体细则,LaPuda仅需少量抽象策略引导LLM完成优化,大幅节省时间与人力成本。此外,为防止LLM产生错误或负向优化,我们借鉴梯度下降思想提出导向成本下降(GCD)算法来引导优化过程,确保优化方向正确性。实验评估表明,本方法在多数场景下显著优于基线方案。例如,本方法生成的优化计划执行速度较基线方案提升1~3倍。