Repository navigation
Description
Description
An explicit CAST of a string that overflows the target signed or unsigned integer range returns the MySQL-compatible wrapped/clamped value, but does not report any conversion warning. SHOW WARNINGS is empty and @@warning_count is 0, while MySQL 8.0.44 exposes 1105/1292 diagnostics for the same expressions. Clients that inspect diagnostics cannot tell that the value was adjusted.
Environment
- Branch:
main - Commit:
501c85ecdd6eee0195172743c6d8aaf125cb252d(confirmed withgit_version()) - Runtime version:
8.0.30-MatrixOne-v - Deployment: local single-node launch built from the pinned source commit
- MySQL comparison:
8.0.44, isolated container, same single-node MySQL protocol - Test date: 2026-10-15
Steps to reproduce
Run each block in one session and inspect SHOW WARNINGS and @@warning_count immediately afterward.
SET SESSION sql_mode='';
SELECT 'nonstrict_casts',
CAST('9223372036854775807' AS SIGNED),
CAST('9223372036854775808' AS SIGNED),
CAST('-9223372036854775809' AS SIGNED),
CAST('-1' AS UNSIGNED),
CAST('18446744073709551616' AS UNSIGNED);
SHOW WARNINGS;
SELECT @@warning_count;
SELECT 'control_casts',
CAST('9223372036854775807' AS SIGNED),
CAST('18446744073709551615' AS UNSIGNED);
SHOW WARNINGS;
SELECT @@warning_count;Actual behavior
MatrixOne returns the same values as MySQL, but no diagnostics:
nonstrict_casts 9223372036854775807 -9223372036854775808 -9223372036854775808 18446744073709551615 18446744073709551615
SHOW WARNINGS returns no rows and @@warning_count is 0. The same happens with the default strict mode (CAST('9223372036854775808' AS SIGNED) and CAST('-1' AS UNSIGNED) both return adjusted values with zero warnings).
This reproduced 3/3 times in independent temporary databases. Each run created and dropped its own database and ended with zero residual round_040_intcast_warn_% schemas.
The omission is not limited to literal folding. These related paths also return adjusted values with @@warning_count = 0:
- column text values:
SELECT CAST(s AS SIGNED) FROM t WHERE id=... - prepared parameters:
PREPARE stmt FROM 'SELECT CAST(? AS SIGNED)'; EXECUTE stmt USING @v;
The boundary controls on both systems return the requested values with no warning, which matches MySQL:
CAST('9223372036854775807' AS SIGNED) -> 9223372036854775807
CAST('18446744073709551615' AS UNSIGNED) -> 18446744073709551615
Expected behavior
MySQL 8.0.44 returns the same values and reports diagnostics. With sql_mode='', one statement reports 4 warnings:
Level Code Message
Warning 1105 Cast to signed converted positive out-of-range integer to its negative complement
Warning 1292 Truncated incorrect INTEGER value: '-9223372036854775809'
Warning 1105 Cast to unsigned converted negative integer to its positive complement
Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616'
The boundary-only control reports 0 warnings, and the strict-mode session reports the 1105 diagnostics for the two adjusted values. MatrixOne should preserve the current wrapped/clamped values while exposing the corresponding warnings through SHOW WARNINGS / @@warning_count.
Stability and controls
- Reproducer: 3/3 on MatrixOne
main, in independent temporary databases, literal path. - MySQL comparison: 3/3, identical values and identical four-warning list in the non-strict session.
- Boundary control: legal
SIGNED/UNSIGNEDmaxima return in range with 0 warnings on both systems. - Mode control: the omission is present in both
sql_mode=''andSTRICT_TRANS_TABLES,.... - Path control: the omission also reproduces for column-derived text and a prepared-statement parameter on MatrixOne.
- Failure atomicity: the session remains usable after the warning path; a follow-up
CREATE TABLE/INSERTsucceeded and each temporary database was dropped.
Evidence
Raw MatrixOne output (one of three identical runs):
nonstrict_casts 9223372036854775807 -9223372036854775808 -9223372036854775808 18446744073709551615 18446744073709551615
warning_count 0
control_casts 9223372036854775807 18446744073709551615
control_warning_count 0
strict_casts -9223372036854775808 18446744073709551615
strict_warning_count 0
session_alive 1
residual 0
Raw MySQL 8.0.44 output (one of three identical runs):
nonstrict_casts 9223372036854775807 -9223372036854775808 -9223372036854775808 18446744073709551615 18446744073709551615
Warning 1105 Cast to signed converted positive out-of-range integer to its negative complement
Warning 1292 Truncated incorrect INTEGER value: '-9223372036854775809'
Warning 1105 Cast to unsigned converted negative integer to its positive complement
Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616'
warning_count 4
control_casts 9223372036854775807 18446744073709551615
control_warning_count 0
strict_warning_count 2
Code analysis
Confirmed path in pkg/sql/plan/function/func_cast.go at the tested commit:
parseSignedExplicitCastStringandparseUnsignedExplicitCastStringimplement MySQL's wrap/clamp value semantics for out-of-range inputs without returning an error.- Their callers (
strToSignedWithProc/strToUnsignedWithProc) appendappendNumericCoercionWarning/appendIntegerNumericCoercionWarningonly for truncated numeric prefixes. The range-adjustment branch itself has no diagnostic append, so the adjusted value is returned silently. - The
castModeExplicitmode therefore has no warning for this case, matching the observed@@warning_count = 0.
Regression coverage
Add explicit integer CAST overflow cases to the cast BVT (test/distributed/cases/function/func_cast.test and result), asserting both the wrapped/clamped value and the 1105/1292 diagnostics in a fresh session, with legal-max boundary rows as the no-warning control. The same expectations should be kept in the motr cast matrix row that currently covers value parity without diagnostics.
Related
- [Compatibility]: explicit DECIMAL cast overflow omits warning 1264 #30265 (
[Compatibility]: explicit DECIMAL cast overflow omits warning 1264) is the analogous gap for the DECIMAL target. This report is the distinctSIGNED/UNSIGNEDstring-cast path with warning codes 1105/1292. - [Compatibility]: Built-in integer arguments omit MySQL warnings for malformed strings #30218 covers malformed string arguments to built-in integer parameters; that is a different conversion path and warning trigger.
- [Bug]: CAST overflow handling differs from MySQL clamp/wrap behavior #25252 reported the value behavior of explicit
CASToverflow. It was closed after fix: align explicit CAST overflow behavior with MySQL #25898 aligned wrap/clamp values; PR fix: align explicit integer string casts with MySQL #25431 explicitly scoped warning behavior out, so the diagnostic gap remains. - Sibling warning-parity reports checked for overlap: [Compatibility]: SELECT division by zero omits MySQL warnings #30211, [Compatibility]: STR_TO_DATE omits MySQL warnings for invalid or truncated input #30213, [Compatibility]: logarithm functions omit MySQL warning 3020 for invalid arguments #30214, [Compatibility]: FORMAT silently ignores warnings for unknown or NULL locale #30217, [Compatibility]: UNHEX omits MySQL warning 1411 for invalid hex input #30230.
Activity
fix(sql): report explicit cast overflow warnings (#30297)
XuPeng-SH commentedon Oct 17, 2026
验证通过,转测 @Ariznawlll。
本轮复核关联 PR #30297,实测 main 提交
aa4b6eddfdad54d11be6fd75a5675eb9801f6690(Linux/amd64、Go 1.27.1;使用对应 native 构建)。独立原始 SQL 复验通过:字符串 signed/unsigned 溢出的返回值保持,SHOW WARNINGS 按顺序返回 1105/1292/1105/1292;合法边界值不产生 warning。相关函数、folding 与真实预编译协议回归通过。
本次保持 OPEN,请测试侧在目标交付版本完成验收后决定关闭。
Ariznawlll commentedon Oct 17, 2026
测试版本
main7c2847207dc5bd87f6c23dc7318f7be21c0a5f2a(fix(sql): report explicit cast overflow warnings #30297 已合入)make build,本机 1 CN / 1 TN / 1 LogService,MySQL 协议端口 6001;默认非严格与显式严格模式。原问题验证
独立执行原有 signed/unsigned 整数 CAST 溢出 SQL,3/3 精确核对五个值:
9223372036854775807、-9223372036854775808、-9223372036854775808、18446744073709551615、18446744073709551615;非严格模式对应告警序列为1105,1292,1105,1292,不再悄悄给错值。Happy Path 覆盖
SHOW WARNINGS为空,3/3。Unhappy Path 覆盖
白盒验证
核对 #30297 合入提交进入上述官方 main;结论基于独立外部客户端的值和诊断信息,不以代码覆盖代替验收。
回归测试
MOTR 成对文件
suites/14_issue_regression/t/issue_30271_integer_cast_warning.test/r/issue_30271_integer_cast_warning.result已在汇总 PR #247,headf55a4b3813d44412ad6dc776ea51547480a0aee6;定向 3/3 通过。三项新 SQL 回归合并定向累计 9/9 文件次、252/252 语句。完整 suite 尚未通过,PR 尚未合入,集成 CI 未验证。测试证据
/private/tmp/mo-30265-qa-adWo0K/qa_cast_warnings.py三轮精确断言结果与告警码。测试结论
测试通过。