Skip to content

[Bug]: COM_QUERY range-count regresses after #32492, outside prepared-TP mitigation #32857

Open

Description

@LeftHandCold

Is there an existing issue for the same bug?

This is a narrow follow-up to #32840, not a claim of a second introducing PR. #32840's measured 129 workload uses prepared execution; the local mitigation being evaluated restores reuse only for prepared TP. This Issue preserves the independently measured text-protocol range-count residual so it is not accidentally declared fixed by that mitigation.

#32818 separately tracks per-statement Statfs. The range-count control already performs Statfs in the parent because it has a Group operator. A text point-select control also exercises the known #32818 path; its unprofiled throughput delta was inconclusive and is NOT reported here as another confirmed regression.

Branch Name

main

Commit ID

Other Environment Information

  • Apple M2 Pro, 16 GiB RAM, Darwin 24.0.0 arm64. This host is not dedicated.
  • Same Go 1.27.1/native build inputs; all binaries built with the same GOEXPERIMENT_OPT= override. No claim of equivalence to CI's SIMD-enabled Linux binaries.
  • Local single-process LOG/TN/CN, local DISK-V2 FileServices, GOMAXPROCS=4, GOMEMLIMIT=3GiB; no external shared cluster modified.
  • 1,000 rows, 8 pinned SQL connections, 1,000 warm-up queries (125 per connection), 15-second scored interval per case.
  • A cleanly stopped parent-produced seed was copied before every process start; every seed file was SHA256-verified before start. Pre/post row count and independent ID/k/v sums matched. Every returned COUNT was checked against 100; zero query errors and zero wrong results.
  • Version order and case order were reversed. No build/test workload ran alongside the measured suite. One separate suite collected CPU profiles; one suite ran without profiling. Do not combine them into one statistical sample or extrapolate to 129's 100M rows/1,000 threads.

Actual Behavior

SQL uses COM_QUERY, not bound arguments and not implicit driver Prepare:

SELECT count(k) FROM t WHERE k BETWEEN 0 AND 9;
-- Change lower bound deterministically over 0..90; upper bound = lower + 9.

Unprofiled suite, version order parent -> child -> local prepared-only candidate -> candidate -> child -> parent:

Version Run 1 QPS Run 2 QPS Mean QPS Relative to parent
Exact parent 15,104.42 14,762.34 14,933.38 baseline
Exact child 14,563.83 13,818.20 14,191.01 -4.97%
Local prepared-only candidate on e116 14,016.45 14,516.56 14,266.50 -4.47%

Separate profile-instrumented suite, parent -> child -> e116 -> candidate -> candidate -> e116 -> child -> parent:

Version Run 1 QPS Run 2 QPS Mean QPS Relative to parent
Exact parent 15,403.15 14,910.23 15,156.69 baseline
Exact child 13,956.38 13,955.62 13,956.00 -7.92%
Unmodified e116 14,154.77 14,108.05 14,131.41 -6.76%
Local prepared-only candidate 14,129.22 14,494.64 14,311.93 -5.57%

The local candidate deliberately does not change COM_QUERY ownership. Its prepared range-count control recovers to about 98-99% of parent; that improvement must not be applied to the text results above.

Expected Behavior

Retain original SQL correctness, memory admission, ownership and cleanup guarantees while avoiding an execution-cost regression for non-prepared TP. Do not expand a prepared-only exemption to all TP merely to hide the cost. Validate any follow-up with parent/candidate text and prepared controls and a Linux/original-scale run before claiming general recovery.

Steps to Reproduce

  1. Build the exact parent and child with identical toolchain/native options.
  2. Create a fresh test database and this table on the parent:
CREATE TABLE t (
  id INT PRIMARY KEY,
  k INT,
  c VARCHAR(80),
  v INT,
  KEY idx_k(k)
);

Insert rows for integer i=0..999: (i, i % 100, CONCAT('row', i), 0). Cleanly stop and save the complete data directory. Before each measured process start, restore that same seed and verify file hashes.

  1. Use eight fixed connections. Send literal SQL with lo=(iteration*17+worker_id)%91 and hi=lo+9. With go-sql-driver/mysql, call conn.QueryRowContext(ctx, formattedSQL) without arguments, never Prepare or QueryRow(sql,args...). Expect exactly one COUNT value of 100 for every request.
  2. Warm up, measure for 15 seconds, consume every result, then stop. Repeat parent/child in reverse order. Profile in a separate paired suite.

