Skip to content

[Bug]: Prepared random_ranges regression disables pruning and loses index access with BIGINT bindings #29606

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Related historical reports #26971 and #24335 concern different regressions. No open issue with the same current random_ranges regression was found.

Branch Name

main

Commit ID

fdf96ba

Other Environment Information

  • Nightly evidence: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/37189981347/job/111406877719
  • GOOD reference: b1b68925d7f6fb32153e788b5285f424222e85ca.
  • Local reproduction: macOS 15.5, arm64, Mac16,1, 16 GiB RAM, 10 logical CPUs; existing embedded SQL integration fixture with one CN and one TN.
  • Data: first 1,000,000 complete rows of the original nightly sbtest1.csv, all four columns preserved. This is a prefix subset, not a uniform sample.
  • CSV size: 200,000,001 bytes; SHA256: 0445c02774cf9e340e4b459f3d648936743bee0c8f031d35c8b9d8a1f7d4cfd9.
  • Original k distribution retained: min 1,555,999, max 8,338,485, mean approximately 5,009,201. Keep the query key domain at 10,000,000 when using this subset.
  • Actual sysbench C MySQL client at upstream de18a03, original benchmark Lua, 32 threads, 30 seconds, random seed 42; server CPU profiling enabled for comparisons.
  • Local client uses system LuaJIT and build/connector adaptations for macOS and plaintext local connections. Query generation and integer parameter binding are unchanged; both server versions use the same client.

Actual Behavior

Prepared random_ranges throughput regresses by orders of magnitude on the same real data and client.

Server revision / diagnostic experiment QPS Queries Ignored errors
GOOD b1b68925d7 14,172.36 425,317 0
#29379 50c15c1fd46 18,862.26 565,930 0
September 28 1ded9fc9148 490.82 14,752 0
September 28, diagnostic storage-gate ablation only 17,754.67 532,696 0
Parent of #29556, 3f6be2e475e 88.13 2,655 0
Current main fdf96ba0be 69.06 2,102 0
Current main, omit BETWEEN lowering only 76.69 2,315 0

These are individual observational runs, not a stable 205x regression estimate. A separately instrumented main run reached 481.70 QPS. Plan-path loss and expensive row filtering remain reproducible despite timing variation. No production fix has been benchmarked yet.

Expected Behavior

Safe integer bindings should retain usable secondary-index ranges and storage pruning, with throughput comparable to GOOD under the same workload. Preserve the existing numeric/source-domain fixes, warning/error ownership, short-circuit behavior, and correctness at type/precision boundaries. Changing parameter values must not require rebuilding the entire plan for every normal execution, and must not reuse an unsafe prior specialization.

Steps to Reproduce

  1. Use clean detached worktrees for GOOD and the affected revision and matching native artifacts.
  2. Create and load sbtest1 with the original schema:
CREATE TABLE sbtest1 (
  id INT NOT NULL AUTO_INCREMENT,
  k INT DEFAULT 0,
  c CHAR(120) DEFAULT '',
  pad CHAR(60) DEFAULT '',
  PRIMARY KEY (id),
  KEY k_1 (k)
);
  1. Load the first 1M rows of the original nightly CSV, verify the row count, flush both base and hidden secondary-index tables, wait for logtail application, and refresh table statistics. Preserve the original key distribution; setting table_size=1000000 for this data would query mostly empty ranges.
  2. Use select_random_ranges.lua and oltp_common.lua from mo-sysbench revision 1a7886fc7566dfc9fd85a81801f09471151365d3. Run the actual sysbench client with local connection settings and:
--tables=1 --table_size=10000000 --threads=32 --time=30
--rand-seed=42 --number_of_ranges=10 --delta=5 --report-interval=5

The prepared query has 20 bound parameters:

SELECT COUNT(k) FROM sbtest1
WHERE k BETWEEN ? AND ? OR k BETWEEN ? AND ?
   OR k BETWEEN ? AND ? OR k BETWEEN ? AND ?
   OR k BETWEEN ? AND ? OR k BETWEEN ? AND ?
   OR k BETWEEN ? AND ? OR k BETWEEN ? AND ?
   OR k BETWEEN ? AND ? OR k BETWEEN ? AND ?;
  1. Capture the actual bound plan, storage filters/selected blocks, and CPU profile. Compare identical data/client settings across revisions.

