可扩展且可验证的查询重写规则语言
An Extensible and Verifiable Language for Query Rewrite Rules
AI总结:
Rulescript 提供一种通用查询重写规则开发语言,通过分离规则定义与执行基础设施,实现规则的自动验证和跨引擎移植,减少重写规则开发的工程成本和错误风险。
摘要:
逻辑查询计划重写将关系数据库查询转换为等效但更高效的表达形式,对数据库应用性能至关重要。现有系统中,重写规则通常手动实现,紧密耦合特定执行引擎,且缺乏形式正确性保证。因此,开发新引擎需重新实现遗留和新规则,导致显著工程成本,限制了可移植性,并且每次新实现都可能引入新错误。我们引入 Rulescript,一种引擎无关的领域特定语言(DSL),通过关系代数启发的核心语言和显式分解规则为匹配和转换阶段,使开发者通过 Rulescript 的核心运算符对查询计划进行模式匹配,并构造语义等价的转换计划,所有重写均自动形式验证以确保正确性。Rulescript 是可扩展的:用户可以以核心语言定义自定义运算符以捕获引擎特定的语义。要与现有系统集成,开发者只需实现一个轻量级适配器,将 Rulescript 的核心和自定义运算符映射到目标引擎实现的运算符。我们通过重新实现 33 个 Apache Calcite 重写规则并扩展语言添加几个自定义运算符来评估 Rulescript。为演示可移植性,我们自动将这些规则部署到 CockroachDB 和 Apache Data Fusion,两个具有显著不同后端的引擎。我们的结果表明,Rulescript 实现了查询计划重写的“一次编写,到处部署”范式,将部署先前编写规则到新数据引擎所需的努力降至最低。
英文摘要:
Logical query plan rewriting transforms a relational database query into an equivalent but more efficient form and is crucial to the performance of database-backed applications. In existing systems, rewrite rules are typically implemented manually, tightly coupled to specific execution engines, and often lack formal correctness guarantees. Consequently, developing a new engine requires reimplementing both legacy and new rules, incurring significant engineering cost, limiting portability, and every new implementation is an opportunity for introducing new bugs. We introduce Rulescript, an engine-agnostic domain-specific language (DSL) for developing query rewrite rules. Rulescript separates rule definition from execution infrastructure via a relational algebra-inspired core language and an explicit decomposition of rules into matching and transformation phases. Developers express rewrites by pattern-matching query plans using Rulescript's core operators and constructing semantically equivalent transformed plans, with all rewrites automatically verified formally to ensure correctness. Rulescript is extensible: users can define custom operators in terms of the core language to capture engine-specific semantics. To integrate with an existing system, developers need only implement a lightweight adapter that maps Rulescript's core and custom operators to the operators implemented in the target engine. We evaluate Rulescript by reimplementing 33 rewrite rules from Apache Calcite and extending the language with several custom operators. To demonstrate portability, we automatically deploy these rules to CockroachDB and Apache Data Fusion, two engines with substantially different backends. Our results show that Rulescript enables "write once, deploy everywhere" paradigm for query plan rewriting, with minimal effort required to deploy previously written rules on a new data engine.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。