Repository navigation
Description
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
fix(sql): harden FORMAT numeric and locale handling (#28508)
Ariznawlll commentedon Sep 10, 2026
测试版本
mainfc621e3616d229c7a29d0c80e73ed8eb1997459c1 Log / 1 TN / 1 CN原问题验证
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 覆盖
VARCHAR列和 SQLPREPARE/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 次通过。测试证据
fc621e3616。测试结论
测试通过。
fix(sql): harden FORMAT numeric and locale handling (matrixorigin#28508)
fix(sql): harden FORMAT numeric and locale handling (matrixorigin#28508)
fix(sql): harden FORMAT numeric and locale handling (matrixorigin#28508)