phpmyadmin / phpmyadmin/sql-parser
CTE parsing fails when name is a non-reserved keyword
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- PHP
- Star
- 485
- Fork
- 119
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy hai bộ tái hiện vendor/bin/sql-parser --lint --query và theo dõi cách lexer và parser xử lý tên CTE sau WITH, bao gồm cả các tên được đặt trong dấu backtick. Được xem là hoàn tất khi cả hai truy vấn đều được phân tích cú pháp thành công, bao gồm các tên từ khóa không dành riêng và các tên từ khóa được đặt trong dấu ngoặc kép, mà không xuất hiện các lỗi đã báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- mysql, php, sql
- Lĩnh vực
- compilers, databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 65/100