Benchmark: polyglot-sql vs other Rust SQL parsers on PostgreSQL workloads #32
LucaCappelletti94
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have published an open-source benchmark comparing Rust SQL parsers on real-world PostgreSQL statements, including
polyglot-sql. Sharing the results here as they may be useful to the team.Benchmark repo: https://github.com/LucaCappelletti94/sql_ast_benchmark
What the benchmark measures
Performance: parse throughput on the Spider + Gretel PostgreSQL datasets (4,505 statements: SELECT, INSERT, UPDATE, DELETE), measured at batch sizes 1-1000.
Correctness: evaluated against the sqlparser-rs test suite using
pg_query.rs(libpg_query - the actual PostgreSQL parser) as ground truth. Four metrics:parse -> print -> re-parse -> re-printproduces identical output?pg_query_canonical(parser_output) == pg_query_canonical(original)- semantically correct output, not just self-consistent?Performance results
polyglot-sql has a notable per-call overhead at low batch sizes but amortizes very well at scale:
The crossover with sqlparser-rs occurs at around 10 statements. At 984 UPDATE statements, polyglot-sql is 2.5x faster (2.44 ms vs 6.23 ms). For a library only a few weeks old, this is a strong result.
Parse success rate on real-world corpus (Spider + Gretel, PostgreSQL-validated)
Correctness results
Tested against the sqlparser-rs test suite on three corpora, using pg_query as PostgreSQL ground truth. Counts show absolute numbers; percentages are bolded.
PostgreSQL-specific tests (312 valid / 129 invalid)
Common (all-dialect) tests (323 valid / 469 invalid)
TPC-H / regression tests (21 valid / 1 invalid)
Key correctness observations
Strengths:
Excellent real-world coverage: 100% parse success on SELECT, INSERT, DELETE; 99.8% on UPDATE. The library handles production-grade PostgreSQL workloads well.
Strong TPC-H recall (100%): complex analytical queries with multi-join, aggregations, subqueries, and window functions all parse successfully.
Good round-trip stability (97-99%): the vast majority of accepted statements round-trip cleanly through
parse -> print -> re-parse -> re-print.Areas for improvement:
False-positive rate is the most significant correctness gap: polyglot-sql accepts 51-61% of SQL that PostgreSQL itself rejects as invalid. This is the highest false-positive rate of any parser in the benchmark. Silent acceptance of invalid queries is a problem for any use case that relies on the parser as a validation layer.
Fidelity gap: among statements the parser accepts, only 78-89% produce semantically equivalent output under
pg_query's canonical form. The round-trip is stable (the parser is self-consistent), but the printer normalizes constructs in ways that change semantics. Several PostgreSQL constructs are emitted verbatim rather than translated:LEAST,GREATEST,DATE_TRUNC,JSON_AGG,EXTRACT,AT TIME ZONE,TIMESTAMPTZ,TSVECTOR,GRANT,REVOKE,CREATE ROLE.Semantic translation bug -
<=>operator:<=>is accepted and emitted unchanged in PostgreSQL-targeted output. In PostgreSQL,<=>is not a valid operator. The correct PostgreSQL equivalent of MySQL's<=>(null-safe equality) isIS NOT DISTINCT FROM.Minimal reproduction:
Summary
polyglot-sql's performance story is solid: faster than sqlparser-rs in bulk workloads and faster than pg_query.rs at all tested sizes. The correctness picture has clear gaps. The false-positive rate (51-61%) and fidelity (78-89%) are the two metrics most in need of attention if the library is used in any PostgreSQL-validation context.
Happy to share the raw test SQL files or open a PR adding polyglot-sql to the benchmark's CI if that would be useful.
I will follow up with a separate post documenting the specific translation failures in detail (concrete SQL inputs, observed outputs, and expected outputs for each affected construct).
Beta Was this translation helpful? Give feedback.
All reactions