Skip to content

[Performance]: [4.2-dev] Exact scalar IVF PRE is 10–15× slower with ~8K wide VARCHAR keys after #33514 #33549

Done

Description

@XuPeng-SH

Impact

Broad scalar filters on IVFFLAT PRE became substantially slower after #33514 when the candidate set contains wide VARCHAR primary keys. The returned Top-10 was correct in every timed execution. Related correctness issues are #33504 and #33531.

Reproduction

Single Linux amd64 CN, four IVF lists, probe_limit=4, 8,300 rows with 1,021-byte primary keys. Run the queries through a persistent SQL connection.

CREATE DATABASE qa_vecwide;
USE qa_vecwide;
CREATE TABLE v (id VARCHAR(1100) PRIMARY KEY, seq INT, v VECF32(2));
INSERT INTO v
SELECT CONCAT(LPAD(result,6,'0'),REPEAT('a',1015)), result,
       CAST(CONCAT('[',result,',0]') AS VECF32(2))
FROM GENERATE_SERIES(1,8300) g;
CREATE INDEX vi USING IVFFLAT ON v(v) LISTS=4 OP_TYPE 'vector_l2_ops';
SET probe_limit=4;

SELECT seq FROM v WHERE seq BETWEEN 1 AND 8192
ORDER BY l2_distance(v,'[0,0]') LIMIT 10 BY RANK WITH OPTION 'mode=pre';

Repeat with the upper bound 8193 and with mode=force as the exact relational control. Consume the entire result and verify seq=1..10. The numbers are medians in milliseconds from eight timed trials per cell after two warmups, alternating the mode order.

Eligible keys PRE before 95679da6cf PRE at cc55300698 FORCE before FORCE at cc55300698
8192 23.163 229.432 (9.9×) 1.651 1.540
8193 15.648 235.177 (15.0×) 1.604 1.576

These are adjacent commits across #33514. Two additional runs on 34b63d7261 measured 258–332 ms in PRE. The fixture covers the 8192-key boundary, and the serialized byte limit can independently split wide-key batches.

Code path and expected result

VisitExactPkFilters serializes the candidate PKs as SQL literals, then the exact search visitor executes an index query per predicate batch, reads qualifying rows and merges the exact Top-K. This introduces serialization, repeated SQL execution and intermediate row processing. The timing comparison does not quantify how much each stage contributes.

Keep exact membership before the final Top-K and bound the overhead for broad candidate sets. Validate short and wide keys, both sides of the row and byte budgets, narrow and broad selectivity, stable membership, OFFSET and empty results. The older PRE timings are a performance baseline; the new path must preserve the correctness guarantees added by #33514.