Additional Information

Established: repeated local parent/child throughput loss with unchanged data/protocol, zero errors, and a stable uncovered text range-count residual after prepared-only gating. This is smaller than the original 129 prepared regression, not a new 35% COM_QUERY claim.

Code changes relevant to the remaining cost:

  • TableScan.SetAllocationAccount adds statement-account-backed expression/output allocation.
  • prepareReaderFilter may schedule all columns and reader-side filtering when OutputAllocation is installed.
  • Expression construction uses the allocation-aware path. Non-prepared execution reconstructs a Compile regardless of the mitigation; eliminating prepared Reset->Free does not address these costs.

One paired text-range profile has parent/child Statfs cumulative samples 13.23s / 11.99s for roughly 10s sampling windows at 15,403 / 13,956 QPS. Normalized by whole-interval QPS, the approximate per-query Statfs cost is unchanged (~86us); these are estimates, not exact counters for requests inside the profile window. This argues against attributing all text-range residual to a newly introduced disk-budget sample. TableScan.Call cumulative samples increase from 0.95s to 1.64s in that pair. Do not add nested CPU percentages or equate this observation with a fully isolated mechanism.

Not established: exact division between account/pointer-metadata work, reader filtering, dictionary consumers, or other #32492 changes; original-scale Linux impact; a safe general non-prepared fix. Keep these as investigation work rather than widening the prepared mitigation.

Raw results, 24 profiles, exact executable hashes, test validation and the runnable bounded harness are retained in the review evidence. All owned processes were stopped normally; no production environment was changed.

