Skip to content

Explicit prepared DOUBLE casts still disable DECIMAL block pruning #29516

Closed

Description

@XuPeng-SH

Reproduction

On #29508 head e0082f4be0, create a DECIMAL table with 100,000 rows in 13 blocks:

create table t(d decimal(18,2));
insert into t select result from generate_series(1,100000) g;

With a binary prepared float64(54321) binding, select count(*) from t where d=? reads one block (~1.5 ms per execution), but select count(*) from t where d=cast(? as double) reads all 13 (~50 ms per execution). SQL PREPARE with @v=cast(54321 as double) confirms the latter plan has cast(t.d AS DOUBLE) = cast(cast('54321' AS DOUBLE) AS DOUBLE) and no block filter.

The equivalent explicit DOUBLE(M,D) cast also scans all 13 blocks. Both forms return the correct count. Unlike a direct DOUBLE marker, the explicit CAST operand follows prepared text transport, so preserving its exact conversion and rounding behavior is necessary before applying DECIMAL filter pushdown.

Expected

When the evaluated explicit CAST value uniquely maps to one DECIMAL value at the column scale, retain a native DECIMAL scan filter. Preserve current results and fallback for fractional values, malformed text, NULL, nonfinite values, precision rounding, and 2^53 collision cases. Reuse the current optimizer and prepared binding owners.

Activity

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

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:本地全新单 CN mo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE
    • 测试日期:2026-10-02

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。DOUBLE marker 与 DECIMAL key 比较保留 native DECIMAL block filter,目标行与 direct SQL 一致。

    Happy Path 覆盖

    覆盖等值、BETWEEN、IN 及多次浮点重绑。

    Unhappy Path 覆盖

    覆盖 NaN/Inf、NULL、超 scale 和无法精确表示值;不生成不安全 filter。

    白盒验证

    关联修复 #29508 已进入当前 main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:DOUBLE marker 与 DECIMAL key 比较保留 native DECIMAL block filter,目标行与 direct SQL 一致。
    • 回归代码与 golden result 已提交到 MOTR #209;本地全量 14_issue_regression 中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。

    测试结论

    测试通过。

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