Repository navigation
Description
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
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
kdistribution 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
- Use clean detached worktrees for GOOD and the affected revision and matching native artifacts.
- Create and load
sbtest1with 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)
);- 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=1000000for this data would query mostly empty ranges. - Use
select_random_ranges.luaandoltp_common.luafrom 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 ?;- 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
-
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 byFilter.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 bya99db843c7b4(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. -
Current type/shape regression. Actual BIGINT bindings on main produce a base
sbtest1scan with OR-connected AND pairs of>=/<=. Integer normalization andcheckIndexFilterdo not compose: the OR matcher rejects AND children, while column-side promotion can independently prevent native index eligibility. INT32 controls retainprefix_betweenindex 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. -
Profiles corroborate the execution cost. Three valid CPU samples from the nightly 100-thread random_ranges window show
TableScan.evalFilterat 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_betweenand 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
fix(plan): preserve guarded prepared integer range access (#29612)
fix(vector): handle empty reversed prefix-between ranges (#29645)
Ariznawlll commentedon Oct 8, 2026
在当前 main
bab4b3286a0dd5683a9b291763817722233e586c上补充了实际 MySQL 二进制协议和查询路径交叉覆盖。环境与数据:
INT k数据,KEY idx_k(k);database/sql + go-sql-driver/mysqlserver-side prepared statement(interpolateParams=false);k BETWEEN ? AND ?的 statement 连续复用,所有场景各 3 轮。同一 statement 的绑定序列:
int64:20 行,min=100001, max=190002, sum=2900030;NULL:其余 9 组共 18 行;MaxInt64/MaxUint64:其余 9 组共 18 行;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;(tenant,k)的 prepared BIGINT 查询结果正确,能选择复合索引;当前只利用tenant前缀,k BETWEEN保留为残余过滤,扫描该 tenant 的 32,768 个索引项;CAST(? AS SIGNED)保留保守基表路径;FALSE AND k BETWEEN ? AND ?配合非法字符串参数返回 0 且 warning_count=0,未执行分支不产生转换诊断;这组扩展没有发现新的错误结果或 stale binding。剩余需要继续观察的是性能边界:含 NULL/不兼容源域时的整体保守回退,以及复合索引第二列范围尚未收窄第一列前缀扫描。
Ariznawlll commentedon Oct 16, 2026
测试补充:BIGINT 参数协议与索引计划(合成数据)
main,commit9f873692e0efa869c64c4d1c84e212c5a8a3272a(2026-10-16)。INT k数据,key domain 约 1,000 万;使用database/sql + go-sql-driver/mysql,显式设置interpolateParams=false,确保通过 server-side prepared statement 发送 BIGINT 参数。k BETWEEN ? AND ?、共 20 个参数的查询。EXPLAIN选择Index Table Scan on sbtest1.k_1,包含 10 组prefix_betweenBlock Filter。IGNORE INDEX(k_1)全表扫描控制一致。测试命令:go test ./pkg/tests/sqlintegration -run '^TestIssue29606SyntheticRandomRanges$' -count=3,3/3 通过。后续 sysbench 性能复测方案
使用 issue 中原始
sbtest1.csv前 1,000,000 行(SHA2560445c02774cf9e340e4b459f3d648936743bee0c8f031d35c8b9d8a1f7d4cfd9),保持table_size=10000000,不能改成 1,000,000;加载后 flush 基表和隐藏二级索引表、等待 logtail 应用并刷新统计信息。使用mo-sysbenchrevision1a7886fc7566dfc9fd85a81801f09471151365d3中的select_random_ranges.lua/oltp_common.lua,以同一个 sysbench C 客户端分别运行 GOODb1b68925d7f6fb32153e788b5285f424222e85ca和修复后的 main9f873692e0efa869c64c4d1c84e212c5a8a3272a:建议 GOOD/fixed 交错运行至少 4 轮(每轮两版本各一次,交替先后顺序),保留每次 QPS/延迟与错误数;同时采集绑定计划、索引扫描的 storage filter/selected blocks、计划构建次数和 CPU profile。只有原始数据和真实 C 客户端的对照结果才能回答性能是否恢复到 GOOD 的波动范围。
本评论只补充已完成的合成数据验证及后续性能复测方案,不给 issue 整体验收结论。
Ariznawlll commentedon Oct 19, 2026
测试版本
mainbeffc64c486d369406a41cdb1447b120bc93cb41原问题验证
复查与本 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_betweenBlock Filter;结果与独立 oracle、IGNORE INDEX控制一致,见前次验证记录。范围说明:129 nightly 的数据规模和线程数不同于 issue 原始的 1M 行、32 线程、本地 GOOD/fixed 对照设置;本次没有重新执行该原始配置的交错基准,因此不能把这些 TPS 数字直接与原始 GOOD 的 14,172 QPS 比值比较,也不宣称逐项完成 issue 中所有扩展验收条件。
Happy Path 覆盖
random_ranges:三次 main 129 回归均完成,TPS 稳定在 1.95–1.98 万,错误数 0。Unhappy Path 覆盖
白盒验证
本次未新增或重跑 UT /
-race;这里引用的是先前的黑盒协议/计划探针与最新 nightly 性能结果,不能据此声称白盒覆盖已补齐。回归测试
现有 129 main Family 的
sysbench_random_ranges_10_10000000用例持续执行并记录性能;最近三次的该用例均通过。最新一次比较器处于 WARMUP 2/5:数据已写入,但自动性能回退门禁尚未启用;此处稳定性判断来自三次实测数据,并非自动门禁结论。本次未修改测试代码。测试证据
random_ranges19,565 TPS,错误数 0。random_ranges用例。测试结论
测试通过。