Repository navigation
Description
Is there an existing issue for the same bug?
I searched open/closed MatrixOne issues and pull requests for prepared DECIMAL with COALESCE/GREATEST/LEAST, precision loss, NULL rebinding, strToFloat, and the observed index-out-of-range panic. No exact duplicate was found.
Related but distinct:
- [Bug]: DECIMAL <=> prepared parameter loses precision through DOUBLE cast #26847 and PR fix prepared DECIMAL comparison coercion #26849 cover direct binary comparisons such as
DECIMAL <=> ?. The direct comparison is now fixed on currentmain; this report concerns common-type inference inside COALESCE/GREATEST/LEAST. - [Performance]: untyped NULL prepared parameter formats every DECIMAL row #26845 is a performance report for a direct NULL-safe comparison. It does not contain wrong results or the NULL-rebind panic below.
Branch Name
main
Commit ID
23bf597e6bcaccb6cc8331bd9f6478ca77c2b59e
Other Environment Information
- Local
mo-service, 2 CN / 1 TN / 1 Log service / Proxy - Reproduced through both SQL PREPARE/EXECUTE and go-sql-driver/mysql binary protocol
- MySQL 8.3.0 was run locally as the behavior oracle
- Non-partitioned table; no distributed transaction
Actual Behavior
Prepared string parameters combined with DECIMAL128 columns inside COALESCE, GREATEST, and LEAST are coerced through DOUBLE. Distinct values above 2^53 become equal and queries silently return extra rows.
For parameter 9007199254740992.0000000002:
expression MatrixOne raw explicit DECIMAL cast / MySQL 8.3
COALESCE(?,d)=d 1,2,3 2
GREATEST(d,?)=d 1,2,3,4 2,3,4
LEAST(d,?)=d 1,2,3 1,2
NULLIF(d,?) IS NULL 2 2
There is also a deterministic reuse panic. A fresh statement executed with NULL first works. But after the same prepared COALESCE statement has executed once with a non-NULL string, rebinding it to NULL over two or more input rows fails with:
internal error: panic runtime error: index out of range [1] with length 1
... vector.(*FunctionResult[...]).Append
... function.strToFloat
... function.strTypeToOthers
... function.newCast
The sequence value -> NULL -> value -> NULL produces wrong rows -> panic -> wrong rows -> panic in every run. One input row does not panic; two and four rows reproduce 3/3. The server remains available and the statement can execute a non-NULL value after the error.
MySQL 8.3 returns exact results for all function cases and returns all rows for the NULL COALESCE execution without an error.
Expected Behavior
When a prepared parameter shares a common type with a DECIMAL operand in these functions, it must retain exact DECIMAL semantics. Parameterized and explicitly cast forms must return the same rows. Rebinding any prepared parameter from non-NULL to NULL must never panic.
Steps to Reproduce
DROP DATABASE IF EXISTS prepared_decimal_function_repro;
CREATE DATABASE prepared_decimal_function_repro;
USE prepared_decimal_function_repro;
CREATE TABLE t(id INT PRIMARY KEY, d DECIMAL(38,10));
INSERT INTO t VALUES
(1,9007199254740992.0000000001),
(2,9007199254740992.0000000002),
(3,9007199254740992.0000000003),
(4,9007199254740993.0000000001);
PREPARE pc FROM
'SELECT id FROM t WHERE COALESCE(?,d)=d ORDER BY id';
SET @p='9007199254740992.0000000002';
EXECUTE pc USING @p;
-- Wrong: 1,2,3. Expected: 2.
SET @p=NULL;
EXECUTE pc USING @p;
-- Panic. Expected: 1,2,3,4.
SET @p='9007199254740992.0000000002';
EXECUTE pc USING @p;
-- Statement recovers, but still returns wrong 1,2,3.
SET @p=NULL;
EXECUTE pc USING @p;
-- Panics again.
-- Explicit typing is correct.
PREPARE pc_typed FROM
'SELECT id FROM t
WHERE COALESCE(CAST(? AS DECIMAL(38,10)),d)=d
ORDER BY id';
SET @p='9007199254740992.0000000002';
EXECUTE pc_typed USING @p;
-- 2
PREPARE pg FROM
'SELECT id FROM t WHERE GREATEST(d,?)=d ORDER BY id';
EXECUTE pg USING @p;
-- Wrong: 1,2,3,4. Expected: 2,3,4.
PREPARE pl FROM
'SELECT id FROM t WHERE LEAST(d,?)=d ORDER BY id';
EXECUTE pl USING @p;
-- Wrong: 1,2,3. Expected: 1,2.Additional Information
PR #26849 added normalizeDecimalParamComparisonArgs, but intentionally invokes it only for direct comparison operators. The function overloads here still choose DOUBLE as the common type for the prepared TEXT transport and DECIMAL operand. That explains the precision collapse and sends COALESCE through strToFloat; after a non-NULL execution, NULL rebinding exposes a result-vector cardinality mismatch in that cast path.
Please retain:
- SQL and binary prepared protocols;
- DECIMAL64 and DECIMAL128 values around 2^53;
- explicit-cast and MySQL controls;
- NULL-first and value-to-NULL reuse;
- one-row and multi-row batches;
- recovery after the panic.
Activity
ck89119 commentedon Aug 28, 2026
Verified on the latest
main(e5f26b66195373f9bff512ac9f428788d1c07e8c). This issue is no longer reproducible after #27483 (3bb6b15c93).I ran the prepared-protocol regression test on the latest main:
The passing coverage includes exact DECIMAL behavior above 2^53, common-value-function handling, both COM_STMT and SQL PREPARE/EXECUTE paths, and non-NULL-to-NULL prepared parameter reuse without a panic.
Ariznawlll commentedon Aug 28, 2026
最新 main SQL PREPARE 复测 3/3:COALESCE、GREATEST、LEAST 的高精度 DECIMAL 正确;value→NULL→value 重绑无 panic;非法文本后重绑也可恢复。稳定 SQL 回归已加入 https://github.com/matrixorigin/motr/pull/131,并行三轮通过。二进制协议维度保留现有 Go 回归覆盖。无需 big-data、PITR/snapshot、stability 或 chaos。结论:关闭。
Ariznawlll commentedon Aug 28, 2026
更正补充:验证基线为 MatrixOne main 28769ff。稳定 SQL 回归已在 https://github.com/matrixorigin/motr/pull/131,连续并行三轮通过。
LeftHandCold commentedon Sep 26, 2026
Main 再次观察到 GREATEST/LEAST Prepared DECIMAL 错行(2026-09-26)
核查了两轮真实 MOTR Artifact、构建 receipt、固定测试 revision、原始 SQL/golden/diff,以及本 Issue 的关闭验收。结论:本 Issue 中 GREATEST/LEAST 两个子场景再次出现相同错行,属于高可信的回归信号;不是单凭 Job failure 或 Case 名称归类。建议重新检查本 Issue 的关闭状态,不另建重复 Issue。
1. Case 级 pass → fail
7ce783464806490263c184f22aaf5d307225adef71c415705c909e524abd21dd0cf3e31b1c18e941success; stmts=20 ok=20 fail=0failed; stmts=20 ok=20 fail=0两轮共同条件:
152893c2e851e45db1ef2146060ba1afa7f123e9。b0c9132c69be598e0e799739105bdd4d1e56b9a3。motr-weekly-shadow-1x2,Job 为TKE TP/AP Family (1TP+2AP Weekly Full) / weekly-shadow-1x2 / TP Tail / MOTR regression。sha256:6fe3577efe0e38d9df214190d31ac172614244ef3377d34123d5e5561ecf0284。suites/14_issue_regression/t/issue_26879_prepared_decimal_functions.test。suites/14_issue_regression/r/issue_26879_prepared_decimal_functions.result。注意:两个 Job 整体都因多项用例失败而为 failure;这里的 pass→fail 仅指该 Case。 后一轮 20 条 SQL 均执行完毕,但输出比较失败,所以
ok=20不能解释为正确性通过。2. 原始结果证据
后一轮 Artifact
tke-family-weekly-shadow-1x2-motr-36152217640-1中,failures.txt的14_issue_regression.issue_26879_prepared_decimal_functions节包含完整 SQL、Expected、Actual 和 diff;两轮summary_parallel.txt分别记录该 Case 的通过/失败。GREATEST(d,?)=d2,3,41,2,3,4LEAST(d,?)=d1,21,2,3差异是整数主键行集合增加,不是 DECIMAL 显示格式或排序差异。两个查询均有
ORDER BY id。本轮COALESCE(?,d)=d的 value→NULL→value→NULL 四次执行仍符合 Golden,不能把本次描述为原 Issue 全部症状复发,也没有证据宣称 NULL 重绑 panic 再现。最小复现(在独立测试 database 中执行):
这里是 已定型 DECIMAL 列 + prepared marker,不是把 SQL 字符串字面量简单代入函数。MySQL 的 PREPARE 类型规则区分推导类型与执行时参数类型;字符串参数通常按推导类型隐式转换。MySQL 8.0.36 的 min/max 类型解析也先从非参数操作数推导参数类型。这是独立的文档/源码依据,不冒充本轮 MySQL 实测。
3. 为什么补在本 Issue,而不是 #29318 或新建
4. 根因候选与未完成的验证
两个被测 SHA 的比较为单向前进 9 个提交。
#29345(
426cf10b000b6a828e8c69f1af26082f26036ed3)位于该区间。其 variadicSource 分支和 runtime source 重建会在 GREATEST/LEAST 上重新引入 SQL user variable 的 source type;这与本次 typed DECIMAL 参数路径高度相关,值得优先核查。这仍是源码支持的调查方向,不是已经证明 #29345 为引入者。 本轮没有完成该 PR 前后同环境 A/B,也没有在审查时最新 Main
3f0a68bd8034d37e098765920f328985c308c9ff上重新运行。因此确认范围限定为上述真实 CI subject,不宣称当前 HEAD 必然仍失败,也不外推到二进制 prepared 协议或 4.2。建议下一步只复跑这个四行 Case:对比 #29345 parent
fdfbea4fb7125d538d8675d725ace17811760023、merge426cf10b000b6a828e8c69f1af26082f26036ed3和最新 Main;补充函数返回类型/计划及显式 DECIMAL CAST 对照。修复时同时保留 COALESCE/NULL 重绑和 #29318 all-parameter mixed-domain 对照,避免修复一端再次破坏另一端。无需重跑整套 TKE/Weekly。XuPeng-SH commentedon Sep 28, 2026
Independent QA found two additional prepared common-value gaps on clean
mainb9013dc6bb058ec74935a62ac3a35f57d13c2f98(local 1 CN / 1 TN / 1 Log service), using MySQL 8.0.44 as a SQL oracle. Both are also present in the local #29428 worktree; they are not introduced by that PR. #29428 fixes the original #29389GREATEST(d,?)/LEAST(d,?)regression and some typed/nested peers, but does not claim these extended cases are solved.Reproducer (run in a scratch database):
Changing
@ptoNULLor a numeric-prefix string also reproduces the untyped-NULL cast error.GREATEST(d,COALESCE(?,?))andGREATEST(?,IFNULL(?,d))show that the outer DECIMAL peer is not propagated through an inner result whose arguments are unresolved markers. The NULL forms have an additional type/order boundary; a local attempt to special-case literal NULL did not fix public SQL and was discarded. They need a common-type/provenance design, with direct SQL string and actual FLOAT controls, rather than another result-specific cast.This extends the still-open prepared common-value issue. It is separate from #29318's resolved all-parameter mixed-domain case. Please retain these exact SQL and MySQL row expectations as acceptance cases for the follow-up fix.
XuPeng-SH commentedon Sep 28, 2026
Independent QA found another prepared NULL rebinding case on clean
mainb9013dc6bb058ec74935a62ac3a35f57d13c2f98. The same result occurs on PR #29428's candidate build; the PR did not introduce it. This belongs to the still-open NULL/common-value follow-up here.This fails on the first execution with NULL, so it does not depend on a prior cached non-NULL plan. Wrapping the inner expression in
GREATEST(?,ABS(COALESCE(?,d)))orCOALESCE(?,ABS(COALESCE(?,d)))reproduces the same error;GREATEST(?,COALESCE(?,d)+0)does not. The failure is already present in the singleABS(COALESCE(?,d))child, which separates it from #29428's fixed outer DECIMAL precision path. The exact prepare-time cast/binder fault still needs investigation. A future fix should test fresh NULL, value→NULL reuse, direct-literal control, and DECIMAL values above 2^53.fix(plan): preserve prepared DECIMAL precision in common-value functi…
fix: preserve nested prepared common-value domains (#29528)
Ariznawlll commentedon Oct 8, 2026
测试版本
MatrixOne 最新 main
1a0088790c8823bd3fe824ad9ff2ef1ce130eb31;本地独立数据目录、单 CN/TN 服务;MOTR PR #218 已推送,Python 3.10/3.12/3.13 与 Go 离线检查均通过。原问题验证
原 DECIMAL(38,10) 高精度参数在 COALESCE/GREATEST/LEAST 不再误匹配;非 NULL→NULL 重绑不再 panic。
正常场景覆盖
四行 >2^53 数据中,原 COALESCE 只返回 id=2,GREATEST 返回 2/3/4,LEAST 返回 1/2;嵌套 GREATEST/IFNULL 与 ABS(COALESCE) 结果符合预期。
边界与异常场景覆盖
对同一 prepared 语句执行值→NULL→值→NULL;新补的非定型 NULL、CAST(NULL AS DECIMAL) 与嵌套函数路径均稳定,源表仍 4 行。
白盒验证
现有
pkg/sql/plan/issue_26879_common_value_test.go覆盖参数类型推断;本轮补真实服务 SQL/多行扫描。回归测试
扩充 MOTR
14_issue_regression.issue_26879_prepared_decimal_functions,3/3 通过(48 条语句/轮)。测试证据
MOTR PR #218 的原路径、补充评论路径与 golden;已含 p2–p5 和 NULL 首次执行。
测试结论
测试通过。