fix(splitter): do not split EXPLAIN from the explained statement#759
Merged
psteinroe merged 1 commit intoJun 11, 2026
Merged
Conversation
Collaborator
|
thanks for the contribution! can you share more about your use case at clickhouse? happy to make the language server work for you! |
psteinroe
approved these changes
Jun 11, 2026
Contributor
|
@psteinroe hey! Clickhouse released recently a managed Postgres offering. We are using it inside our SQL Editor. Thank you for the great work so far! |
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 kind of change does this PR introduce?
Bug fix.
What is the current behavior?
The statement splitter treats the statement after an
EXPLAINprefix as a new statement, soEXPLAIN SELECT 1is split into two statements (EXPLAIN+SELECT 1):Downstream,
lint()then reports valid SQL as invalid — the bareEXPLAINfragment fails to parse withInvalid statement: syntax error at end of input— and consumers that execute the split statements send a broken bareEXPLAINto Postgres. All EXPLAIN forms are affected (EXPLAIN ANALYZE,EXPLAIN (ANALYZE, BUFFERS), etc.).This is the same mis-split class previously fixed for UNION (#321) and GRANT (#417).
What is the new behavior?
EXPLAINis handled as a statement prefix: a dedicatedexplain()splitter function consumes the prefix — the parenthesized option list or the legacy[ANALYZE | ANALYSE] [VERBOSE]modifiers — and then delegates to the splitter function of the explained statement, mirroring howstatement()dispatches. Covered forms includeEXPLAIN SELECT/INSERT/UPDATE/DELETE,EXPLAIN WITH ... SELECT,EXPLAIN CREATE TABLE AS,EXPLAIN VALUES, and multi-statement sources (EXPLAIN SELECT 1; SELECT 2splits at the semicolon).EXPLAIN_KWis deliberately not added toSTATEMENT_START_TOKENS:explainis an unreserved keyword and remains valid as an identifier mid-statement (e.g.SELECT explain FROM t), which a break-on-EXPLAIN rule inunknown()would mis-split. A regression test covers this.Additional context
Found while integrating
@postgres-language-server/wasmfor SQL editing/execution at ClickHouse, where this surfaced both as lint false positives and as broken EXPLAIN execution.