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

通过 LLM 进行查询重写

Query Rewriting via LLMs

Sriram Dharwada, Himanshu Devrani, Jayant Haritsa, Harish Doraiswamy

AI总结:

本文提出 LITHE 系统,结合提示词集成、数据库敏感规则与 token 概率引导重写,并用逻辑和统计工具校验语义,显著提升复杂 SQL 查询性能。

摘要:

当复杂 SQL 查询即使经过查询优化仍执行缓慢时,DBA 通常会调用自动化查询重写工具,以推荐有助于更快执行的“精简”等价语句。这类重写通常通过转换规则实现,但这些规则适用范围有限,且难以在生产系统中更新。近来,也有人提出基于 LLM 的技术,但它们容易出现语义和语法错误。我们在此研究如何利用 LLM 卓越的认知能力实现高性能查询重写,同时纳入保障与优化措施以确保正确性和效率。研究表明,这些目标可以通过逐步融合以下机制实现:(a) 一组基础提示词集成套件;(b) 通过冗余消除和基于选择度的重写规则生成的数据库敏感提示词;以及 (c) LLM token 概率引导的重写路径。此外,在提交 DBA 考虑之前,可使用一套基于逻辑和统计的工具检查重写中的语义违背。我们已在 LITHE 系统中实现上述融合 LLM 的技术,并在当代数据库平台上评估来自标准基准的复杂分析查询。结果显示,慢查询性能相对 SOTA 重写器和原生优化器均有显著提升。例如,在 PostgreSQL 上运行 TPC-DS 时,相对原生优化器的运行时加速比几何均值高达 13.2,而 SOTA 仅达到 4.9。总体而言,LITHE 是迈向可行的、基于 LLM 的咨询工具以改善企业查询性能的有希望一步。

英文摘要:

When complex SQL queries suffer slow executions despite query optimization, DBAs typically invoke automated query rewriting tools to recommend ``lean'' equivalents that are conducive to faster execution. The rewritings are usually achieved via transformation rules, but these rules are limited in scope and difficult to update in a production system. Recently, LLM-based techniques have also been suggested, but they are prone to semantic and syntactic errors. We investigate here how the remarkable cognitive capabilities of LLMs can be leveraged for performant query rewriting while incorporating safeguards and optimizations to ensure correctness and efficiency. Our study shows that these goals can be progressively achieved through incorporation of (a) an ensemble suite of basic prompts, (b) database-sensitive prompts via redundancy removal and selectivity-based rewriting rules, and (c) LLM token probability-guided rewrite paths. Further, a suite of logic-based and statistical tools can be used to check for semantic violations in the rewrites prior to DBA consideration. We have implemented the above LLM-infused techniques in the LITHE system, and evaluated complex analytic queries from standard benchmarks on contemporary database platforms. The results show significant performance improvements for slow queries, over both SOTA rewriters and the native optimizer. For instance, with TPC-DS on PostgreSQL, the GM of runtime speedups was a high 13.2 over the native optimizer, whereas SOTA only gave 4.9. Overall, LITHE is a promising step toward viable LLM-based advisory tools for ameliorating enterprise query performance.

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

↑