Skip to content

perf(query): use Stile for per-candidate filtering on sealed IPC segments - #925

Open
luoxiaojian wants to merge 11 commits into
alibaba:mainfrom
luoxiaojian:codex/stile-interpreter-main
Open

luoxiaojian wants to merge 11 commits into
alibaba:mainfrom
luoxiaojian:codex/stile-interpreter-main

Conversation

@luoxiaojian

@luoxiaojian luoxiaojian commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

改动

本 PR 优化向量和全文召回中的逐候选正排过滤。当规划器把一个 segment 的过滤条件从全部倒排转为全部正排时,召回过程会逐个检查候选行。对于能提供 ForwardReadView 的已封存 IPC segment,DocFilter 将绑定后的 Arrow 布尔表达式编译成 Stile 的只读求值树。Stile 按候选行号直接读取 Arrow 列缓冲区,省去逐行构造 Scalar、ExecBatch 和调用 ExecuteScalarExpression 的开销。

  • 按列快照复用 chunk 索引。 每个 ForwardColumn 首次用于 Stile 时构建一份 ColumnIndex。后续查询共享索引元数据,命中时无需获取构建锁。列值复用原有缓冲区,谓词仍按查询编译。DDL 换列后,已准备的查询继续持有原索引。
  • 保留 Arrow 的过滤语义。 Stile 支持常见比较、布尔组合、空值判断、集合匹配和部分 LIKE,保留 TRUE、FALSE、NULL 三值逻辑。遇到不支持的子表达式或超过编译预算时,整条谓词回退到 Arrow。绑定和数据校验错误继续上报。

性能

测试使用 1,000 万行只读 sealed IPC 数据,62 维 COSINE HNSW、INT8 量化,ef=300、topk=21。过滤条件 dataTime > 536870911 命中 7,497,998 行(74.98%)。吞吐按 Python Collection.query 的端到端 QPS 计算,返回字段包含 pid、mail 和 dataTime。

相同逐候选计划下的吞吐

规划器按 segment 的估计命中比例决定是否把这个范围谓词从倒排转为正排。实验保留 dataTime 的范围倒排索引,设置 enable_range_optimization=True、invert_to_forward_scan_ratio=0,使三个版本均走逐候选过滤。每个平台在同一张 HNSW 图上交替运行三个提交,表中为四轮 QPS 中位数。

平台 并发客户端 Arrow 基线(ea1519a0) Stile 每查询构建列索引(c21b4f93) Stile 共享列索引(3947ce89) 当前 / 基线
Linux x86_64 1 153.79 344.76 415.40 2.70×
Linux x86_64 8 674.92 1,831.72 2,233.54 3.31×
macOS arm64 1 545.36 1,507.12 1,804.49 3.31×
macOS arm64 8 951.73 7,604.17 9,103.11 9.56×

在 Stile 已经直接读取列缓冲区的基础上,跨查询复用列索引又使 Linux 的 1、8 客户端 QPS 分别提高 20.5% 和 21.9%,macOS 两种并发度均提高 19.7%。

与 Gandiva JIT 的逐候选过滤对比

在共同基线 a26f8abe 上,对比 Stile(7789d910)与从 #913 移植的 Gandiva JIT(c5774890)。两版在每个平台共用同一张 HNSW 图,所有谓词均包含 dataTime > 536870911。表中为预热后的端到端 QPS 中位数(Linux 4 轮、macOS 6 轮),JIT 已在计时前完成编译。增幅按两版中位数之比计算。JIT 对照实现 #913

平台 谓词 1 客户端 QPS(JIT → Stile) 8 客户端 QPS(JIT → Stile)
Linux x86_64 单比较 385.99 → 413.95(+7.25%) 2,055.52 → 2,216.75(+7.84%)
macOS arm64 单比较 1,604.15 → 1,742.10(+8.60%) 7,862.77 → 8,621.98(+9.66%)
Linux x86_64 另加 pid >= 3333333(双列) 247.23 → 258.51(+4.56%) 1,517.98 → 1,552.78(+2.29%)
macOS arm64 另加 dataTime < 1610612736(同列) 1,078.88 → 1,228.69(+13.89%) 5,593.64 → 6,400.36(+14.42%)

单比较在两端的每一轮均是 Stile 更快。Linux 双列 AND 在 8 客户端时差距最小,四轮中有一轮 Stile 略低于 JIT。每条谓词的 1,024 个查询均在本机得到一致的有序 Top‑21。

首次单比较查询的耗时中位数(JIT → Stile)在 Linux 为 114.34 → 59.77 ms(打开集合后直接查询),在 macOS 为 17.85 → 1.06 ms(先用无过滤查询预热 HNSW)。两端测得的 JIT 编译耗时分别约为 53 ms 和 16 ms。