Important protocol detail: Lua declares sysbench.sql.type.INT, but sysbench bind_create normalizes integer bindings to BIGINT (int64_t). The wire type is MYSQL_TYPE_LONGLONG (8), confirmed on actual benchmark connections. An INT32-only Go probe can select a different, fast plan and miss this regression.

Additional information

Evidence-backed mechanisms

  1. Earlier storage-filter regression. At 1ded9fc9148, the query still selects the hidden secondary index, but recorded index scans have empty storage filters and scan all 124 blocks. CPU is dominated by Filter.Call (85.22% cumulative), opMultiOr (35.23% flat), and byte-range comparison (20.48% flat).

    A diagnostic overlay removes only the constant/statement-invariant diagnostic exclusions in compile.filterScanStorageExprs, retaining volatile-function exclusion and logical predicates. On the same revision/data/client, QPS recovers from 490.82 to 17,754.67 and the large byte-range/OR filtering hotspot disappears. These exclusions were introduced by a99db843c7b4 (fix: align date compatibility semantics #28851, September 27). Prepared placeholder conversions are conservatively classified as potentially diagnostic even for the actual safe integer bindings. Source attribution plus the ablation identifies this mechanism; an exact full-commit before/after bisection has not been completed.

  2. Current type/shape regression. Actual BIGINT bindings on main produce a base sbtest1 scan with OR-connected AND pairs of >=/<=. Integer normalization and checkIndexFilter do not compose: the OR matcher rejects AND children, while column-side promotion can independently prevent native index eligibility. INT32 controls retain prefix_between index access. Omitting only the current BETWEEN lowering remains slow, so reverting that branch alone is insufficient. fix(sql): preserve prepared numeric and temporal contracts #29556 is not the initial origin: its parent is already slow.

  3. Profiles corroborate the execution cost. Three valid CPU samples from the nightly 100-thread random_ranges window show TableScan.evalFilter at 88.94% cumulative CPU and INT32 comparisons at 62.64%; plan building is only 0.40%. Local main reproduces the integer AND/OR filtering hotspot. Cumulative percentages overlap. The later 1000-thread RPC capacity timeout is a separate failure.

Current main already has execution-local diagnostic proofs and a runtime-plan cache. The fix should repair their integration rather than add another proof/cache mechanism. The storage-gate removal above is a diagnosis-only ablation, not a safe production patch.

Proposed repair and engineering constraints

  • Reuse existing prepared integer boundary admission/proofs across IN, comparisons, and BETWEEN. For eligible conversions, prove original-domain equivalence and both bounds before publishing any rewrite. Preserve the column's physical domain and executable parameter references.
  • Keep BETWEEN when both bounds are safely normalized; use existing prefix_between and storage-range planning. Preserve the existing semantic path when independent comparisons are necessary. Avoid broadening the index matcher to arbitrary AND trees as a workaround.
  • Use the existing execution-local diagnostic candidates and proof to admit safe storage filters. Preserve genuine warnings/errors, inactive-arm behavior, explicit row-scoped casts, and volatile-function exclusion. Proof cannot escape its parameter binding or plan generation.
  • Reuse the existing runtime-plan cache with per-execution checks for guarded narrowing. Boundary failure must replan in the original valid domain and must not execute an unsafe cached specialization. Normal executions should check the relevant parameters without rebuilding plans or traversing all expressions repeatedly.
  • Consolidate overlapping conversion/proof helpers and remove superseded wiring and dedicated tests. Add no parallel state machine, second cache, or duplicate execution/storage path. Review production, test, and documentation changes separately; each added abstraction must justify its cost.

Acceptance criteria

  • Actual BIGINT PREPARE/EXECUTE results match an independent oracle; retain INT32 as a separate control rather than substituting it for the benchmark protocol.
  • Safe → out-of-range → safe executions of the same prepared statement preserve results and warning/error semantics, without leaking proof or stale values across executions/retries.
  • Cover NULL, reversed/equal/overlapping bounds, signed/unsigned and precision boundaries, explicit casts, real conversion diagnostics, empty tables, and inactive branches using orthogonal cases and existing fixtures.
  • Verify covering-index and backfill paths, serialized/composite-key boundary correctness, and a no-index control. Safe ranges reach storage filtering and block pruning; exact residual predicates remain where needed.
  • Verify ordinary safe bindings reuse the plan/Compile; boundary-changing bindings cannot reuse unsafe narrowing. Confirm existing related correctness regressions still pass.
  • Interleave multiple GOOD/fixed runs on the same 1M-row/32-thread real-data workload, compare QPS/latency, scan counts, plan-build counts, and profiles. Performance must recover to the GOOD baseline within established run-to-run variation.
  • Audit equivalent prepared range/comparison consumers and keep implementation/test/documentation scope proportionate. Avoid rebuilding duplicate fixtures or asserting only implementation-shaped internals.

Activity

  1. added
    kind/bug
    on Oct 4, 2026
  2. Ariznawlll commented on Oct 8, 2026

    @Ariznawlll
    Collaborator

    在当前 main bab4b3286a0dd5683a9b291763817722233e586c 上补充了实际 MySQL 二进制协议和查询路径交叉覆盖。

    环境与数据:

    • 单 CN/TN,本地 1,000,000 行 INT k 数据,KEY idx_k(k);
    • 真实 database/sql + go-sql-driver/mysql server-side prepared statement(interpolateParams=false);
    • 同一个含 10 组 k BETWEEN ? AND ? 的 statement 连续复用,所有场景各 3 轮。

    同一 statement 的绑定序列:

    • 安全 int64:20 行,min=100001, max=190002, sum=2900030;
    • 一组 NULL:其余 9 组共 18 行;
    • 一组 MaxInt64 / MaxUint64:其余 9 组共 18 行;
    • 一组字符串数字:20 行;
    • 一组反向区间:其余 9 组共 18 行;
    • 前两组重叠:去重后共 31 行;
    • 每轮最后换一套安全 int64:20 行,min=200001, max=290002, sum=4900030。

    三轮结果完全一致,边界绑定没有污染后续安全执行,也没有连接或 prepared statement 状态泄漏。安全 int64 和边界后的安全恢复约 0–5 ms;一组 NULL 约 48–61 ms,字符串数字约 42–49 ms,最大有/无符号整数约 12–15 ms,说明非安全域仍走保守路径,但结果语义正确。

    另外补充:

    • 空表连续三次返回 count=0, sum=0;
    • 无索引 131,072 行控制表返回精确 20 行,计划为基表扫描;
    • 复合索引 (tenant,k) 的 prepared BIGINT 查询结果正确,能选择复合索引;当前只利用 tenant 前缀,k BETWEEN 保留为残余过滤,扫描该 tenant 的 32,768 个索引项;
    • 反向、NULL 后再次恢复安全参数,复合索引路径结果保持一致;
    • 显式 CAST(? AS SIGNED) 保留保守基表路径;
    • FALSE AND k BETWEEN ? AND ? 配合非法字符串参数返回 0 且 warning_count=0,未执行分支不产生转换诊断;
    • 源表行数均未变化。

    这组扩展没有发现新的错误结果或 stale binding。剩余需要继续观察的是性能边界:含 NULL/不兼容源域时的整体保守回退,以及复合索引第二列范围尚未收窄第一列前缀扫描。

  3. Ariznawlll commented on Oct 16, 2026

    @Ariznawlll
    Collaborator

    测试补充:BIGINT 参数协议与索引计划(合成数据)

    • 测试版本:main,commit 9f873692e0efa869c64c4d1c84e212c5a8a3272a(2026-10-16)。
    • 环境:macOS arm64,MatrixOne embedded 单 CN/TN;Go 1.27.1。
    • 临时构造 1,000,000 行 INT k 数据,key domain 约 1,000 万;使用 database/sql + go-sql-driver/mysql,显式设置 interpolateParams=false,确保通过 server-side prepared statement 发送 BIGINT 参数。
    • 执行 10 组 k BETWEEN ? AND ?、共 20 个参数的查询。EXPLAIN 选择 Index Table Scan on sbtest1.k_1,包含 10 组 prefix_between Block Filter。
    • 同一个 prepared statement 执行 safe → 超出 INT 范围 → safe,完整重复 3 轮;结果与独立计算 oracle 一致,也与 IGNORE INDEX(k_1) 全表扫描控制一致。测试命令:go test ./pkg/tests/sqlintegration -run '^TestIssue29606SyntheticRandomRanges$' -count=3,3/3 通过。
    • 本探针使用生成数据,不是原始 nightly CSV,也不是原始 sysbench C 客户端;结果仅证明该协议形态下的结果正确性和索引/过滤计划,不作为性能 QPS 结论。探针未提交入库。

    后续 sysbench 性能复测方案

    使用 issue 中原始 sbtest1.csv 前 1,000,000 行(SHA256 0445c02774cf9e340e4b459f3d648936743bee0c8f031d35c8b9d8a1f7d4cfd9),保持 table_size=10000000,不能改成 1,000,000;加载后 flush 基表和隐藏二级索引表、等待 logtail 应用并刷新统计信息。使用 mo-sysbench revision 1a7886fc7566dfc9fd85a81801f09471151365d3 中的 select_random_ranges.lua / oltp_common.lua,以同一个 sysbench C 客户端分别运行 GOOD b1b68925d7f6fb32153e788b5285f424222e85ca 和修复后的 main 9f873692e0efa869c64c4d1c84e212c5a8a3272a:

    --tables=1 --table_size=10000000 --threads=32 --time=30
    --rand-seed=42 --number_of_ranges=10 --delta=5 --report-interval=5
    

    建议 GOOD/fixed 交错运行至少 4 轮(每轮两版本各一次,交替先后顺序),保留每次 QPS/延迟与错误数;同时采集绑定计划、索引扫描的 storage filter/selected blocks、计划构建次数和 CPU profile。只有原始数据和真实 C 客户端的对照结果才能回答性能是否恢复到 GOOD 的波动范围。

    本评论只补充已完成的合成数据验证及后续性能复测方案,不给 issue 整体验收结论。

  4. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • 最新回归使用的 MatrixOne commit:beffc64c486d369406a41cdb1447b120bc93cb41
    • 部署方式:129 单机性能回归(main Family,TP shared mo-data)
    • 测试日期:2026-10-17 至 2026-10-19(北京时间)

    原问题验证

    复查与本 issue 对应的实际 sysbench C 客户端 random_ranges 回归项(sysbench 1.1.0-de18a03,1000W 数据规模、1000 线程、每次 300 秒)。连续三次 main 回归的 TPS 分别为 19,565 / 19,778 / 19,528,忽略错误数均为 0;最新一次平均延迟 51.19 ms、P95 134.90 ms。三次 TPS 最大与最小差约 1.28%,原先的断崖式吞吐下降没有再出现。

    修复已由 #29612 合入。此前对真实 BIGINT 参数的 server-side prepared statement 做过结果与计划验证:10 组 BETWEEN、20 个参数的计划选择 sbtest1.k_1 索引并带 10 组 prefix_between Block Filter;结果与独立 oracle、IGNORE INDEX 控制一致,见前次验证记录。

    范围说明:129 nightly 的数据规模和线程数不同于 issue 原始的 1M 行、32 线程、本地 GOOD/fixed 对照设置;本次没有重新执行该原始配置的交错基准,因此不能把这些 TPS 数字直接与原始 GOOD 的 14,172 QPS 比值比较,也不宣称逐项完成 issue 中所有扩展验收条件。

    Happy Path 覆盖

    1. 真实 sysbench C 客户端 random_ranges:三次 main 129 回归均完成,TPS 稳定在 1.95–1.98 万,错误数 0。
    2. 已有 BIGINT prepared 探针:安全整数参数结果正确,走二级索引及存储过滤;与无索引控制的结果一致。

    Unhappy Path 覆盖

    1. 已有探针在同一 prepared statement 上执行安全值 → 越界值 → 安全值,重复 3 轮,结果与 oracle 一致,后续安全执行未受前次绑定影响;另有 NULL、反向/重叠区间等语义检查,详见验证记录及补充记录。本次只复查 nightly 性能,没有重跑这些边界探针。

    白盒验证

    本次未新增或重跑 UT / -race;这里引用的是先前的黑盒协议/计划探针与最新 nightly 性能结果,不能据此声称白盒覆盖已补齐。

    回归测试

    现有 129 main Family 的 sysbench_random_ranges_10_10000000 用例持续执行并记录性能;最近三次的该用例均通过。最新一次比较器处于 WARMUP 2/5:数据已写入,但自动性能回退门禁尚未启用;此处稳定性判断来自三次实测数据,并非自动门禁结论。本次未修改测试代码。

    测试证据

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions