apache / apache/datafusion-sqlparser-rs

`PostgreSqlDialect` accepts large amounts of non-PostgreSQL syntax

Ouverte
#2,237 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Rust
Étoiles
3.5k
Forks
772
Merge moyen
4 j 9 h
PR mergées (30 j)
17

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par pg_query.rs comme référence de référence pour PostgreSQL ainsi que par les fichiers de test spécifiques à PostgreSQL et au dialecte commun, puis comparez les instructions acceptées listées avec leur comportement attendu. Déterminez d'abord si PostgreSqlDialect doit rejeter ces cas et définissez un périmètre limité ; le travail est terminé lorsqu'une orientation est convenue et qu'une couverture de régression existe pour la syntaxe sélectionnée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
rust, sql
Domaine
compilers, databases
Type d'issue
Bug
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.