Repository navigation
Description
Branch Name: main
Commit ID: 6fb6531
Other Environment Information
- Hardware parameters: Apple Silicon (arm64), 10 cores
- OS type: macOS (darwin), Go 1.27.1
- Others: MatrixOne single-node
mo-service(LOG/TN/CN in one process) built from the commit above, default launch topology with all ports shifted (LOOM_TEST_PORT_OFFSET); control server: MySQL 8.0.46 (Homebrew); client:mysqlCLI
Actual Behavior
A numeric literal whose exponent is started but incomplete (digits '.' digits 'e' with no exponent digits after the e) is silently split into TWO tokens and executed as a valid query with an implicit alias:
SELECT 1.5e;-> row value1.5, column headereSELECT 1.e;-> row value1, column headere
At the AST level the select list contains a single expression NumVal "1.5" (ValType=P_float64) with implicit alias "e" - i.e. the broken literal was re-interpreted as 1.5 AS e. A typo like a missing exponent digit is silently transformed into a different, successful query instead of an error; the value is the truncated mantissa and the column name is the dangling e.
Expected Behavior
MySQL 8.0.46 (real server, same statements):
mysql> SELECT 1.5e;
ERROR 1064 (42000): You have an error in your SQL syntax; ... near '1.5e' at line 1
mysql> SELECT 1.e;
ERROR 1064 (42000): ... near '1.e' at line 1
Once the MySQL lexer commits to a fractional numeric literal (a '.' has been consumed) an invalid exponent cannot be demoted - the whole 1.5e is one malformed token and the statement is rejected with the error position pointing at the literal. 1.5e is NEVER equivalent to 1.5 AS e.
Steps to Reproduce
Pure unit repro, no server needed - full test source (verified FAILING on commit 6fb6531):
package parsers
import (
"context"
"fmt"
"testing"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
)
func TestReportFIncompleteExponentIsNotAnAlias(t *testing.T) {
ctx := context.Background()
for _, sql := range []string{"select 1.5e", "select 1.e"} {
stmts, err := Parse(ctx, dialect.MYSQL, sql, 1)
if err != nil {
// Rejected is what MySQL does, but for the wrong reason is also a
// bug; here we only flag the silent-split case.
continue
}
// Safe introspection: the generated (*tree.Select).String() can panic
// on this shape, so assemble the description field by field.
desc := fmt.Sprintf("unexpected statement type %T", stmts[0])
if sel, ok := stmts[0].(*tree.Select); ok {
switch inner := sel.Select.(type) {
case *tree.SelectClause:
if len(inner.Exprs) == 1 {
e := inner.Exprs[0]
if alias := e.As.Origin(); alias != "" {
desc = fmt.Sprintf("single expression %s with alias %q", e.Expr.String(), alias)
} else {
desc = fmt.Sprintf("single expression %s with no alias", e.Expr.String())
}
if nv, ok := e.Expr.(*tree.NumVal); ok {
desc += fmt.Sprintf(" (NumVal ValType=%v)", nv.ValType)
}
} else {
desc = fmt.Sprintf("SelectClause with %d expressions", len(inner.Exprs))
}
case nil:
desc = "Select with nil inner clause"
default:
desc = fmt.Sprintf("Select with inner %T", inner)
}
}
t.Errorf("F1: MySQL rejects %q with ERROR 1064 near '%s'; MatrixOne accepted it as: %s", sql, sql[len("select "):], desc)
}
// Boundary forms both engines agree on - they must keep parsing.
for _, sql := range []string{"select 1.e5", "select 1.5e38", "select 1e"} {
if _, err := Parse(ctx, dialect.MYSQL, sql, 1); err != nil {
t.Errorf("F2: regression, %q must still parse: %v", sql, err)
}
}
}
Run:
go test ./pkg/sql/parsers -run '^TestReportFIncompleteExponentIsNotAnAlias$' -count=1 -v
Current output: F1 fires for select 1.5e (accepted as single expression 1.5 with alias "e" (NumVal ValType=6)) and select 1.e - see evidence. F2 asserts the boundary forms (1.e5, 1.5e38, 1e) that must keep parsing and passes today.
SQL-level, against a running server:
mysql ... -e "SELECT 1.5e;"-> row1.5with column headere(expected: ERROR 1064 near '1.5e').mysql ... -e "SELECT 1.e;"-> row1with column headere(expected: ERROR 1064 near '1.e').- Same statements on a real MySQL 8.0.46 -> both rejected with ERROR 1064 (full outputs in evidence).
Additional information
- Root cause (scanner, MySQL dialect): in
scanNumbertheexponent:label (pkg/sql/parsers/dialect/mysql/scanner.go:885-898) checks the character AFTERe/E: if it is neither[+-]nor a digit the code executesgoto exitWITHOUT consuming thee. Because a.was already consumed for this literal,canPromoteToIdentifierisfalse, so the identifier-fallback atexit:(scanner.go:900-906) does NOT absorb the dangling character; insteadscanNumberreturns FLOAT"1.5"(or"1.") and the next token scan reads the unconsumedeas a fresh identifier. The grammar (as_name_opt, mysql_sql.y:8640-8660) then silently turns that identifier into an implicit alias of the numeric expression. - Why only the dotted forms diverge: for
select 1e(no '.')canPromoteToIdentifierstaystrue, so theexit:promotion absorbs theeinto the identifier1e- the same thing MySQL does (SELECT 1e;->Unknown column '1e' in 'field list'). The demotion on '.' is correct lexer-wise, but the failed-exponent path must then be an ERROR, not a silent split into two tokens. - Boundary regression coverage (F2, both engines agree today - a fix must preserve):
select 1.e5-> 100000,select 1.5e38-> float,select 1e-> column ref. - Recommended fix: when the exponent start is followed by anything that is not
[+-]|digit, consume to the end of the malformed literal and report a lexer error positioned at the literal start (MySQL behavior), instead of returning the truncated mantissa and leaving theedangling mid-stream. No stored-data implications. - Severity: s1 - silent wrong result on edge input (a malformed literal silently becomes a valid alias query with a truncated value).
- Duplicate screening: checked fix(sql): align approximate numeric text notation with MySQL #30316 / [Compatibility]: Approximate numeric text rendering differs from MySQL in scalar and JSON functions #30227 (approximate-numeric TEXT rendering in CAST/CONCAT/GROUP_CONCAT - a different layer) and feat: backport MySQL type compatibility features to 3.0-dev (#24184) #24198 (type-compat feature backport) - none covers literal LEXING of incomplete exponents.
Full reproduction, exactly as Loom ran it
Run on commit 6fb6531432 (single command, no server needed):
go test ./pkg/sql/parsers -run '^TestReportFIncompleteExponentIsNotAnAlias$' -count=1 -v
Current build: FAIL (F1 fires for both inputs; F2 boundary guard passes) - bug reproduced.
Full test file source:
```
package parsers
import (
"context"
"fmt"
"testing"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
)
func TestReportFIncompleteExponentIsNotAnAlias(t *testing.T) {
ctx := context.Background()
for _, sql := range []string{"select 1.5e", "select 1.e"} {
stmts, err := Parse(ctx, dialect.MYSQL, sql, 1)
if err != nil {
// Rejected is what MySQL does, but for the wrong reason is also a
// bug; here we only flag the silent-split case.
continue
}
// Safe introspection: the generated (*tree.Select).String() can panic
// on this shape, so assemble the description field by field.
desc := fmt.Sprintf("unexpected statement type %T", stmts[0])
if sel, ok := stmts[0].(*tree.Select); ok {
switch inner := sel.Select.(type) {
case *tree.SelectClause:
if len(inner.Exprs) == 1 {
e := inner.Exprs[0]
if alias := e.As.Origin(); alias != "" {
desc = fmt.Sprintf("single expression %s with alias %q", e.Expr.String(), alias)
} else {
desc = fmt.Sprintf("single expression %s with no alias", e.Expr.String())
}
if nv, ok := e.Expr.(*tree.NumVal); ok {
desc += fmt.Sprintf(" (NumVal ValType=%v)", nv.ValType)
}
} else {
desc = fmt.Sprintf("SelectClause with %d expressions", len(inner.Exprs))
}
case nil:
desc = "Select with nil inner clause"
default:
desc = fmt.Sprintf("Select with inner %T", inner)
}
}
t.Errorf("F1: MySQL rejects %q with ERROR 1064 near '%s'; MatrixOne accepted it as: %s", sql, sql[len("select "):], desc)
}
// Boundary forms both engines agree on - they must keep parsing.
for _, sql := range []string{"select 1.e5", "select 1.5e38", "select 1e"} {
if _, err := Parse(ctx, dialect.MYSQL, sql, 1); err != nil {
t.Errorf("F2: regression, %q must still parse: %v", sql, err)
}
}
}
```
SQL-level check of the same behavior against a server (mysql CLI):
mysql --protocol=TCP -h 127.0.0.1 -P <port> -u root --default-character-set=utf8mb4 --force -e "SELECT 1.5e; SELECT 1.e; SELECT 1.e5; SELECT 1e;"
MatrixOne: row 1.5 col `e` / row 1 col `e` / 100000 / ERROR 1054 column 1e. Real MySQL 8.0.46: ERROR 1064 near '1.5e' / ERROR 1064 near '1.e' / 100000 / Unknown column '1e'.Found by Loom bug hunt (module: sql-parser; tests: unit, black-box; severity: S1)
Activity
fix: reject incomplete exponents and keep owned daemon controls avail…
XuPeng-SH commentedon Nov 3, 2026
转 QA 验证:修复 PR #31137 已合入 main,merge SHA
6eb619121f0d3e1b2284d250122d8ac212a8a8f1。已读取本 issue 正文及全部评论(当前无评论),未发现适用于新修复的已验证反例或尚未完成的本问题开发 follow-up。证据边界:本轮仅核对远端 PR/issue,不是本轮本地实测。PR 作者报告原始 head 上 macOS arm64 / Go 1.27.1 完整 parser 测试、60 项 MatrixOne/MySQL 实际客户端对照、两次 11/11 BVT 通过;rebase 后重跑两包测试、vet/lint,通过,但客户端/BVT 是历史 head 证据。PR 同时包含独立 daemon 控制修复及 Linux normal/race 验证,不代表底层 HAKeeper 可用性问题已解决。
请 @Ariznawlll 在合并后版本复核
SELECT 1.5e、SELECT 1.e返回 1064/42000,错误位置保留原 literal;同时覆盖大小写 E、正负号/缺失数字、有效指数、1e标识符、合法别名、PREPARE、parser 复用及列元数据。合并后实际服务端/多节点组合尚未由本轮测试;本次为转测,不是验收通过。Ariznawlll commentedon Nov 3, 2026
结论
测试通过。最新 main 对不完整指数数字返回语法错误,不再把尾随
e当作隐式别名;合法指数、合法别名和错误后的会话继续可用。关键证据
main@dd2499cdcdf2722848851d4debca6cd6c66b4751;本地独立 LOG/TN/CN,macOS/Apple Silicon,Go 1.27.1。关联修复 #31137。1.e5、1.5e+2、.5E-2返回 100000、150、0.005,类型为 DOUBLE;1.5 e、注释分隔别名和显式别名保留正确值及列名,数字开头的引用标识符1e、字符串字面值也正确。1.5e、1.e、.5e、大小写 E、缺失指数及符号后缺数字等 10 类非法输入在两种协议各重复 3 轮,均返回1064 / 42000,错误消息保留原始字面量;每次错误后执行正常 SQL 成功。非法PREPARE返回 1064,合法PREPARE/EXECUTE/DEALLOCATE成功;事务中非法 INSERT 不产生部分写入,先前合法写入提交后仅有预期的一行。go test -p 1 ./pkg/sql/parsers ./pkg/sql/parsers/dialect/mysql -run 'TestNumericExponentParsing|Test.*Scanner|Test.*Position' -count=3两包通过,覆盖 tokenizer、错误位置及 parser 复用。4bf2808e55dd96fa7321edb66ec2965992bda2f8;SQL 用例 连续 3 次通过,共 69/69 条语句;该 PR 四项离线 CI 均通过。待解决点