Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Related issues are #28397 and #29317, but neither tracks this prepared statement shape: #28397's precision cases are fixed for direct expressions, while #29317 covers all operands being runtime parameters.
Branch Name
codex/fix-prepared-variadic-comparison
Commit ID
2c564748e34294e682dc337b92bbd0b80757d098
Other Environment Information
- Darwin arm64 local CGo test environment.
- Reproduced through the MySQL parser's PREPARE plan,
FillValuesOfParamsInPlanWithSpecialization, and the expression executor. The follow-up used a package-level reproduction, not a fresh standalone SQL service.
Actual Behavior
With a DECIMAL SQL EXECUTE parameter and a fixed DECIMAL candidate, FIELD() rounds both distinct values to the same DOUBLE and returns candidate position 1. The equivalent direct expression returns 0.
At commit 2c564748e342, the focused planner reproduction returned 0 for direct SQL and 1 for the prepared execution. It also reproduces on base 7db5bee77ef4; the mismatch predates PR #29345.
Expected Behavior
The prepared execution should preserve the exact DECIMAL comparison domain and return 0, matching the equivalent direct expression. The all-parameter control also returns 0.
Steps to Reproduce
SELECT FIELD(
CAST(9007199254740993 AS DECIMAL(20,0)),
CAST(9007199254740992 AS DECIMAL(20,0))
);
-- 0
PREPARE p_field_decimal_peer FROM
'SELECT FIELD(?, CAST(9007199254740992 AS DECIMAL(20,0)))';
SET @needle = CAST(9007199254740993 AS DECIMAL(20,0));
EXECUTE p_field_decimal_peer USING @needle;
-- Expected: 0; current prepared-plan reproduction: 1
DEALLOCATE PREPARE p_field_decimal_peer;
PREPARE p_field_decimal_control FROM 'SELECT FIELD(?, ?)';
SET @candidate = CAST(9007199254740992 AS DECIMAL(20,0));
EXECUTE p_field_decimal_control USING @needle, @candidate;
-- 0
DEALLOCATE PREPARE p_field_decimal_control;The package-level reproduction prepares both queries, binds the marker with ParamValue{SourceType: DECIMAL(20,0)}, specializes the copied plan, and evaluates the resulting expression. The fixed candidate in the failing query retains the prepare-time FLOAT64 envelope; the all-parameter control restores both runtime DECIMAL domains.
Additional information
- [Bug]: FIELD loses DECIMAL precision through DOUBLE coercion #28397 established and fixed exact DECIMAL comparison for direct
FIELD()expressions and table columns. Its post-fix verification did not cover a prepared marker beside a fixed DECIMAL peer. - [Bug]: prepared FIELD miscompares mixed DECIMAL and string runtime operands #29317 covers prepared runtime-domain selection when all
FIELD()operands are markers. PR fix: preserve prepared variadic comparison domains #29345 addresses that issue but does not restore a fixed numeric peer forFIELD(). - This reproduction is based on the test path rather than a fresh server session; please confirm through the standalone SQL path when adding the public regression.
Activity
XuPeng-SH commentedon Sep 25, 2026
Follow-up verification: #29379 fixes the bare-marker example, but nested fixed-peer cases remain
Deep review of exact PR head
b85a90231da21c9c561cd3e88f52eab95004f50c: review and reproduction.Confirmed through a real MySQL connection to an embedded CN:
COALESCE(?, CAST(0 AS DECIMAL(20,0))),IF(true, ?, CAST(0 AS DECIMAL(20,0))), and placingABS(?)in the candidate position also retain the same mismatch. Planner inspection shows the nested child is DECIMAL128 but FIELD still compares DOUBLE/DOUBLE because its fixed peer retains the provisional cast.The original bare-marker example now passes, as do additional exactness/explicit-cast/error-reuse controls. The four nested failures above also reproduce with the PR's two changed production files restored to base
ce7f84dabc563fa5bb29c648e8b02aa6581b608b; they are remaining coverage of the original precision problem, not a new regression. Please preserve this remaining scope when deciding whether this issue can be closed, or explicitly move it to a linked follow-up.Related protocol gap, beyond the original SQL EXECUTE user-variable reproduction: COM_STMT_PREPARE/EXECUTE of
SELECT FIELD(?, CAST(9007199254740992 AS DECIMAL(20,0)))with Gouint64(9007199254740993)also returns 1 instead of 0 on both base and PR head. The current SQL-source restoration excludes binary-protocol parameters. This also needs tracking if prepared FIELD precision is claimed across both protocols.Local evidence:
/home/xupeng/mo-validation/pr29379-review-b85a/; 19 public SQL scenarios, 14 passing and the 5 cases above failing on PR head. Exact-head SCA and existing BVT pass but do not include these counterexamples.XuPeng-SH commentedon Sep 25, 2026
Follow-up to my earlier review comment: PR #29379 has been rebased and updated at
90bde35db972e34f6fda74febdca3a52f3711f55. The nested ABS/COALESCE/IF fixed-peer precision failures and the typed numeric COM_STMT gap are fixed, including reverse operand order and prepared statement reuse. Independent public SQL counterexamples now pass 19/19 (old head: 14/19); planner package, focused embedded SQL test, and prepared BVT 48/48 twice pass. The fullpkg/tests/issuespackage is not verified: a 20-minute overall timeout fired during an unrelated test; a longer rerun was stopped to avoid delaying delivery. This remains visible in the PR validation section. The prior comment documents the old head; these gaps are no longer known outstanding scope for #29378.fix(plan): preserve prepared source domains across FIELD and relation…
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交
50c15c1fd461fc3cd320d047b95ff3316170d468。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
确认修复提交
50c15c1fd461fc3cd320d047b95ff3316170d468是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。回归测试
已加入 MOTR PR #204 的
issue_29317_29318_29378_prepared_comparison.test,MOTR 提交2b4462f2;本地基线比对连续 3 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。