Repository navigation
Allow parenthesized queries in EXPLAIN - #100136
Conversation
|
Workflow [PR], commit [15d54a0] Summary: ✅ AI ReviewSummaryThis PR fixes a parser/formatter round-trip inconsistency for ClickHouse Rules
Final Verdict
|
|
Removed the backticks changes since they were causing test errors |
|
I see some tests failing and apparently they are related with AST |
Ergus
left a comment
There was a problem hiding this comment.
The fix looks correct, however there are 2 failing tests.
04049_explain_ast_parenthesized_access_queries the ticks are needed in the reference is this intended?. Update the reference file for 04049 to use `p7` instead of p7
03786_AST_formatting_inconsistencies_in_debug_check this test was recently updated on master with new ALTER ROW POLICY and WITH CHECK cases... so let's merge master and try again
3e89ec9 to
15d54a0
Compare
|
Should be good now |
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 72.97% (27/37, 0 noise lines excluded) |
…ized query `EXPLAIN AST` accepts a parenthesized query of any type (ClickHouse#100136), and the `FORMAT`, `SETTINGS` and `INTO OUTFILE` after the closing parenthesis then belong to the EXPLAIN. The formatter only re-emitted the parentheses for a non-`ASTQueryWithOutput` inner query other than `INSERT` (ClickHouse#100174), so it printed e.g. `EXPLAIN AST INSERT INTO t SELECT 1 FORMAT TSV`, and on re-parse the inner query took the options: `ParserInsertQuery` takes a `FORMAT` after a SELECT or INFILE and `SETTINGS` under `allow_settings_after_format_in_insert`, `DELETE`/`UPDATE` take `SETTINGS`, and every statement parsed by `ParserQueryWithOutput` (CREATE, ALTER, DROP, SHOW, ...) takes all of them. Debug builds abort with `Inconsistent AST formatting` (STID 1941-26fa, BuzzHouse), and in release builds `formatQuery` returns a different query. For `EXPLAIN AST` with trailing output options, wrap every inner query except a SELECT or EXPLAIN, which would re-parse as a subquery and already own their options in a text parse. Inside the parentheses, format the query without the trailing-options flags, because the closing parenthesis already separates it (same as `ASTSubquery` and the AS-select of `ASTCreateQuery`). Other EXPLAIN kinds keep the previous rule: they have no parenthesized form for non-SELECT queries. Not covered: a nested `EXPLAIN AST (EXPLAIN SYNTAX INSERT ...) FORMAT ...`, where the wrap would collide with the `(EXPLAIN ...)` subquery rewrite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Queries like the following were failing the double parse/format check (see f.e. here):
because the parsed/formatted query would add parentheses around the inner query (because of #99545). I think there is no reason to forbid parenthesized queries in EXPLAIN.
Changelog category (leave one):
Version info
26.4.1.61