Repository navigation
Fix FORMAT clause not applying to EXPLAIN INSERT SELECT output - #101772
alexey-milovidov merged 10 commits into
Conversation
`ParserInsertQuery` greedily consumed the FORMAT clause after a SELECT subquery, leaving nothing for `ParserQueryWithOutput` to apply to the EXPLAIN output. Now, when a single FORMAT follows an INSERT...SELECT inside EXPLAIN, the FORMAT is rewound so it applies to the EXPLAIN output instead. The double-FORMAT form (`EXPLAIN INSERT INTO t SELECT 1 FORMAT CSV FORMAT JSON`) continues to work: first FORMAT goes to INSERT, second to EXPLAIN. Fixes ClickHouse#67321
Rename `04062_explain_insert_format` to `04077_explain_insert_format` to avoid collision with existing tests on main. Remove unrelated `04076_union_all_null_type_mismatch` files that don't belong in this PR.
The 04079_ prefix now collides with four tests on master (04079_crosstab_window_state_variant_cast, 04079_iceberg_write_retry_explicit_metadata, 04079_memory_engine_table_virtual_column, 04079_pr_view_sql_security_none, 04079_s3_read_request_histogram_metrics). 04309 is free both locally and on master. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Merged the latest Renumbered the test Rebuilt and verified the fix against the fresh binary:
Both match the reference. No unresolved review threads. |
|
Workflow [PR], commit [feeb81f] Summary: ✅
AI ReviewSummaryThis PR fixes Findings
Tests
Final VerdictStatus: Minimum required actions: make the rewind decision independent of unrelated |
The previous change rewound the trailing `FORMAT` from the inner
`INSERT ... SELECT` so it applies to the `EXPLAIN` output. But that also
rewound the `FORMAT` of `INSERT ... FROM INFILE ... SELECT ... FORMAT ...`
and `INSERT ... SELECT ... FROM input(...) ... FORMAT ...`, where the
`FORMAT` describes the insert's input data and must be preserved.
This broke the existing stateless test `02165_insert_from_infile`
(`EXPLAIN SYNTAX INSERT INTO test FROM INFILE 'data.file' SELECT x FROM
input('x UInt32') FORMAT TSV` lost its `FORMAT TSV`).
Now the rewind is skipped when the `INSERT` reads input data, i.e. when
`infile` is set or the `SELECT` contains an `input` table function.
Extended `04309_explain_insert_format` to cover both cases.
CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101772&sha=cb99c6cd9d553135eb425f9afa34d99f2e7899cf&name_0=PR&name_1=Fast%20test
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Fixed the CI failure ( The Fast test failure on The rewind is now skipped when the Verified locally against a fresh build:
All build jobs were already green; |
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 21/21 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
Both remaining review comments (the over-broad |
Follow-up to ClickHouse#101772. The FORMAT rewind that makes `FORMAT` apply to the `EXPLAIN` output of `EXPLAIN ... INSERT ... SELECT ... FORMAT ...` was guarded by `!insert_query->settings_ast` and `insert_query->format != "Values"`. Both guards were too broad: - `!settings_ast` also skipped the rewind for `SETTINGS` written before the `FORMAT` (and for settings pushed down from the inner `SELECT` by `InsertQuerySettingsPushDownVisitor`), so `EXPLAIN SYNTAX INSERT INTO FUNCTION null('x UInt64') SELECT 1 SETTINGS max_threads = 1 FORMAT JSONEachRow` left `FORMAT JSONEachRow` on the `INSERT` instead of applying it to the `EXPLAIN` output. - `format != "Values"` excluded the valid `Values` output format even though `insert_query->select` already rules out the `INSERT ... VALUES` data path, so `EXPLAIN SYNTAX INSERT INTO FUNCTION null('x UInt64') SELECT 1 FORMAT Values` never applied `FORMAT Values` to the `EXPLAIN` output. The original `settings_ast` guard existed because the blind `--pos; --pos;` rewind is only correct when the `FORMAT` clause is the last thing the `INSERT` parser consumed, which is not true when `SETTINGS` follow the `FORMAT` (`allow_settings_after_format_in_insert`). Instead of guarding on `settings_ast`, verify that the two trailing tokens are exactly `FORMAT <name>` before rewinding. This keeps `SETTINGS`/`FORMAT`-after-`SETTINGS` and `FORMAT Values` working while still leaving the `FORMAT` on the `INSERT` for the `SETTINGS`-after-`FORMAT`, `FROM INFILE`, `input`, and explicit double-`FORMAT` forms. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What this PR does
EXPLAIN INSERT INTO t SELECT 1 FORMAT JSONincorrectly applied FORMAT to the INSERT rather than the EXPLAIN output. The parser now detects when a single FORMAT follows INSERT...SELECT inside EXPLAIN and rewinds it so it applies to the EXPLAIN output.Fixes #67321
Changelog category (leave one):
Changelog entry:
Fixed
FORMATclause being consumed byINSERTinstead of applying toEXPLAINoutput inEXPLAIN INSERT INTO ... SELECT ... FORMAT ....Version info
26.6.1.466