表中增幅适用于双方原生支持的数值谓词。多段 LIKE 在逐候选执行时可能使 #925 回退 Arrow。

同一谓词的两条 bitset 对照路径

这两条路径都在召回前生成 bitset。第一行保留原复现脚本的切换阈值 0.9,第二行使用移除了 dataTime 索引的同图副本。下表为 macOS 上 ea1519a0 → c21b4f93 的四轮 QPS 中位数。

过滤路径 dataTime 范围倒排索引 invert_to_forward_scan_ratio 1 客户端 QPS 8 客户端 QPS
倒排索引构建 Roaring bitset 有 0.9 386.02 → 384.53 1,698.47 → 1,723.59
正排整段扫描构建 bitset(Acero) 无 0 71.11 → 70.60 162.86 → 162.11

复杂数值谓词下的过滤性能

沿用共同基线 a26f8abe 和 10M × 62 维 HNSW 数据,用 AND / OR 组合 dataTime 和 pid 的 4、10、22 个范围比较,三组命中率均约 50%。

在 Linux 和 macOS 的单客户端、8 客户端测试中,Stile 的端到端 QPS 中位数至少是三条对照路径中最快者的 11 倍(倒排 bitset、正排 Acero bitset、旧 Arrow 逐候选)。Stile 与热态 Gandiva JIT 的吞吐接近,相对 JIT 的差异在单客户端下为 −8.5% 至 +8.9%,在 8 客户端下为 +4.3% 至 +12.6%。

下表为 22 个范围比较时的 QPS 中位数,每格依次为 1 客户端 / 8 客户端(Linux 4 轮,macOS 5 轮)。JIT 在计时前完成编译。

平台 倒排 bitset 正排 bitset(Acero) 旧 Arrow 逐候选 Stile 逐候选 JIT 逐候选
Linux x86_64 4.15 / 30.95 7.79 / 9.10 4.58 / 11.25 234.53 / 1,480.02 219.60 / 1,347.77
macOS arm64 18.84 / 94.61 14.22 / 17.99 12.04 / 17.32 853.80 / 4,798.30 846.38 / 4,260.07

验证

  • Linux 使用 Xeon E5-2682 v4(4 核 8 线程,GCC 13.3),macOS 使用 Apple M5 Pro(15 核,Apple Clang 21)。两端均为 Release 构建,ENABLE_NATIVE=OFF,zvec 查询线程数固定为 8。上述 Arrow/Stile 三提交对比每客户端预热 256 次,每进程计时 4,096 次,每个平台共计时 98,304 次查询。
  • 每个平台用 1,024 个固定查询向量,在本机同一张 HNSW 图上核对三个提交。有序 Top-21 的主键、分数位模式及返回字段逐项一致。
  • 当前提交在 Linux 上通过 Stile、forward filter 读取和 Collection 集成三个测试套件,共 74/74 个用例。macOS 上包含并发读取、segment 和 IVF 在内的七个相关套件共 190/190 个用例通过。

@luoxiaojian luoxiaojian changed the title perf(query): 使用 Stile 解释 sealed IPC 的逐候选谓词 perf(query): use Stile for per-candidate filtering on sealed IPC segments Nov 23, 2026
Embed the Stile v0.1.0 interpreter and use it for single-stage candidate filtering over owning forward views. Keep the Arrow evaluator when a predicate is unsupported or exceeds the Stile compilation budget.

Cover Arrow parity, virtual row IDs, independent chunk layouts, and fallback in the forward filter regression suite.
补齐生产后端选择、整表达式回退、错误恢复、差分语义及已编译谓词生命周期回归;固定来源与 Arrow 21 适配边界,增加可复用生产查询基准。

验证:九组 174 项本机测试通过,限定范围 ASan 75 项通过;Stile 通过 ASan/UBSan。与 PR905 精确基线完成三轮比较及五轮 bitmap 对照复测。全 DB UBSan 仍被既有倒排编码对齐问题阻断。
统一 Stile 源文件归属及兼容性提示,移除独立第三方项目声明,保留 Apache Arrow 来源。新增模块 README,说明 API、示例、回退策略、生命周期与生产接入边界。

验证:README 示例编译运行成功;三组相关回归测试全部通过;格式与 diff 检查通过。
Keep each immutable column index with its forward column snapshot. Synchronize the first successful build, allow retries after errors, and reuse the index across queries and projections.

Compare both batch evaluation APIs with Arrow and cover concurrent preparation, DDL replacement, and index lifetime.
@luoxiaojian
luoxiaojian force-pushed the codex/stile-interpreter-main branch from 507217c to 7789d91 Compare November 24, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant