Skip to content

[Compatibility]: FORMAT misparses signed, whitespace-prefixed, and normalized numeric strings #28476

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked open and closed issues.

#28213 covers rounding, sign retention, and the maximum number of decimal places. #28475 covers unchecked string indexes that produce internal panics. The behavior below is a separate numeric-string conversion and normalization problem: all queries return normally except the exponent-overflow case, but the value is wrong or an implementation error is exposed.

Branch Name

main

Commit ID

f0c31cd4b830be32442cf329e0a3fb08aa9c16c3

Other Environment Information

  • Local standalone MatrixOne built from the commit above
  • Reference: MySQL 8.3.0

Actual Behavior

FORMAT() uses an ad-hoc character parser rather than the function's numeric-conversion contract. It consequently misinterprets valid numeric strings with leading whitespace or a leading plus sign, preserves insignificant leading zeroes, and exposes a Go parsing error for an overflowing exponent.

Representative results:

SELECT FORMAT(' 1234.56', 2), FORMAT('+1234.56', 2),
       FORMAT('000123.4500', 2), FORMAT('1e309', 2);

MatrixOne:

0.00 | 0.00 | 000,123.45 | strconv.ParseFloat: parsing "1e309": value out of range

MySQL 8.3:

1,234.56 | 1,234.56 | 123.45 | 179,769,313,...,000.00

The decimal-place argument has the same conversion defect:

SELECT FORMAT('1234.56', ' 2'), FORMAT('1234.56', '+2');

MatrixOne returns 1,234 for both expressions, while MySQL returns 1,234.56.

The same results occur for leading tabs and whitespace before a negative number. The behavior is identical with VARCHAR columns and SQL PREPARE parameters. Every form was executed three times.

Expected Behavior

FORMAT() should convert number and decimal-place character arguments with the same numeric-prefix rules used by MySQL, normalize insignificant leading zeroes before grouping, and handle numeric overflow through the SQL conversion contract rather than returning a Go strconv implementation error.

Steps to Reproduce

SELECT FORMAT(' 1234.56', 2);
SELECT FORMAT('+1234.56', 2);
SELECT FORMAT('  -12.5', 1);
SELECT FORMAT('000123.4500', 2);
SELECT FORMAT('1e309', 2);
SELECT FORMAT('1234.56', ' 2');
SELECT FORMAT('1234.56', '+2');

CREATE DATABASE codex_format_string_coercion;
USE codex_format_string_coercion;
CREATE TABLE src(id INT PRIMARY KEY, n VARCHAR(40), d VARCHAR(20));
INSERT INTO src VALUES
  (1, ' 1234.56', '2'),
  (2, '+1234.56', '2'),
  (3, '000123.4500', '2'),
  (4, '1e309', '2'),
  (5, '1234.56', ' 2'),
  (6, '1234.56', '+2'),
  (7, '1234.56', '2');

SELECT id, FORMAT(n, d) FROM src WHERE id = 1;
SELECT id, FORMAT(n, d) FROM src WHERE id = 5;

PREPARE p FROM 'SELECT FORMAT(?, ?)';
SET @n = '+1234.56', @d = '2';
EXECUTE p USING @n, @d;
SET @n = '1234.56', @d = '+2';
EXECUTE p USING @n, @d;
DEALLOCATE PREPARE p;

Controls

Plain numeric strings, ordinary numeric values, numeric-prefix tails such as '12tail', NULL arguments, and nonnumeric strings such as 'abc' return through their expected non-panic paths. The server remains usable after the exponent error.

Root Cause

pkg/vectorize/format/format.go decides validity from the first byte and does not skip leading whitespace or accept +. It passes the unnormalized integer part directly to the grouping routine, and parses scientific notation with strconv.ParseFloat, returning that library error to SQL when the exponent exceeds float64.

Activity

  1. added this to the MO-202609 milestone on Sep 9, 2026
  2. added theissue type on Sep 9, 2026
  3. self-assigned this
    on Sep 9, 2026
  4. added a commit that references this issue on Sep 10, 2026
    1603316
  5. Ariznawlll commented on Sep 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:fc621e3616d229c7a29d0c80e73ed8eb1997459c
    • 部署方式:本地单机 1 Log / 1 TN / 1 CN
    • 测试日期:2026-09-10

    原问题验证

    FORMAT(' 1234.56',2)、FORMAT('+1234.56',2)、FORMAT('000123.4500',2) 连续 3 次返回 1,234.56 / 1,234.56 / 123.45;1e309 不再泄露 strconv 错误,返回被钳制的大数且保留 .00。

    Happy Path 覆盖

    1. 带空白负号、plus scale、空白 scale 的输入均按数值前缀规则得到正确格式。
    2. VARCHAR 列和 SQL PREPARE/EXECUTE 分别覆盖 plus-number 与 plus-scale,结果为 1,234.56。

    Unhappy Path 覆盖

    原问题中的指数溢出 1e309 是鲁棒性路径:连续 3 次均被数值钳制而非暴露实现错误;随后 fixture 仍为 6 行。

    白盒验证

    修复 PR matrixone#28508 已合入;pkg/vectorize/format 定向单测通过。

    回归测试

    已加入 MOTR PR #153:issue_28213_28475_28476_28478_28480_format_compatibility.test,连续 3 次通过。

    测试证据

    • 本地构建二进制的 Git commit 为 fc621e3616。
    • 回归提交:1cc567ea。

    测试结论

    测试通过。

  6. added 3 commits that reference this issue on Sep 17, 2026
    ef793b0
    79163fe
    7a03d78
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