Skip to content

[Compatibility]: explicit integer CAST overflow omits MySQL warnings 1105/1292 #30271

Closed

Description

@Ariznawlll

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 with git_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/UNSIGNED maxima return in range with 0 warnings on both systems.
  • Mode control: the omission is present in both sql_mode='' and STRICT_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 / INSERT succeeded 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:

  • parseSignedExplicitCastString and parseUnsignedExplicitCastString implement MySQL's wrap/clamp value semantics for out-of-range inputs without returning an error.
  • Their callers (strToSignedWithProc / strToUnsignedWithProc) append appendNumericCoercionWarning / appendIntegerNumericCoercionWarning only for truncated numeric prefixes. The range-adjustment branch itself has no diagnostic append, so the adjusted value is returned silently.
  • The castModeExplicit mode 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

Activity

  1. added this to the MO-202610 milestone on Oct 15, 2026
  2. added theissue type on Oct 15, 2026
  3. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

    验证通过,转测 @Ariznawlll。

    本轮复核关联 PR #30297,实测 main 提交 aa4b6eddfdad54d11be6fd75a5675eb9801f6690(Linux/amd64、Go 1.27.1;使用对应 native 构建)。

    独立原始 SQL 复验通过:字符串 signed/unsigned 溢出的返回值保持,SHOW WARNINGS 按顺序返回 1105/1292/1105/1292;合法边界值不产生 warning。相关函数、folding 与真实预编译协议回归通过。

    本次保持 OPEN,请测试侧在目标交付版本完成验收后决定关闭。

  4. Ariznawlll commented on Oct 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:7c2847207dc5bd87f6c23dc7318f7be21c0a5f2a(fix(sql): report explicit cast overflow warnings #30297 已合入)
    • 部署方式:隔离 make build,本机 1 CN / 1 TN / 1 LogService,MySQL 协议端口 6001;默认非严格与显式严格模式。
    • 测试日期:2026-10-17

    原问题验证

    独立执行原有 signed/unsigned 整数 CAST 溢出 SQL,3/3 精确核对五个值:9223372036854775807、-9223372036854775808、-9223372036854775808、18446744073709551615、18446744073709551615;非严格模式对应告警序列为 1105,1292,1105,1292,不再悄悄给错值。

    Happy Path 覆盖

    1. 可表示范围内的 signed/unsigned CAST 值保持正确,SHOW WARNINGS 为空,3/3。
    2. 表列值、预处理语句复用后的正常输入不产生残留告警,3/3。

    Unhappy Path 覆盖

    1. 严格模式溢出返回 1105 错误;非严格模式给定义的截断值及上述告警,均 3/3。
    2. 表列与预处理语句中的溢出输入同样报告 1105;失败后再执行有效输入成功且无旧告警,3/3。

    白盒验证

    核对 #30297 合入提交进入上述官方 main;结论基于独立外部客户端的值和诊断信息,不以代码覆盖代替验收。

    回归测试

    MOTR 成对文件 suites/14_issue_regression/t/issue_30271_integer_cast_warning.test / r/issue_30271_integer_cast_warning.result 已在汇总 PR #247,head f55a4b3813d44412ad6dc776ea51547480a0aee6;定向 3/3 通过。三项新 SQL 回归合并定向累计 9/9 文件次、252/252 语句。完整 suite 尚未通过,PR 尚未合入,集成 CI 未验证。

    测试证据

    • MOTR 回归提交
    • 隔离工作树 /private/tmp/mo-30265-qa-adWo0K/qa_cast_warnings.py 三轮精确断言结果与告警码。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions