CTE parsing fails when name is a non-reserved keyword
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 65/100
調査の方向性
まず、2つの vendor/bin/sql-parser --lint --query 再現ケースを実行し、WITH の後の CTE 名を lexer と parser がどのように処理するかを、バッククォートで引用された名前も含めて追跡します。両方のクエリが、予約されていないキーワード名と引用符で囲まれたキーワード名を含め、報告されたエラーなしに正常にパースできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
The parser rejects valid CTEs whose names are non-reserved keywords, throwing:
The name of the CTE was expected.
MySQL has a large set of keywords that are explicitly not reserved (no (R) marker in the official MySQL 9.7 keyword list^1). Non-reserved keywords are explicitly permitted as unquoted identifiers, including CTE names. MySQL executes these queries without error^2.
Reproducer
Unquoted:
vendor/bin/sql-parser --lint --query "WITH data AS (SELECT 1) SELECT * FROM data"
#1: The name of the CTE was expected. (near "data" at position 5)
#2: Unexpected end of the WITH CTE. (near "data" at position 5)
#3: Unrecognized statement type. (near "data" at position 5)
Backtick-quoted (which should unconditionally allow any keyword as an identifier):
vendor/bin/sql-parser --lint --query "WITH `data` AS (SELECT 1) SELECT * FROM `data`"
#1: The name of the CTE was expected. (near "`data`" at position 5)
#2: Unexpected end of the WITH CTE. (near "`data`" at position 5)
#3: Unexpected beginning of statement. (near "`data`" at position 5)
#4: Unrecognized statement type. (near "AS" at position 12)
Expected behaviour
The query parses successfully for any non-reserved keyword used as a CTE name, whether unquoted or backtick-quoted.
Actual behaviour
Parser throws errors in both cases. The root cause appears to be that the lexer classifies all keywords as keyword tokens unconditionally, rather than resolving them contextually. After WITH, the parser expects an identifier token; receiving a keyword token instead, it fails, even though MySQL allows non-reserved keywords in identifier position without quoting, and allows any keyword in identifier position when backtick-quoted.
- 主要言語
- PHP
- スター
- 485
- フォーク
- 119
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
phpmyadmin/sql-parser のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
phpmyadmin/sql-parser#655 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
phpmyadmin/sql-parser#666 ·
-
kind/support
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
phpmyadmin/sql-parser#653 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
phpmyadmin/sql-parser#649 ·
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
phpmyadmin/sql-parser#643 · コメント 1 件 ·
phpmyadmin/sql-parser の issue をすべて見る
似ている issue
-
sync-en
難易度 1/5 1〜3時間 初心者へのやさしさ 85/100
-
sync-en
難易度 1/5 1〜3時間 初心者へのやさしさ 85/100
-
Перевод устарел
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
-
[6.x]: "Cannot use object of type stdClass as array" loading Users index (regression of #19182) オープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100