apache / apache/datafusion-sqlparser-rs
`PostgreSqlDialect` accepts large amounts of non-PostgreSQL syntax
- 主要言語
- Rust
- スター
- 3.5k
- フォーク
- 772
- 平均マージ
- 4日 9時間
- マージ済み PR(30日)
- 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.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
PostgreSQL の正しい基準として pg_query.rs と、PostgreSQL 固有および共通方言のテストファイルから始め、次に、一覧にある受け入れられた文を期待される動作と比較します。まず PostgreSqlDialect がこれらのケースを拒否すべきかを明確にし、範囲を限定します。選択した構文に対する合意済みの方向性とリグレッションカバレッジがあれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust, sql
- 領域
- compilers, databases
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100