Skip to content

[Performance]: Prepared ROUND numeric text can disable BIGINT filter pushdown #29512

Closed

Description

@XuPeng-SH

Performance gap in newly supported prepared numeric text

With #29508, ROUND(?,0) correctly accepts complete fractional/scientific numeric text and returns the expected value. When that result is compared with a selective signed BIGINT key, the planner may cast the key column to DECIMAL128 and lose native block filtering. A text spelling difference that leaves the rounded value unchanged can therefore produce a large latency jump.

Reproduction

On a 100,000-row table with id BIGINT PRIMARY KEY, current #29508 candidate:

PREPARE p FROM 'SELECT COUNT(*) FROM t WHERE id=ROUND(?,0)';
SET @v='54321';   EXPLAIN FORCE EXECUTE p USING @v;
-- cast(id AS DOUBLE) comparison, with a block-filter expression
SET @v='54321.0'; EXPLAIN FORCE EXECUTE p USING @v;
-- cast(id AS DECIMAL128(38,0)) comparison, no Block Filter Cond
SET @v='5.4321e4'; EXPLAIN FORCE EXECUTE p USING @v;
-- same loss of native filtering

100 sequential executions per spelling, one connection/case, same service: '54321' ~0.57 ms/execute; '54321.0' ~9.15 ms; '5.4321e4' ~8.5 ms. All returned the same count of 1. Direct id=ROUND(54321.0,0) also casts the BIGINT column to DECIMAL128, showing that the comparison coercion/optimizer is a shared owner, while #29508 makes this runtime domain reachable from a prepared text parameter.

Correctness constraints

Do not force a BIGINT result overload or cast the rounded result to BIGINT for arbitrary values: fractions, negative precision, overflow, signedness and values near 2^53 / INT64 boundaries can change results. Prove a safe domain per binding, preserve ROUND/TRUNCATE result semantics and cache invalidation, then assert both rows and scan plans. Include TRUNCATE, scalar/derived parameter expressions, casts, binary protocol and a safe-value control.

Related: #29505/#29508, #29506, #29511.

Activity

  1. XuPeng-SH commented on Sep 29, 2026

    @XuPeng-SH
    ContributorAuthor

    Follow-up confirms TRUNCATE has the same behavior on the same service/table (100 sequential EXECUTEs each): '54321' ~0.74 ms/execute, '54321.0' ~7.96 ms, and '5.4321e4' ~8.58 ms. Repeated ROUND controls were ~0.61, 8.13, and 8.20 ms respectively. All returned the same count. This is a value-spelling-dependent loss of effective pruning for both functions, not just ROUND.

  2. self-assigned this
    on Sep 29, 2026
  3. added
    severity/s0
    on Sep 29, 2026
  4. added a commit that references this issue on Sep 30, 2026
    3d22228
  5. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:d59cc02ef6ca68f340c9570e56f7eb71d90e42e7
    • 部署方式:本地单机 one-CN,默认配置
    • 测试日期:2026-10-02

    原问题验证

    构造 100000 行 BIGINT 数据,验证 prepared id = ROUND(?,0) 与 id = TRUNCATE(?,0)。

    • 整数文本、带 .0 的完整数值文本、科学计数法绑定均返回正确结果
    • 安全绑定恢复 BIGINT 原生 block filter,实际扫描 1 block / 1 row
    • 未复现原问题中同值不同文本格式导致的 8–9 ms 全扫描路径

    正常路径覆盖

    对 integer text、fractional spelling、scientific notation 等安全值分别执行 30 次,ROUND/TRUNCATE 均保持选择性过滤,平均约 0.209–0.258 ms。

    同时覆盖 direct、scalar subquery、derived table / CTE 参数传递形态,结果与计划一致。

    边界与保守路径覆盖

    1. 12345.5 按 ROUND/TRUNCATE 各自语义返回正确行,不因优化改变函数结果。
    2. NULL 返回 0 行。
    3. precision 在 0 / -1 / NULL / 0 间复用,计划和值均未出现陈旧状态。
    4. 覆盖显式 CAST、超大整数和 2^53 附近值,不能证明安全时保留原比较路径。

    白盒与 BVT 验证

    MatrixOne 现有用例 test/distributed/cases/prepare/issue_29512_round_filter_pushdown.sql 连续执行 3 轮均通过。

    回归测试

    已加入 MOTR PR #209,commit 3b4d80060724d3f19c672d9f039c5df951d63c81,用例:
    suites/14_issue_regression/t/issue_29507_29510_29511_29512_filter_pruning.test

    • 新用例本地连续 10 轮:640/640 statements 通过
    • 完整 14_issue_regression 并发套件中该新增用例通过
    • 离线契约 CI 的 Python 3.10 / 3.12 / 3.13 jobs 全部通过

    本问题是 prepared 参数域与过滤器生成问题,安全值、函数语义、NULL、precision 复用和保守路径都可由确定性 SQL/计划断言覆盖,不依赖数据规模阈值,因此不另加 big-data。

    测试结论

    最新 main 中,ROUND/TRUNCATE 的安全数值文本和科学计数法绑定已恢复 BIGINT 原生过滤;边界输入仍保持原函数与比较语义,回归已补充。

    测试通过。

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

Metadata

Metadata

Assignees

Labels

severity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions