Repository navigation
Description
Environment
- MatrixOne:
mainatfc621e3616d229c7a29d0c80e73ed8eb1997459c - MySQL reference: 8.0.46
Problem
MatrixOne accepts IGNORE_SPACE in sql_mode, but always permits whitespace between whitespace-sensitive built-in function names and (. The parser behaves as if IGNORE_SPACE were permanently enabled, so switching the mode has no effect and SQL rejected by MySQL's default mode is accepted by MatrixOne.
MySQL documents the function-name rule and the effect of IGNORE_SPACE: for affected built-in functions, the name must be immediately followed by ( unless the mode is enabled.
Reproduction
CREATE TABLE src(id INT PRIMARY KEY, a INT);
INSERT INTO src VALUES(1,10),(2,20);
SET SESSION sql_mode = 'STRICT_TRANS_TABLES';
SELECT NOW ();
SELECT SUBSTRING ('abcdef',2,3);
SELECT COUNT (*) FROM src;
SELECT SUM (a) FROM src;
SELECT DATE_ADD ('2024-01-01',INTERVAL 1 DAY);MatrixOne executes every statement and returns the same results as the no-whitespace forms.
MySQL 8.0.46 in the default mode rejects these statements: NOW, SUBSTRING, and SUM are resolved as schema functions, while COUNT (*) and DATE_ADD (...) produce syntax errors.
After enabling the mode, MySQL accepts all of them:
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,IGNORE_SPACE';MatrixOne's results do not change between the two modes.
Controls and persistent SQL objects
ABS (-2)andMOD (5,2)succeed in MySQL with or without the mode and also succeed in MatrixOne. This distinguishes MySQL's function-specific whitespace rule from a blanket ban on spaces before(.- No-whitespace forms such as
NOW(),SUBSTRING(...), andCOUNT(*)succeed in both systems in both modes. PREPARE p FROM 'SELECT NOW (),COUNT (*) FROM src'and a view with the same expressions succeed in MatrixOne under the default mode; MySQL rejects their creation. Both systems accept and retain them when created withIGNORE_SPACEenabled.- A prepared statement and view successfully created under
IGNORE_SPACEremain executable after the session returns to the default mode in both systems, confirming that creation-time parsing is the relevant stage.
Code analysis
pkg/frontend/variables.go lists IGNORE_SPACE as a valid sql_mode token. pkg/sql/parsers/dialect/mysql/sql_mode.go has parser flags only for ANSI_QUOTES, PIPES_AS_CONCAT, NO_BACKSLASH_ESCAPES, and REAL_AS_FLOAT; it neither defines nor parses an IGNORE_SPACE flag. The grammar consequently accepts whitespace for the affected built-ins regardless of session mode.
The only other IGNORE_SPACE symbol in the repository is CLIENT_IGNORE_SPACE in the MySQL protocol capability constants, which does not implement the session SQL-mode rule.
The behavior above was reproduced three times with fresh databases and connections. Direct scalar functions, aggregates, date syntax, unaffected function controls, SQL prepared statements, views, and mode changes after creation were covered.
Activity
Ariznawlll commentedon Sep 14, 2026
测试版本
main7ffce04a0921c684ccfe92863eac5f56279068fc原问题验证
在 fresh database 中连续执行 3 轮原复现:
STRICT_TRANS_TABLES下NOW ()、COUNT (*)、DATE_ADD (...)分别稳定拒绝(错误码为20105、1064、20105);切换为STRICT_TRANS_TABLES,IGNORE_SPACE后,NOW ()、SUBSTRING (...)、COUNT (*)、SUM (a)与DATE_ADD (...)均返回预期值。每轮输出一致,未出现连接断开、服务重启或异常资源日志。Happy Path 覆盖
NOW()正常;ABS(-2)与MOD(5,2)在默认模式下均正常,确认不是全局禁止函数名前空格。IGNORE_SPACE模式下验证标量、聚合、日期函数,分别得到1、bcd、1、1、1。IGNORE_SPACE下创建包含NOW ()与COUNT (*)的 PREPARE 和 VIEW,切回默认模式后仍可执行,两个对象均返回now_ok=1, count_ok=1。Unhappy Path 覆盖
NOW ()、COUNT (*)、DATE_ADD (...)均按函数类别被拒绝。information_schema.views,对应 view 数量为0,确认失败未遗留持久对象。白盒验证
执行
go test -vet=off ./pkg/sql/parsers/dialect/mysql -run '^(TestParseSQLModeFlagsIgnoreSpace|TestIgnoreSpaceFunctionParsing|TestIgnoreSpaceReservedFunctionIdentifiers|TestIgnoreSpaceFunctionFormatting|TestIgnoreSpaceGenericFunctionFormatRoundTrip|TestScannerSQLModeIgnoreSpace)$' -count=1 -v,全部通过;覆盖 scanner、SQL mode flag、函数解析及保留字边界。回归测试
suites/14_issue_regression/t/issue_28199_28201_28603_spatial_ignore_space.test。./motr --repeat 3 14_issue_regression.issue_28199_28201_28603_spatial_ignore_space -v:3/3 通过,46 条语句/轮,共 138/138。测试证据
/tmp/mo-issue-validation-20260914/latest14-run/。测试结论
测试通过。