Activity

  1. self-assigned this
    on Dec 1, 2026
  2. XuPeng-SH commented on Dec 1, 2026

    @XuPeng-SH
    ContributorAuthor

    QA handoff for #33551 on 4.2-dev: tested the immediate pre-fix tree (34b63d72, build 01514ba4) and final merge-equivalent tree (847e6c17, build f1cdc4b5). The pre-fix shared build and fixed shared build both use -cover; source tree, binary version, and downloaded SHA-256 were checked.

    Independent Linux/amd64 single-CN MySQL TCP replay of the reported 8,300-row fixture: 1,021-byte VARCHAR keys, four IVF lists, probe_limit=4; 16 alternating timed PRE/FORCE pairs per key count after two warmups. Every result was seq=1..10.

    Eligible keys PRE p50, before → after FORCE p50, before → after
    8,192 408.19 → 32.30 ms 2.74 → 2.55 ms
    8,193 386.04 → 36.69 ms 2.65 → 2.72 ms

    The same-tree pessimistic multi-CN BVT also ran vector_ivf_pre_exact_domain.sql: 51 passed, zero skipped or failed, including a binary-key page with OFFSET, excluded closer rows, and an empty domain. This verifies the reported slowdown and those controls, not full scale/upgrade acceptance. QA should still challenge concurrent wide-key queries, cancellation, and byte-budget boundaries with larger persisted datasets. #33531 remains a separate issue.

  3. Ariznawlll commented on Dec 1, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过,限定为本 Issue 原始宽主键 IVF PRE 性能与正确性修复的验收。 补充测试发现的 TN 重启恢复超时已独立提交 #33654,不再将它混写为 #33551 性能修复失败。下文保留原始故障证据和拆分边界。

    已查清此前两次冷重启查询超时所处的等待链:TN logtail 服务重建期间连接断开,CN 重连后仍等待系统表订阅完成,事务准入处于暂停状态。此次在最新 4.2-dev 上用真实 TN 重启再次得到同一等待栈,并保留现场确认能够随后恢复。恢复前的第一次 30 秒业务请求仍会失败,该故障恢复场景不通过,已由 #33654 独立跟踪。本 Issue 原始性能验收及对应 MOTR/CI 已完成,按原问题范围关闭;不表示该恢复缺陷已修复。

    关键证据

    版本、分支与环境

    • 修复 [4.2-dev] Avoid SQL literal expansion for exact IVF PRE #33551 只合入 4.2-dev,merge 847e6c17c2a69ee5c3f1755ab2682806701e819f。
    • 本次冻结并编译官方 4.2-dev 6a905c7e660a71597ff1eb9fc61907145584377b,实际 SQL git_version() 核对完整 SHA;二进制 SHA256 为 57ec42cbab0cee307ffdd7d1f7a7d82c5963e8c74e40705dd90fad55c2477cdb。没有用 main 替代 4.2-dev 验收。
    • Linux 128、独立目录和无外网容器,3 LogService / 1 TN / 1 CN,保留其他任务;未使用 129。MO 服务没有产品补丁。性能对照统一 12 GiB 内存/含 swap 上限、4 CPU;故障诊断通常 6 GiB、2 CPU,低 CPU 对照单列。

    一、最新版本重做原始性能对照

    严格使用原始 VARCHAR(1100)、实际 1021 字节主键、8300 行、IVF lists=4、probe_limit=4。保留同一 SQL 连接,8192/8193 两个候选域分别两轮预热、16 对交替 PRE/FORCE 查询,每次完整取数并核对 seq=1..10。

    对照为修复直接父提交 34b63d72614b81bf8fd4d08dd5930a0773342345;新/旧/旧/新四个独立环境依次执行,均核对运行版本和正常退出。以下为各单元 16 次中位数,ms:

    轮次 PRE 8192 PRE 8193 FORCE 8192 FORCE 8193
    latest 1 42.079 45.567 2.901 2.935
    parent 1 386.657 393.565 2.808 2.935
    parent 2 413.379 415.882 3.577 3.709
    latest 2 40.803 47.945 3.160 2.927

    256 次计时查询全部结果正确。PRE 仍有约 8–10 倍改善;不把共享机器上的绝对毫秒数承诺为生产 SLA。此前 91c59a43bd519f7cccee408035cbf6c5b13dc0e2 同样取得约 8–10 倍改善,此次表格是最新版本的新一组独立测量,没有混合旧样本。

    二、两次旧失败的现场证据

    此前 portable-v2 与 portable-v4 在最后冷重启后报:

    OperationalError(2013, 'Lost connection to MySQL server during query (timed out)')
    

    重新解压两轮当时保存的 CN goroutine 快照,两轮均有如下等待链,参数 (1,1) 为系统库/系统表订阅:

    connector.run
      -> PushClient.connect
        -> PushClient.subSysTables
          -> PushClient.forcedSubscribeTable(..., 1, 1)
             logtail_consumer.go:807 [select]
    

    同时分别有 11 / 14 个 goroutine 停在 txnClient.waitReadyLocked;快照中没有 IVF 搜索执行栈。这与日志中 TN 副本替换、logtail 服务关闭/重建、CN stream closed 和事务暂停相吻合,不能仅凭最终错误码判断是向量算子慢。

    v4 原始 UTC 时间线:

    21:47:48.251  TN close logtail service
    21:47:48.257  CN clean finished, start to reconnect
    21:47:48.264  CN stream is closed on send / rpc stream closed
    21:47:48.358  txn client is in pause state, wait for it to be ready
    21:47:48.364  TN start logtail service
    21:48:17.629  客户端 30 秒查询超时
    21:48:17.642  保存 CN goroutine,仍在 forcedSubscribeTable
    21:48:17.806  测试清理才发送 SIGTERM
    

    此前清理过早结束了后续观察,因此旧两轮单独不能证明“永远恢复不了”,也不能证明数据丢失。

    三、最新版本真实故障复现与恢复观察

    保留已持久化的四张各 48,000 行表,在独立副本上执行:

    1. 启动完整集群,核对完整 SHA、三个 Log 投票副本;实际读取 wide 的 COUNT(*)=48000、SUM(seq)=1152024000。
    2. 只向本测试 TN 发送 SIGTERM,确认其正常退出;CN 和 LogService 保持运行。
    3. 间隔 1 秒,用相同二进制/配置/数据目录重启 TN,立即通过新连接查询。保留原 30 秒客户端超时,没有放宽原失败条件。
    4. 若首次请求失败,先保存 CN goroutine,继续用新连接观察恢复,并逐条校验 PRE/FORCE Top10;再检查四种主键表的 OFFSET 边界结果。

    首组三轮中的第三轮得到:

    首次业务尝试(整条业务链):30.243590 s,OperationalError 2013 timed out
    goroutine:forcedSubscribeTable(1,1),16 个事务等待 waitReadyLocked
    后续业务尝试:3.222094 s,COUNT=48000,SUM=1152024000
    PRE / FORCE:Top10 完整相等
    恢复后四表边界复查:8/8 通过
    

    对应 UTC 服务端日志:

    05:07:39.485634  clean finished, start to reconnect
    05:07:39.491876  stream is closed on send
    05:07:39.491891  fail to send request via morpc stream: rpc stream closed
    05:07:39.491937  reconnect signal is received
    05:08:11.191982  forced subscribe table timeout
    05:08:11.192082  开始下一轮 reconnect
    05:08:11.218124  connected to server
    

    即失效订阅等待约 31.7 秒后才进入下一次重连,下一次约 26 ms 恢复连接。代码中的 forcedSubscribeTable 在请求交给异步发送后等待订阅标记,按 30,000 个 1 ms tick 检查;该等待没有立即响应这里已发生的 stream 失败。期间事务准入暂停,30 秒客户端先超时。可核对 精确版本等待循环 和 重连流程。

    随后用另一份独立数据副本再完成七轮同样 TN 重启,七轮首个读取均通过。合并计数为 10 轮中 1 轮首次超时、9 轮首次通过;所有轮次最终数据校验通过。这是本次观测频次,不作为概率保证。

    这证明了可恢复的 CN logtail 重连等待及首次请求失败,不能写成 TN 永久退出或索引损坏。#29275 也涉及系统表订阅与事务暂停,但其大目录 forced-flush/取消条件不同,本次不直接判定二者重复。

    四、已通过的扩展覆盖与 MOTR

    • 同一最新版本、保留原失败数据副本及原主机名:连续 10 轮正常冷重启通过;另有 3 轮 TN 延迟启动 18 秒、3 轮 TN SIGSTOP/CONT 18 秒、3 轮 0.5 CPU 配额冷启动对照通过。共 19 轮,95 个进程正常退出;每轮首次业务读取、精确 PRE/FORCE 和后续四表边界均校验。上述成功不抵消真实 TN 重启中的首次超时。
    • 最新版本重新完成四种主键各 48,000 行的持久化 72 项矩阵、8 连接 × 20 次查询(160 次精确核对)、10 次实际活动查询取消、取消后 72 项复查,以及三轮完整冷重启各 72 项断言。25 个服务进程正常退出,整套最新 driver 退出码 0。
    • 更新既有 MOTR 4.2-dev #399,head 0cbe63a8d3cb0c193e234de161922eb058d4c198。每套持久化用例增加至三次最终冷重启,并在冷读取失败时先保存等待栈和后续恢复情况,再保留失败退出;不会因后续读取恢复而把首个失败改成 PASS。main nullable check logic update for mergesort #404 只保留显式选择 4.2-dev 的每日薄调度。没有 MatrixOne 主库 PR。
    • 原 CI 46753054127 在旧 91c 版本完成三套用例及 63 次原生 race。更新后的 46814413712 已完整 success,被测 MOTR head 为 0cbe63a8d3cb0c193e234de161922eb058d4c198。
    • 已下载并核验该 run 的 188,169 字节产物(artifact 15575456880):三套独立 wide-key fixture 全部通过,每套 5 次运行时版本检查均为 6a905c7e660a71597ff1eb9fc61907145584377b;每套持久化后 72 项、取消后 72 项、三次最终冷重启各 72 项,共每套 360 项、三套 1,080 项矩阵断言。另有合计 30 次并发精确结果、30 次已观察到执行中的成功取消,以及 192 次计时查询的精确结果检查。
    • 三套共 75 个服务进程退出记录均为 exit 0,未出现强制清理、首次冷读取失败或被后续成功掩盖的失败;21 个原生根测试各执行 3 次,共 63 次 race 通过,0 fail、0 skip。这里的三套托管用例每套是 2 workers × 5 queries,本地更高并发的 8 workers × 20 已在上文单独列出。
    • 上述正常回归 CI 通过不抵消本次 128 真实 TN 重启中已经复现的首次超时,也不等同于汇总 PR 所有无关 job 均通过。

    待解决点

    本 Issue 原始性能与正确性验收无剩余未通过项;以下故障恢复问题已移至 #33654,保留开放:

    • 原始 IVF PRE 性能与正确性修复已有通过证据;另一个问题是系统表订阅对应的流已失败后,CN 仍等完整订阅窗口,导致恢复期间首次 30 秒查询失败。需要对这一等待/重连边界作独立处理,再执行相同故障与精确数据复查。
    • 不建议单纯增加客户端超时或吞掉首个错误作为修复。保留现有错误断言、goroutine 和恢复后数据证据;本次不修改产品实现,不转派。

    最终结论:本 Issue 原始性能问题测试通过,按原问题范围关闭。4.2-dev 宽主键 IVF PRE 性能、精确结果与对应 MOTR 回归/CI 均通过;TN 重启后首次业务请求超时仍未修复,已独立提交 #33654 跟踪。关闭 #33549 不代表 #33654 通过,也不代表所有故障恢复场景通过;MOTR 回归 PR 尚待合入。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions