Repository navigation
Description
Description
In strict SQL mode, assigning an integer to a DECIMAL(p,s) column can bypass the declared precision check. MatrixOne accepts 2 into DECIMAL(2,2) and persists 2.00, although the positive maximum for that type is 0.99. The equivalent decimal or string representation is correctly rejected. The same gap appears while copying existing integer rows through ALTER TABLE ... ALGORITHM=COPY.
Environment
- Branch:
main - Commit:
48dbe277b6d20216c1c513d03c5cbd681380a8a2 - Deployment: isolated local MatrixOne 1 LogService / 1 TN / 2 CN (
127.0.0.1:16041and:16042);git_version()=48dbe277b6,version()=8.0.30-MatrixOne-v1.3.0 - SQL mode:
STRICT_TRANS_TABLESenabled - Comparator: isolated MySQL 8.0.45 with
STRICT_TRANS_TABLESenabled - Date: 2026-10-16
Steps to reproduce
CREATE DATABASE decimal_integer_assignment_repro;
USE decimal_integer_assignment_repro;
CREATE TABLE t(id INT PRIMARY KEY, v DECIMAL(2,2));
INSERT INTO t VALUES (1, 0.99); -- valid boundary
INSERT INTO t VALUES (2, 2); -- outside DECIMAL(2,2)
SELECT id, v FROM t ORDER BY id;Actual behavior
MatrixOne accepts the second INSERT and returns:
id v
1 0.99
2 2.00
It also accepts INSERT ... VALUES(10) into DECIMAL(3,2) and stores 10.00 (valid maximum is 9.99). A separate table copied from an INT source via ALTER TABLE ... ALGORITHM=COPY, MODIFY COLUMN rawv DECIMAL(2,2) likewise retained existing 2.00, 3.00, and 4.00 in the narrowed column.
Expected behavior
Strict assignment should reject the out-of-range integer and leave the table unchanged. MySQL 8.0.45 returns ERROR 1264 (22003): Out of range value for column 'v' at row 1 for the same INSERT and ALTER TABLE narrowing.
Stability and controls
- MatrixOne: 3/3 independently created databases across both CNs accepted the integer
2intoDECIMAL(2,2)and read it back as2.00from a fresh connection on the other CN. - MySQL 8.0.45: 3/3 independent databases rejected the integer
2with 1264 and retained only the valid0.99row. - MatrixOne correctly accepted valid
0.99and-0.99boundaries; a valid INSERT after the failed string control worked, so the connection remained usable. - MatrixOne rejected
INSERT ... VALUES('2.00')with20301: 2.00 beyond the range, can't be converted to Decimal64(2,2)in each database, left no row for that rejected statement, and also rejected numeric decimal literal1.00. This isolates an integer-source conversion gap, not a missing decimal range rule generally. - On a cloned table with a stored generated column, UNIQUE key and CHECK, COPY ALTER from INT/BIGINT to
DECIMAL(2,2)also succeeded and retained out-of-range rows. An independent duplicate-key UPDATE returned 1062, and an invalid CHECK INSERT returned 3819; source table and nonviolating rows remained unchanged.
Evidence
Exact SQL outputs, versions, comparison results and plan observations are in /private/tmp/mo-explore-run-20261016/checkpoint.md on the isolated local test host.
Code analysis
pkg/sql/plan/function/func_cast.go:4022-4042 (signedToDecimal64) scales the integer into the Decimal64 physical carrier and appends it without checking to.GetType().Width; it also discards the Scale error. The unsigned and wider-decimal integer conversions nearby follow a similar shape. By contrast, decimal/string paths call precision-aware parsing. This is a code-level hypothesis for the observed source-dependent difference; the issue does not claim that CLONE itself corrupts rows.
Existing TestCast and TestCastNumericToDecimal256Dispatcher Go UTs passed on this commit but do not assert the narrow target-precision boundary; they do not invalidate the SQL repro.
Regression coverage
After a fix, add a focused cast/assignment UT plus public SQL regression for integer literal, prepared integer, and INT-column COPY ALTER into DECIMAL(2,2) and DECIMAL(3,2), with strict error, unchanged rows/schema on failure, valid boundary and same-scale string/decimal controls. No repository tests or PR were added during this exploration.
Related
- [Bug]: recursive CTE bypasses DECIMAL precision and stores out-of-range values #29137 (closed) covered recursive CTE DECIMAL overflow; its direct DECIMAL-literal INSERT control correctly rejected overflow and did not cover integer-source assignment.
- [Bug]: LOAD DATA parquet same-scale DECIMAL path bypasses target precision validation #26265 (closed) covered the Parquet raw decoding path, not SQL integer casts.
- [Bug]: DML assignment casts must honor bounds and SQL-mode adjustment semantics #27340 covers non-strict and IGNORE handling of rejected numeric assignments; this issue is invalid value acceptance in strict mode.
Activity
Ariznawlll commentedon Oct 16, 2026
补充同一问题的执行路径边界(固定
maincommit48dbe277b6d20216c1c513d03c5cbd681380a8a2,隔离双 CN;MySQL 8.0.45 对照;两端均启用STRICT_TRANS_TABLES):SQL PREPARE/EXECUTE 也会写入越界整数。 在三个独立库各建
t(id INT PRIMARY KEY, v DECIMAL(2,2)),执行:MO 在两个 CN 上均成功写入
(5,5.00)(3/3);MySQL 均报1264 / 22003: Out of range value for column 'v' at row 1(3/3),且没有写入 id=5。同一 prepared statement 的输入类型切换与错误恢复。 在 MO 的同一连接中,把
@v改成字符串'2.00'后EXECUTE报20301: 2.00 beyond the range, can't be converted to Decimal64(2,2),表未增加该行;再改成-0.99后复用同一ins成功写入(4,-0.99)。MySQL 对整数2和字符串'2.00'均拒绝,随后复用该语句写入-0.99成功。这说明连接和 prepared statement 在错误后可用,缺口集中在整数值到目标 DECIMAL 精度的转换。相关控制。
CAST(6 AS UNSIGNED)写入DECIMAL(2,2)时,MO 也接受并保存6.00,MySQL 报 1264(当前该变体仅执行 1 轮)。相反,原列已是DECIMAL(3,2)且值为2.00时,ALTER TABLE ... ALGORITHM=COPY, MODIFY COLUMN v DECIMAL(2,2)在 MO 与 MySQL 均被拒绝;MO 错误后仍保留原DECIMAL(3,2)定义及原行,随后可继续正常写入。先前 issue 正文中的 INT/BIGINT 来源 COPY ALTER 却可成功保留2.00等越界值,进一步指向整数来源的 cast 路径,而不是所有 COPY ALTER 都跳过检查。白盒对应
pkg/sql/plan/function/func_cast.go的signedToDecimal64/unsignedToDecimal64:当前按目标 scale 写入物理 Decimal64,但未使用目标 width 验证精度。这里是代码与现象一致的定位线索,不是声称所有 DECIMAL 转换路径均有此问题。本轮没有增加仓库用例或 PR。fix(sql): enforce DECIMAL width for integer assignments (matrixorigin…
fix(sql): keep out-of-domain integer constants outside DECIMAL compar…
XuPeng-SH commentedon Oct 22, 2026
PR #30639 review update (head
7134ffe6d66c9a9e6d7d4f3459e95a357e760055)XuPeng-SH submitted a current-head
CHANGES_REQUESTEDreview on 2026-10-22 identifying an unresolved compatibility case inpkg/sql/plan/catalog_decimal_compat.go: persisted generated-column expressions using four-argumentIN_RANGEare not included in the legacy implicit-decimal migration. The review reports that a base-authored stored expression overBIGINTandTIME(0)remainsDecimal64(18,0)after upgrade; writing10^18-1succeeds, while10^18fails the new width check, although fresh head binding widens toDecimal128(19,0). It requests migrating thisIN_RANGEform and adding an old-catalog/new-reader regression.This is reviewer-provided parser/planner/catalog/executor evidence, not an execution I performed in this run. The report notes frozen CI statuses pass but does not provide raw CI logs; the persisted-expression compatibility case remains open. No duplicate issue opened. Issue remains open and assigned to daviszhen pending a fix and validation.
XuPeng-SH commentedon Oct 22, 2026
PR #30639 current-head performance findings (head
a1027b586d37b067ab0b67e0187de8fe28503c0e)The latest review reports two P2 performance regressions in the fix path. These numbers are from the reviewer’s benchmark report; I have not rerun those benchmarks in this QA run.
Unchanged table-resolution allocations —
pkg/sql/plan/catalog_decimal_compat.go:61-65copies each non-nil column (owned := *col) before knowing whether any legacy DECIMAL expression changed. The review reports 100-column resolution rising from 2 allocations / 1,344 bytes to 102 / 36,544 bytes, and NULL-default resolution from 102 to 202 allocations (+35,200 bytes). Consider cloning the column only after a default, on-update, or generated expression actually changes.Per-row DECIMAL256 bound construction —
pkg/sql/plan/function/func_cast.go:4080-4099reconstructs the width bound with repeated wide multiplications insidecheckIntDecimal256Width; integer-to-DECIMAL vector conversion invokes this validation for each row. The review reports 4,096-row serial median latency of 14.29→95.80 μs for DECIMAL256 and 14.54→30.13 μs for DECIMAL128. Consider computing the invariant bound once per vector/batch or precomputing it, while preserving strict-width boundary tests.Please retain both findings in the fix/verification scope for #30367. Static inspection here confirms the eager column copy and repeated bound construction at the cited exact-head locations; no runtime benchmark or MatrixOne integration test was run in this environment.
Current-head verification checkpoint (2026-10-22)
PR #30639 is now at exact head
78c61bd8309c613c616cd59d72592064beed538e. Its current-head APPROVED review states that the earlier correctness, persisted-catalog compatibility, and performance findings are addressed; it reports eight targeted test roots run three times, with retained artifacts/receipts reconciled. This is reviewer-reported evidence, not a test run by this QA automation. The review also notes that no live rolling-upgrade test was performed.Issue #30367 remains open. It is already assigned to tester
Ariznawlll, so no duplicate assignment was made. The PR is not merged yet; the issue remains open under the repository workflow.XuPeng-SH commentedon Oct 23, 2026
QA handoff checkpoint (2026-10-22): linked fix PR #30639 is at
78c61bd8309c613c616cd59d72592064beed538e. XuPeng-SH submitted an APPROVED review on this exact head; the prior precision, BIT comparison, persisted catalog compatibility, and performance findings have fixes with resolved review threads. The exact-head MatrixOne ALL CI, Iceberg Connector E2E, and Connector/J Pool Reset E2E workflows all completed successfully. This environment did not run MatrixOne locally; the test details are from the review/CI evidence. Transferring this issue to Ariznawlll for tester verification; issue remains open.XuPeng-SH commentedon Oct 23, 2026
PR #30639 current-head DUMP/LOAD 阻塞(head
78c61bd8309c613c616cd59d72592064beed538e)aptend 在该 head 的最新
CHANGES_REQUESTEDreview 中报告了一个尚未覆盖的目录兼容性回归:对旧版本创建并持久化的 CHECK / STORED generated-column 表达式,DUMP 路径绕过编译期 resolver/migration,LOAD 对有效的旧 bound-expression payload 也可能因当前绑定校验拒绝而失败。最小例子:
评审报告称,base planner 生成的旧 TableDef 在新 head 上执行 DUMP 会报
table dump cannot verify bound check expression ck;同类 STORED generated-column 表达式也失败。LOAD 旧备份中有效 CHECK payload 的验证同样失败。评审称其用 base 生成的 protobuf 在 head 重放确认,并通过 fresh-table / explicit-CAST controls;这是 review 提供的验证,我本轮没有独立重跑。请修复 DUMP 和 LOAD 的旧表达式绑定处理,并增加旧 TableDef / 旧 payload 的回归覆盖;需继续保留严格赋值精度、显式 CAST 与 payload 完整性校验。该问题尚未修复并验证,本 issue 暂不转测;目前仍 open、assigned to
Ariznawlll。fix(sql): enforce DECIMAL width for integer assignments (#30367) (#30639
Ariznawlll commentedon Oct 26, 2026
测试版本
main28e8760905a7f39dba2ce436357ea75492f30512;隔离 worktree 从该 SHA 构建的实际服务返回git_version()=28e8760905,两个 CN 均核对。3de2ee56e840fedb8b9994002a4fcbcb049c37e0经git merge-base --is-ancestor确认在该 main 祖先链上。原问题验证
每轮新建独立数据库,共 3/3 轮。在
STRICT_TRANS_TABLES下向DECIMAL(2,2)插入整数2,三轮均返回20301: 2 beyond the range, can't be converted to Decimal64(2,2),没有写入原 issue 的错误值2.00。另一 CN 读回原有三行始终为(1,0.99),(2,-0.99),(3,0.00)。将含0,2,3的 INT 列用ALGORITHM=COPY改为DECIMAL(2,2),三轮均因2越界拒绝,另一 CN 核对行仍为0,2,3且列类型仍是int。Happy Path 覆盖
DECIMAL(2,2)的0.99、-0.99和0均正确存储;DECIMAL(3,2)的9.99正确存储。3/3。Unhappy Path 覆盖
2、-2、1,字符串'2.00'与小数1.00写入DECIMAL(2,2)均被拒绝;每次失败后再次从另一 CN 读回,原三行未变。3/3。INSERT SELECT从 INT 源列写入越界值以及 SQL 服务端PREPARE/EXECUTE绑定整数2,均返回 20301,目标表无部分行。3/3。10写入DECIMAL(3,2)被拒绝,合法9.99仍在。3/3。白盒验证
合入后的完整 main 上,
TestIntToDecimalWidthContract、TestIntLiteralIntoColumnKeepsDecimalWidth、TestTableDumpHistoricalDecimalBoundPayload、TestTableDumpPersistedDecimalBindings使用-race -count=3定向通过;TestDecimalHistoricalDumpRoundtrip也用实际 SQL 集成路径-race -count=3通过。历史 DUMP/LOAD 的序列化夹具得到覆盖,但本轮未执行真实旧二进制到新二进制的滚动升级。回归测试
.result。隔离服务上录制后定向重放 3/3、共 90/90 SQL 语句通过,未把错误值写成成功 golden。测试证据
上述 MOTR 提交的 SQL/期望结果可直接复跑;本轮隔离脚本及 3 轮实际值保留在
/private/tmp/mo-six-qa-20261026/qa-current/verify_30367.py。修复前原 issue 的 3/3 复现记录保留在 issue 正文。测试结论
测试通过。