apache / apache/datafusion-sqlparser-rs
`PostgreSqlDialect` accepts large amounts of non-PostgreSQL syntax
- 主要语言
- Rust
- 星标
- 3.5k
- 派生
- 772
- 平均合并
- 4 天 9 小时
- 30 天内合并 PR
- 17
描述
While building a parser correctness benchmark using libpg_query (`pg_query.rs`) as the PostgreSQL ground truth, we measured how often `PostgreSqlDialect` accepts SQL that real PostgreSQL rejects. The numbers are surprisingly high.
Against SQL extracted from the sqlparser-rs test suite itself:
- **28.7%** of statements rejected by pg_query are silently accepted by `PostgreSqlDialect` (37/129, PostgreSQL-specific test file)
- **30.0%** in the broader common-dialect test file (141/470)
We understand sqlparser-rs is intentionally permissive. The question is: **is this level of permissiveness intentional for `PostgreSqlDialect`, or is it leakage that would be worth tightening?**
## Examples of what `PostgreSqlDialect` currently accepts
A selection from the 141 cases found, grouped by the dialect the syntax originates from:
```sql
-- Oracle
FETCH NEXT IN my_cursor INTO result_table -- INTO clause on FETCH
-- SQL Server / T-SQL
SELECT TOP 3 * FROM tbl
EXEC my_proc N'param'
MERGE … OUTPUT inserted.* INTO log_target
EXECUTE FUNCTION f -- trigger EXECUTE without ()
-- MySQL / MariaDB
INSERT customer VALUES (1, 2, 3) -- missing INTO
INSERT OR REPLACE INTO t (id) VALUES(1)
DROP FUNCTION IF EXISTS f(a INTEGER, IN b INTEGER = 1) -- defaults in DROP
-- Snowflake / BigQuery
SELECT i FROM qt QUALIFY ROW_NUMBER() OVER (...) = 1
CREATE OR REPLACE TABLE t (a INT)
CREATE OR REPLACE USER IF NOT EXISTS u1 PASSWORD='secret'
-- ClickHouse
ALTER TABLE t ON CLUSTER my_cluster ADD CONSTRAINT bar PRIMARY KEY (baz)
-- HiveQL
ALTER TABLE t SET TBLPROPERTIES('classification' = 'parquet')
-- Unclear origin / possibly over-permissive parsing
ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY -- missing ALWAYS/BY DEFAULT
COPY t FROM 'f.csv' BINARY DELIMITER ',' CSV HEADER -- mutually exclusive formats
SHOW search_path search_path -- duplicate trailing token
```
Happy to help with PRs if the direction is clear.
贡献指南
这个仓库没有索引到贡献指南
调研方向
先以 pg_query.rs 作为 PostgreSQL 的事实标准,并查看 PostgreSQL 专用测试文件和通用方言测试文件,然后将列出的已接受语句与其预期行为进行比较。首先确定 PostgreSqlDialect 是否应拒绝这些情况,并定义一个有界范围;完成的标准是就方向达成一致,并为选定的语法提供回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rust, sql
- 领域
- compilers, databases
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100