一句话:用符号区间分析自动推导树元数据剪枝条件,并将复合查询编译融合为单次树遍历。
树结构可通过在节点上存储元数据来加速大集合上的搜索与聚合查询:当元数据上的谓词能证明某子树的数据全部无关(或全部相关)时,即可整棵剪枝或整体纳入。现有系统需要针对每种查询谓词与数据结构手工实现这套剪枝逻辑。本文提出 Bonsai,将这类优化推广并机械化:它以每个节点可用的元数据为输入,通过符号区间分析自动推导子树可被剪枝或整体包含的条件,并为此扩展了处理相交、包含等几何谓词的新规则;同时,编译器能把复合查询(如 filter 之上的 reduction)融合为一次树遍历。这些技术可自动导出广义的单索引与双索引树连接,支持远超等值与范围谓词的连接条件。生成的遍历与专家手写代码行为一致,并能在手写情形不适用时渐近优于线性扫描与嵌套循环连接。
Trees can accelerate queries that search or aggregate values over large collections. They achieve this by storing metadata that enables quick pruning (or inclusion) of subtrees when predicates on that metadata can prove that none (or all) of the data in a subtree affect the query result. Existing systems implement this pruning logic manually for each query predicate and data structure. We generalize and mechanize this class of optimization. Our method derives conditions for when subtrees can be pruned (or included wholesale), expressed in terms of the metadata available at each node. We efficiently generate these conditions using symbolic interval analysis, extended with new rules to handle geometric predicates (e.g., intersection, containment). Additionally, our compiler fuses compound queries (e.g., reductions on filters) into a single tree traversal. These techniques enable the automatic derivation of generalized single-index and dual-index tree joins that support a wide class of join predicates beyond standard equality and range predicates. The generated traversals match the behavior of expert-written code that implements query-specific traversals, and can asymptotically outperform the linear scans and nested-loop joins that existing systems fall back to when hand-written cases do not apply.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@article{RootGGFRAK26,
title = {Bonsai: Compiling Queries to Pruned Tree Traversals},
author = {Alexander J Root and Christophe Gyurgyik and Purvi Goel and Kayvon Fatahalian and Jonathan Ragan-Kelley and Andrew Adams and Fredrik Kjolstad},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {PLDI},
year = {2026},
doi = {10.1145/3808256}
}