Parse PostgreSQL parenthesized EXPLAIN ( option [, ...] )#315
Open
alexey-milovidov wants to merge 1 commit into
Open
Parse PostgreSQL parenthesized EXPLAIN ( option [, ...] )#315alexey-milovidov wants to merge 1 commit into
alexey-milovidov wants to merge 1 commit into
Conversation
PostgreSQL and the PostgreSQL-compatible dialects CockroachDB, RisingWave
and Materialize accept the parenthesized EXPLAIN option form:
EXPLAIN (VERBOSE, COSTS OFF, FORMAT JSON) SELECT ...
Previously this failed to parse ("Expected identifier, got LParen"), which
blocked a large fraction of real PostgreSQL EXPLAIN statements from being
transpiled.
The options are planner/output directives with no cross-dialect meaning, so
they are parsed and discarded here - consistent with the existing
normalization of EXPLAIN to DESCRIBE. The ANALYZE option is folded into the
DESCRIBE style so that "EXPLAIN (ANALYZE) ..." matches bare
"EXPLAIN ANALYZE ...". A parenthesized subquery ("EXPLAIN (SELECT ...)") is
still parsed as a subquery target.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds support for PostgreSQL's parenthesized
EXPLAINoption syntax:This form is also accepted by the PostgreSQL-compatible dialects CockroachDB, RisingWave and Materialize.
Why
Before this change the parenthesized form failed to parse:
While transpiling PostgreSQL's regression test suite (
src/test/regress, ~53k statements) to ClickHouse viatranspile, this single gap caused the majority ofEXPLAINtranspilation errors (~2.7k statements): everyEXPLAIN (...)in the suite failed before its inner statement could be reached.How
The options (
ANALYZE,VERBOSE,COSTS,BUFFERS,SETTINGS,WAL,TIMING,SUMMARY,MEMORY,GENERIC_PLAN,SERIALIZE,FORMAT) are planner/output directives with no cross-dialect meaning, so they are parsed and discarded — consistent with the existing normalization ofEXPLAINtoDESCRIBE. TheANALYZEoption is folded into theDESCRIBEstyle so thatEXPLAIN (ANALYZE) ...behaves like bareEXPLAIN ANALYZE .... A parenthesized subquery (EXPLAIN (SELECT ...)) is still parsed as a subquery target, not an option list.The new parsing is gated to the PostgreSQL-family dialects (PostgreSQL, CockroachDB, RisingWave, Materialize), so no other dialect's behavior changes.
Tests
Adds
crates/polyglot-sql/tests/postgres_explain_options.rs(7 tests) covering option discard,ANALYZEfolding (includingANALYZE false/off), subquery disambiguation, PostgreSQL→ClickHouse transpilation, and the PG-compatible dialects. The fullpolyglot-sqlsuite passes; the only failing test,tpch_query2_transpile_postgres_to_fabric, is pre-existing onmainand unrelated to this change.