arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2606.20853cs.DB
收藏

ReSequel: 基于模板化和采样的鲁棒性LLM辅助查询重写与优化

ReSequel: Robust LLM-assisted Query Rewriting and Optimization using Templatization and Sampling

Concordia University(康考迪亚大学);TU Berlin(柏林工业大学);BIFOLD(柏林数据与人工智能联合实验室)

Saeed Fathollahzadeh, Essam Mansour, Matthias Boehm

AI总结:

提出ReSequel,一种利用LLM和元数据(目录、统计信息)通过模板化规则和采样验证来重写SQL查询的优化层,在多个DBMS上实现高达16倍的工作负载加速。

摘要:

启发式查询重写长期以来一直补充基于代价的优化以提高性能。这些重写将SQL查询转换为语义等价但更易或更快执行的形态。例如标准化表达式、消除冗余、传播常量、下推选择和投影、解嵌套查询以及利用约束。现代DBMS实现了数百到数千条这样的规则,但维护它们非常困难。规则之间的交互复杂,且其静态性质和固定的应用顺序阻止了针对特定查询和数据库特征的适应性。最近使用大型语言模型(LLM)进行查询重写的方法显示出前景,但面临搜索空间大、查询验证可靠性和元数据利用等挑战。我们提出ReSequel,一个位于现有DBMS之上的外部优化层,利用LLM重写SQL查询。ReSequel利用目录和统计元数据推断模板特定规则,引导LLM进行有效的查询转换。我们在采样数据上生成、验证和排名重写的查询变体,以确保结果正确性和运行时改进。我们的实验涵盖八个基准:JOB、TPC-H、Stats(-CEB)、Public BI、IMDB、DSB和StackOverflow;多个DBMS:PostgreSQL、MySQL和DuckDB;以及基于LLM的查询重写基线。ReSequel在八个基准和三个DBMS上,相对于原生DBMS实现了高达16倍的工作负载加速,相对于基于LLM的系统实现了22倍加速,单个查询加速超过600倍。

英文摘要:

Heuristic query rewriting has long complemented cost-based optimization to improve performance. Such rewrites transform SQL queries into semantically equivalent forms that are easier or faster to execute. Examples are standardizing expressions, eliminating redundancy, propagating constants, pushing down selections and projections, unnesting queries, and utilizing constraints. Modern DBMSs implement hundreds to thousands of such rules, but maintaining them is notoriously difficult. The interactions among rules are complex, and their static nature and application order prevent adaptation to specific query and database characteristics. Recent approaches that use large language models (LLMs) for query rewriting show promise but face challenges regarding the large search space, reliable query verification, and exploitation of metadata. We present ReSequel, an outer optimization layer on top of existing DBMSs to rewrite SQL queries using LLMs. ReSequel leverages catalog and statistical metadata to infer template-specific rules that guide the LLM toward effective query transformations. We generate, verify, and rank rewritten query variants on sampled data to ensure result correctness and runtime improvements. Our experiments cover eight benchmarks: JOB, TPC-H, Stats(-CEB), Public BI, IMDB, DSB, and StackOverflow; multiple DBMSs: PostgreSQL, MySQL, and DuckDB; as well as LLM-based query rewriting baselines. ReSequel yields workload-level speedups of up to 16x over native DBMSs and 22x over LLM-based systems, with individual queries exceeding 600x, across eight benchmarks and three DBMSs.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