Activity

  1. self-assigned this
    on Nov 18, 2026
  2. added
    severity/s0
    and removed on Nov 18, 2026
  3. XuPeng-SH commented on Nov 19, 2026

    @XuPeng-SH
    Contributor

    转测:main 短索引范围扫描开销优化

    #32895 已于 2026-11-19 02:02 UTC 合入 main,merge SHA ae9e665f3093094ba3286e72bf1af8e111463180,最终 head ac8200937b0ab36bd12b30fe7b1960a1128db62f,base 035af996806917b23d9428695e0295b65cb16356。完整 issue 评论、PR 会话、评审及最终补丁已核;旧版 replay admission/read-ahead findings 已通过撤掉 gather 路径解决,未见当前适用的已验证反例或必要未完成开发 follow-up。交 QA @Ariznawlll,保持 open。转测不是性能恢复或验收通过。

    最终实际范围:

    • 未掩码且已证明三个输入非 NULL 的 prefix_between 复用既有非空 Boolean 结果路径;NULL 输入仍保留 NULL 语义。
    • dictionary publication slots 延后到可发布 dictionary output 的 partial selection 才创建;apply-only / all-match 避免无用准备。
    • committed replay 保持原标量投影和逐行分配顺序。先前候选版 gather、tombstone/iterator guards 已移除,不把旧版合并优化收益算给最终版。

    证据与版本边界:

    • 作者在 PR 正文报告 Go 1.27.1 + SIMD 下 disttae、colexec、table_scan 完整普通及 race suite、增量格式/vet/lint/molint 通过。真实 replay iterator 测试覆盖 7-byte 首行拒绝、23-byte 第二行替换峰值拒绝、24-byte 两行成功及 account 清理。
    • 最新批准评审基于 7fb22c67e430110d7f4abf71097c4af161fb80c2,不是最终 head ac820093...。评审实际执行 prefix validity、reader selection、上述 7/23/24-byte admission、reader ownership 和完整 colexec/table_scan 检查;冻结 CI 记录 x86 UT 与 multi-CN BVT 成功。最终合并队列报告 CI Required 成功,这不等于原问题端到端性能验收。
    • 历史独立 QA 在 891ff4655f7cf688aa359c3413dea86240a2a023 对比 87c44445... 执行每版 1,228 个自定义断言及投影检查;两个 text range-count 短跑为 +1.61% / +1.70%。该版本后来仍被评审发现 replay admission/read-ahead 问题,并被继续修改;这些旧版通过项和吞吐数字不能作为最终 head 的通过证明或性能恢复结论。
    • 作者给出的 replay 微基准 8.83 → 11.73 µs 是撤掉 gather 相对旧候选版的代价,不是最终版对原问题 baseline 的端到端回归数据。最终 executor-only 补丁的端到端吞吐尚未测量。本次巡检没有自行运行 SQL、测试或性能基准。

    请 QA 固定包含 merge 的 main 版本,按本 issue 原 COM_QUERY(无绑定参数/无隐式 Prepare)1000 行、8 固定连接、逐条 COUNT=100 的同数据同资源反序配对方法复测,并独立记录 prepared range-count / text point-select 控制组。验证 NULL、partial/all-match、apply-only、DML/rollback、取消后可用性、内存拒绝和释放;原规模 Linux 100M 行 / 1000 sessions、重启/持久化与最终 head 吞吐仍属未测边界。若仍有残余性能退化,记录精确版本和对照证据,不用旧候选版结果覆盖。未自动 backport 或部署。

  4. Ariznawlll commented on Nov 20, 2026

    @Ariznawlll
    Collaborator

    QA 阶段性性能测量(2026-11-20,尚不能认定恢复)

    固定完整构建版本:parent f70c37b16e2d2378dd6d48775df0f29c610dce6b、#32492 child 49d552e16cfb7fb9160210d19f2874dc4a71272c、包含 #32895 的 final b543648d99395492918ce0a5a3c08a7de952042d。每轮启动均核对 git_version()、完整 1000 行冻结数据及逐文件 SHA256;三版二进制哈希也已保存。

    环境为 macOS 独立单 CN,GOMAXPROCS=4、GOMEMLIMIT=3GiB、独立数据目录和端口。8 固定连接,每连接 125 次预热;每轮 15 秒计分并逐条消费结果。range-count 必须返回 100,点查返回 0;prepared 控制组逐次更新绑定参数。执行顺序 parent→child→final→final→child→parent。18 个计分结果均 0 SQL 错误、0 错结果,六轮服务均正常退出。

    用例 parent 两轮 / 均值 QPS child 两轮 / 均值 QPS final 两轮 / 均值 QPS
    text_range 6682.67 / 8851.07;7766.87 6639.07 / 8881.13;7760.10 6596.53 / 7466.07;7031.30
    prepared_range 3101.80 / 5903.07;4502.43 3338.20 / 4741.67;4039.93 3240.60 / 4272.80;3756.70
    text_point 6718.80 / 12246.13;9482.47 5956.20 / 9497.20;7726.70 6331.27 / 9161.47;7746.37

    后半段三个版本的吞吐均明显上升,存在显著时间漂移;两轮均值也不能消除该影响。因此不能挑选某一轮宣布恢复,也不能用另一轮宣称普遍残余 33% 退化。本机 1000 行数据不能外推为 Linux 原始 100M 行 / 1000 sessions 或生产性能结论。

    已排除误连其他版本、RPC/SQL 端口冲突、共享 LogService、prepared 固定参数及并发资源干扰的结果,不将其混入上述配对。原始规模 Linux 性能、最终 head 的持久化/重启及完整边界尚未完成;issue 保持 OPEN,不标性能验收通过。

  5. Ariznawlll commented on Dec 1, 2026

    @Ariznawlll
    Collaborator

    结论

    未完成验收,保持开放。 本轮补做 Linux 上原 1,000 行/8 固定连接协议的六轮反序对照,累计 1,923,929 次计分查询,0 SQL 错误、0 错结果。目标 COM_QUERY range-count 的三轮平均 QPS 与原始父提交基本相同(-0.055%);但不能据此宣布普遍性能恢复:当前是共享主机小数据短跑,物理种子跨版本不兼容,且 text point-select 控制组均值仍低约 7.44%,大规模门槛未完成。

    关键证据

    版本和运行配置

    • 原始引入前父提交:f70c37b16e2d2378dd6d48775df0f29c610dce6b。
    • 本轮最新官方 main:ec945a6323d4e505a8445bfd129f02a70073c301,包含修复 perf(exec): reduce accounted work on short index range scans #32895。所有进程启动均实际核对完整 git_version(),二进制 SHA256 单独保存。
    • 128 Linux,独立单进程 LOG/TN/CN、独立数据目录;Go 1.27.1、SIMD、GOAMD64=v3、funcalign=64、相同 GCC 工具链,GOMAXPROCS=4、GOMEMLIMIT=3GiB、8 GiB 进程 cgroup 限额。没有在 129 执行测试。
    • 自有构建/集成测试全部结束后才启动计分,没有把本轮自己的编译与性能测试并发。128 仍有其他既存任务,因此不是专用性能机器。

    数据种子的兼容限制

    最初尝试把父提交正常关闭后的完整冻结目录直接交给最新 main。main 启动时返回:

    invalid state catalog 4.0.7 offset 44 differs from binary offset 53;
    4.0.7 is frozen and further migrations require a new catalog version
    

    该尝试未进入 main 的性能计分,未把它当作 range-count 回退或本 Issue 的失败。随后重新开始完整对照,两个版本各自建全新库,使用相同逻辑行:i=0..999、k=i%100、c='row'+i、v=0。每个版本正常停止并冻结自己的种子,每次启动前逐文件 SHA256 核对该版本的拷贝。

    因此,本轮证明的是同逻辑用户数据、每版本内部冻结种子,不是跨版本物理文件完全相同。最初只有父版本的一轮数据没有混进下表。

    协议与执行方法

    • 8 个固定连接,每连接预热 125 次,随后 15 秒计分。
    • COM_QUERY range 使用无参数的 literal SQL:lo=(iteration*17+worker)%91、hi=lo+9,逐次结果必须为 100;未调用 Prepare,也未把它隐式改为带参数查询。
    • prepared_range 单独 Prepare,再逐次更新 lo/hi;不能拿它的结果代替 text_range。
    • text_point 是独立的主键点查控制,逐次返回 v=0。
    • 每组之前/之后都完整逐行核对全部 1,000 行,而不是仅检查 COUNT。
    • 版本顺序 P→M→M→P→P→M,case 顺序逐轮正反交替;未采样 profile,避免把带 profile 和不带 profile 的成绩混合。
    场景 父提交三轮 QPS main 三轮 QPS 均值变化
    COM_QUERY range-count 6594.76 / 6495.77 / 6442.79 6169.08 / 6700.13 / 6653.42 -0.055%
    prepared range-count 8230.89 / 8161.81 / 8091.75 8275.82 / 8844.79 / 8693.32 +5.43%
    COM_QUERY point-select 6780.99 / 6774.75 / 6645.79 5996.52 / 6419.81 / 6281.40 -7.44%

    目标 text_range 的均值 P=6511.11、M=6507.54;三轮样本变异系数分别约 1.18% 和 4.52%。这里没有临时自定“5%以内就通过”的阈值,也没有用 prepared 控制的提升抵消 point 控制的下降。

    计分共 18 组 / 1,923,929 次请求,错误与错结果均为 0。性能脚本保存了各组 p50/p95/p99 和原始 QPS;本次只报告观察,不把 15 秒共享主机结果解释为稳定业务 SLA。

    证据与回归状态

    128 目录 /root/qa-32857-20261202:

    • bench.go:固定连接、原协议、预热、逐条结果断言。
    • run_logical.py:版本种子、SHA校验、六轮顺序、服务清理与原任务恢复。
    • logical/summary.json、各 round-*/bench.jsonl、seed-hashes-*.json、binary-hashes.json:原始运行证据。
    • run.log 保留最初跨版本目录不兼容的尝试,与后续 logical.log 分开。

    本轮是独立验收探针,尚未宣称接入每日大数据回归;不把已有小 SQL 用例或此处短跑当作 100M/1,000 sessions 的回归覆盖。全部自有计分实例已停止,原来的自有测试 MO 已恢复。

    待解决点

    需继续按交接要求完成专用资源上的大规模 Linux/100M 行/1,000 sessions 验收,并补齐完整边界的对应回归。text_point 控制组的下降需要独立配对/profile 归因,不能只凭这次共享主机短跑就另判一个已确认新产品 Bug或将其归因于 #32895。当前目标 range-count 在本次小数据测量中未见稳定残余损失,但不足以关闭完整性能验收。

    最终结论:未完成验收。 已完成 Linux 小数据六轮原协议对照,目标 range-count 均值接近基线且所有查询正确;未完成项:大规模与专用资源性能验收、控制组下降的独立分析及完整专项回归,因此保持开放、不转回研发。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions