Skip to content

[Bug]: EWM rejects numeric prepared parameters nested in IFNULL or CASE #31952

Closed

Description

@Ariznawlll

Description

EWM window functions reject a prepared statement when the numeric decay marker is nested inside a row-independent IFNULL or CASE expression. The statement fails during preparation, before any numeric value can be bound. This prevents clients from using otherwise constant-per-execution expressions as the decay configuration.

Environment

  • Official main: ae40f12a647880a63466de32a9f507c2c72dca0b.
  • Isolated local MatrixOne, 1 CN / 1 TN / 1 LogService; Linux/amd64 under Docker emulation.

Steps to reproduce

PREPARE ew FROM 'SELECT ewmmean(CAST(result AS DOUBLE), IFNULL(?, 0.5), FALSE) OVER (ORDER BY result) FROM generate_series(1, 4) g';

The analogous CASE WHEN ? > 0 THEN ? ELSE 0.5 END decay expression also reproduces. SQL PREPARE and a MySQL binary-protocol prepared cursor both reproduce.

Actual behavior

Preparation rejects the expression with error 20203: invalid argument function ewmmean, bad value [DOUBLE VARCHAR BOOL]. No result is returned.

Expected behavior

The row-independent numeric expression with a numeric parameter should be accepted as an execution-time decay configuration. With the parameter bound to 0.5, the result should be 1, 1.5, 2.25, 3.125. This follows #29945 / #31941's acceptance of prepared markers and row-independent CASE/IFNULL configuration expressions; it does not assume full pandas or MySQL EWM-function compatibility.

Stability and controls

  • IFNULL and CASE forms: each reproduced 3/3 via SQL PREPARE and 3/3 via binary protocol.
  • IFNULL(CAST(? AS DOUBLE), 0.5) and a direct numeric marker prepare and produce the expected four values 3/3. A marker inside a CASE condition whose result branches are numeric literals also works.
  • After a rejected preparation, SELECT 1 succeeds. The query is read-only; no table state is changed.

Evidence

  • Exact-main build: https://github.com/Ariznawlll/matrixone/actions/runs/41212242785 (workflow branch 2cfb30778fcca6a6c51dd0599cb4f132b96ea932 checks out official MatrixOne commit ae40f12a647880a63466de32a9f507c2c72dca0b; the workflow builds the binary, and the SQL/protocol checks were run locally against that binary).
  • Local evidence: evidence/qa29945-20261031/qa29945-main-family.json, qa29945-main-nested.json, qa29945-main-prepdiag.json. All five EWM functions rejected the IFNULL marker 3/3; explicit numeric casts returned four rows 3/3 for each function.
  • In a separate MySQL 8.0.46 control, the conditional expressions with numeric parameters can be prepared and evaluated; this checks the expressions only, since MySQL does not implement these EWM names.

Code analysis

Hypothesis: at preparation the nested conditional is typed as VARCHAR and the EWM function overload rejects it before the row-independent expression can be resolved. This is an inference from the reported argument types; the precise owner requires investigation. The design's intended behavior is described in pkg/sql/plan/window_binder.go and #31941's review-22 description.

Regression coverage

After the fix, cover both text and binary prepared protocols, IFNULL and CASE markers, repeated numeric values and NULL, invalid decay followed by recovery, and explicit-CAST/direct-marker controls. The user's current regression preference is MOTR or big-data rather than new MatrixOne BVT.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 31, 2026
  2. added
    kind/bug
    on Oct 31, 2026
  3. added theissue type on Oct 31, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Nov 5, 2026
  5. gouhongshen commented on Nov 9, 2026

    @gouhongshen
    Contributor

    PR #32435 is trying to fix this issue.

  6. gouhongshen commented on Nov 9, 2026

    @gouhongshen
    Contributor

    PR #32435 has merged and is awaiting manual validation. The issue remains open.

  7. XuPeng-SH commented on Nov 9, 2026

    @XuPeng-SH
    Contributor

    QA 交接:修复 PR #32435 已于 2026-11-09 23:07 UTC 合入 main,merge SHA b743219dd2a0a69ddb41760f81548234c2cbc083,评审 head 8933e26feb9bd2b539cf0b120ab8bedd084bd2db。本项是 EWM prepared IFNULL/CASE 数值 decay 的产品行为修复,不是 CI flaky。

    现有验证证据:PR 作者记录了原错误的 red/green 回归、plan/function/compile 三个所属包测试及 EWM BVT 377/377 两次。该 head 的评审报告(https://github.com/matrixorigin/matrixone/pull/32435#pullrequestreview-5833394258)另记录五个 EWM 函数的文本与二进制 prepared 协议、参数变化、NULL fallback、无效值后恢复和 boolean-domain 控制通过。以上均为作者/评审报告;本次交接仅核对远端状态与讨论,未运行本地测试,也不表示合并 SHA 已通过 QA 验收。

    未测范围与边界:评审 BVT 为 embedded single-CN 且排除 metadata comparison;两个既有 planner 子测试跳过,MOTR/big-data 和独立分布式验证未运行。请在合并版本上重点复核 IFNULL/CASE 的文本及二进制协议、重复 EXECUTE 的数值与 NULL、无效 decay 后恢复,以及显式 CAST/直接 marker 对照,优先补充 MOTR 或 big-data 覆盖。row-dependent decay/policy、非 halflife decay 文本、boolean half-life 和显式窗口 frame 仍按设计拒绝,不视为本次承诺支持。

    已读取 issue 全部评论及修复说明,未见适用于新修复的已验证反例或未完成开发 follow-up;转交 Ariznawlll 验证,issue 保持开放。

  8. Ariznawlll commented on Nov 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 官方 main@4760bcaa88b23fabe064b1631b624c0e8c40d549,包含修复 #32435。隔离 CI 为 1 LogService / 1 TN / 2 CN,两个 CN 的 git_version() 与完整 SHA 一致。
    • 本地双 CN 扩展与标准 BVT 使用 main@c8accd138bb91144050ff173100afd7a71a02888。修复仅合入 main,不把本次结果表述为 4.2-dev 验收。

    原问题验证

    IFNULL(?,0.5) 和 CASE WHEN ? > 0 THEN ? ELSE 0.5 END 可在 SQL PREPARE 和 MySQL 二进制 prepared 协议中准备并执行;ewmmean 绑定 0.5 时返回预期序列 1、1.5、2.25、3.125,不再出现原 20203 准备错误。

    Happy Path

    覆盖 ewmmean、ewmvar、ewmstd、ewmcov、ewmcorr 五个函数,重复绑定 0.5、0.25 和 NULL 回退;双 CN 各 3 轮共 246/246 项扩展检查通过,并与相同函数的直接数值调用结果对照。

    Unhappy Path

    无效 alpha 在文本和二进制协议下均按预期拒绝;随后重新绑定有效值,两种协议均可在同一 prepared statement 上恢复。主库完整 EWM BVT 同时覆盖不支持的行相关配置、显式窗口 frame 和其他无效参数控制。

    白盒验证

    核对条件表达式中 prepared marker 的数值类型解析与 EWM 参数绑定;未将行相关 decay 或未承诺支持的配置表述为新增能力。

    回归测试

    官方 mo-tester 完整比较行值及元数据,主库 ewm_statistics.sql 在两个 CN 各 3 轮均 377/377、0 跳过。文本与二进制协议回归已提交 MOTR PR #329,PR 尚待合入。

    测试证据

    最新 main 双 CN CI run 43158932197 包含本单 prepared 协议回归,目标集合在两个 CN 各 3 轮分别 30/30 case、1335/1335 语句通过,run 整体成功。

    测试结论

    测试通过。原 IFNULL/CASE 数值参数准备失败未复现;数值变化、NULL 回退和无效参数后恢复符合预期。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions