Repository navigation
fix(parser): support unquoted non-ASCII identifiers - #27010
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
e7e31e8 to
065efd8
Compare
065efd8 to
65f88bc
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
[P1] Preserve raw client bytes when a digit-leading token is promoted to an identifier.
This change explicitly supports both raw high-byte client identifiers (for example t_\xe9g) and digit-leading extended identifiers, but their combination takes a different path. In pkg/sql/parsers/dialect/mysql/scanner.go:813-820, scanNumber promotes the token to ID and then returns strings.ToLower(s.buf[start:s.Pos]). Go's Unicode lowercasing replaces an invalid UTF-8 byte such as the latin1 0xe9 with U+FFFD.
I reproduced this through the public parser at head 65f88bcf1d0388e299fd2ac85d8bf6438697fd13:
stmt, _ := ParseOne(ctx, "CREATE TABLE 1\xe9 (a INT)", 1)
tree.String(stmt, dialect.MYSQL)
// actual: "create table 1� (a int)"
// expected: "create table 1\xe9 (a int)"This silently addresses a different catalog object and can collapse distinct byte identifiers. Please keep the identifier bytes intact (or use byte-preserving ASCII-only folding if normalization is required), and add both scanner-level and ParseOne regressions for the pairwise case.
There is a second compatibility boundary to close: isUnquotedIdentifierLetter accepts every byte >= 0x80, so a valid UTF-8 supplementary character such as U+1F600 is accepted as an unquoted ID. MySQL explicitly limits identifiers to the BMP and prohibits U+10000 and above in quoted and unquoted identifiers: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html. I confirmed CREATE TABLE 😀 (a INT) parses successfully on this head. The validation needs to be charset-aware (or otherwise distinguish the supported raw-byte contract) so the fix does not broaden the grammar beyond the compatibility contract.
aptend
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 65f88bcf1d0388e299fd2ac85d8bf6438697fd13, including the existing same-head feedback. Two compatibility blockers remain:
-
[P1] Preserve raw client bytes when a digit-leading token is promoted to
ID.scanNumbernow accepts a following extended identifier byte, but still returnsstrings.ToLower(s.buf[start:s.Pos]). Go Unicode lowercasing rewrites invalid UTF-8 bytes. I reproducedCREATE TABLE 1\xe9 (a INT)throughParseOne: deparse returnscreate table 1� (a int)rather than preserving byte0xe9, so the parsed catalog name changes. Use byte-preserving ASCII-only folding (or return the original identifier bytes) and cover this combined digit-leading/raw-byte path at scanner and parser levels. -
[P1] Do not accept supplementary Unicode code points as MySQL identifiers.
isUnquotedIdentifierLetteraccepts every byte >= 0x80 independently, so UTF-8 for U+10000 and above is accepted as an unquoted identifier. I independently confirmedCREATE TABLE 😀 (a INT)parses successfully. MySQL restricts identifiers to the BMP; the validation boundary must distinguish supported raw client bytes from valid UTF-8 supplementary sequences instead of broadening the grammar to all high-byte sequences.
The two focused counterexamples fail on this exact head as described.
68ec2d9 to
fb5cfe6
Compare
|
已将分支从精确旧 head 68ec2d9 rebase 到当前 canonical main 0fc87ec,并用精确 lease 推送;新 head 为 fb5cfe6,无冲突。 失败的 UT run 31711715051 / job 94486146456(attempt 1)完整日志显示失败命令为 make ut UT_PARALLEL=6 UT_TIMEOUT=40,唯一失败是 pkg/tests/features.TestTableFeatures;稳定错误签名是 HAKeeper 连接 ID 分配期间 connection reset by peer / broken pipe / context deadline exceeded。该 run 执行期间合入的 #27119(fix(logservice): prevent connection ID refill convoys)直接修复了同一调用链和 2 秒超时/共享 transport reset 问题,本次 rebase 已包含该修复。未 rerun 旧 head 的 run,push 已触发新 head CI。 本地验证(rebase 后):
现有 CHANGES_REQUESTED 均基于旧 head;raw client bytes、digit-leading/raw-byte 组合、BMP/补充平面边界及 charset introducer 反馈已包含回归覆盖。请基于 fb5cfe6 重新 review。 |
|
@XuPeng-SH @aptend 重新核对当前 exact head 旧反馈在当前实现中的闭环证据:
该 exact head 在 rebase 后已 fresh 通过 parser tree/mysql 的 list、build、vet、完整 deterministic tests,以及 |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head fb5cfe6 (base and merge-base 0fc87ec). The previous raw-byte, supplementary-code-point, direct-entry, and charset-introducer blockers are closed. One PR-introduced correctness blocker remains.
[P1] Do not absorb invalid ASCII punctuation into an unquoted identifier when Unicode follows (pkg/sql/parsers/dialect/mysql/scanner.go:784-804, 813-840, 843-862).
scanNumber promotes the result to ID whenever the next position begins a supported Unicode identifier character, even after the numeric state machine has already consumed '.', or exponent '+'/'-'. Similarly, the 0x/0b fallback and @/@@ direct paths call scanIdentifier after punctuation, while scanIdentifier consumes its first byte unconditionally. Consequently the exact head accepts all of these malformed statements:
- CREATE TABLE 1.数量 (a INT)
- CREATE TABLE 1e+数量 (a INT)
- CREATE TABLE 1e-数量 (a INT)
- CREATE TABLE 0x.数量 (a INT)
- CREATE TABLE 0b+数量 (a INT)
- SELECT @+数量
- SELECT @@-数量
The ASCII '.', '+', and '-' are not legal unquoted-identifier characters. The same public ParseOne regression test passes on the exact base (all statements are rejected) and fails on the exact head (all are accepted), proving the behavior is introduced by this PR.
Please gate ID promotion on the complete consumed prefix being identifier-legal, and validate the first byte before every direct scanIdentifier entry. Preserve valid controls such as 1数量 and 1e数量, and add scanner plus public ParseOne regressions for the malformed boundaries above.
Validation on the exact head: git diff --check; GOWORK=off go list/build/vet -mod=readonly for parser tree/mysql; full deterministic tests for ./pkg/sql/parsers/tree and ./pkg/sql/parsers/dialect/mysql. All existing checks pass; the temporary head/base counterexample was removed after verification.
fb5cfe6 to
5c2276d
Compare
|
已修复 XuPeng-SH 在 exact head 修复闭环:
新增 scanner + public ParseOne 回归覆盖 review 中七个反例,并在 scanner 层验证 FLOAT 的原值及下一完整 Unicode ID,防止仅改 token type 却仍错误推进位置。 最终 rebase 后验证均 exit 0:
新 push 已触发 CI,未 rerun 旧 head run。烦请基于 |
|
@XuPeng-SH @aptend 当前 exact head 其中最新 review
当前 fork ref 与 PR head 均为 |
aptend
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head 5c2276d, including all prior review rounds. The raw-client-byte, supplementary-plane, direct scanIdentifier entry, _utf8mb4 prefix, and punctuation-before-Unicode blockers are closed. The latest change gates numeric-to-ID promotion after decimal/exponent punctuation, validates every direct identifier entry byte, preserves legal 1数量 and 1e数量 controls, and keeps malformed statements split/rejected without consuming the following BMP token.
I inspected the full scanner/CStr boundary and reran the focused scanner plus public ParseOne matrix for BMP/raw bytes, charset introducers, supplementary rejection, 0x/0b/@/@@ direct paths, and all seven punctuation counterexamples. Both parser packages passed on this exact head. No blocking correctness issue remains.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review on exact head 5c2276d. The earlier blockers are closed: valid supplementary-plane UTF-8 is rejected across the normal and direct scanner entry paths; malformed single-byte client-encoding bytes are preserved without RuneError replacement; _utf8mb4 is treated as a charset introducer only when followed by a string literal; and number/hex/bit/@ paths no longer absorb punctuation before a BMP identifier. Coverage exercises both scanner tokens and public ParseOne behavior. Verified full tree/mysql parser tests, 20x focused regressions, go vet, and git diff --check.
Merge Queue Status
This pull request spent 3 hours 32 minutes 48 seconds in the queue, including 57 minutes 26 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #26715
What this PR does / why we need it:
fix(parser): support unquoted non-ASCII identifiers