Repository navigation
EXPLAIN SYNTAX: return a single record (default on) - #110479
Conversation
Add a single_record option to EXPLAIN SYNTAX. When set, the reformatted query is returned as one multi-line record instead of one record per line. Off by default, so the existing row-per-line output (and all reference files that consume it) is unchanged. See issue #80410. The single-record code path already existed (used by EXPLAIN PLAN json); this wires it to the new option for the SYNTAX kind and renames the flag single_line -> single_record, since the SYNTAX buffer is multi-line but one record. Other EXPLAIN kinds keep one row per line. Closes #80410 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Make single_record on by default, so EXPLAIN SYNTAX returns the reformatted query as a single multi-line record instead of one record per line. Set single_record = 0 to restore the historical row-per-line output. This is a backward-incompatible change: existing EXPLAIN SYNTAX consumers now see one row instead of N (the whole reformatted query, with embedded newlines). The oneline option still controls physical-line rendering and defaults to 0. Regenerated the affected stateless .reference and .oldanalyzer.reference files for the new default. Switched the optimize_syntax_fuse_functions docstring example from FORMAT TSV to FORMAT TSVRaw so its multi-line output stays literal now that the single record carries the embedded newlines. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…le-record # Conflicts: # tests/queries/0_stateless/02226_analyzer_or_like_combine.oldanalyzer.reference # tests/queries/0_stateless/02226_analyzer_or_like_combine.reference
… master The merge of master brought in the reworked `optimize_or_like_chain` (#94517), which changed the semantic content of this test. Regenerate both reference files from the merged binary so the `EXPLAIN SYNTAX` results are single records with embedded newlines, matching the new `single_record = 1` default. Verified with clickhouse-test against a local server: `02226_analyzer_or_like_combine` passes with both the new and the old analyzer.
|
Workflow [PR], commit [287bfc5] Summary: ✅
AI ReviewSummaryThis PR changes Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 61/73 (83.56%) · Uncovered code |
The single_record default was hardcoded to true inside the local QuerySyntaxSettings struct in InterpreterExplainQuery.cpp, so it never consulted `compatibility`. Old clients that rely on `compatibility` (rather than editing every EXPLAIN SYNTAX query by hand) would silently start seeing a single row after upgrading, with no way to opt back into the pre-26.7 output. Add a proper `explain_syntax_single_record` setting (mirroring `explain_query_plan_default`, used the same way for EXPLAIN PLAN), register it in SettingsChangesHistory.cpp for 26.7, and feed it into checkAndGetSettings() as the default before any explicit `single_record = ...` option in the EXPLAIN statement overrides it. Setting `compatibility` to any version older than 26.7 now restores the historical row-per-line output, same as for `explain_query_plan_default`. Addresses review feedback on PR #110479 (single_record couldn't be reverted via compatibility).
…e_record default This test's EXPLAIN SYNTAX run_query_tree_passes=1 calls were still checked in with the pre-26.7 row-per-line output; it was added to master after the single_record default flip landed on this branch and was missed by the earlier reference regeneration pass, so CI failed with a result-differs-with-reference diff on the two EXPLAIN SYNTAX statements (amd_debug/tsan/asan_ubsan parallel, arm_binary parallel).
…NTAX output The AI review and clickhouse-gh[bot] requested a focused regression test for the upgrade-safe legacy path: the new `explain_syntax_single_record` default must be restorable via `compatibility`, not only via the `EXPLAIN`-local `single_record` option that 04517 already covered. Add to 04517_explain_syntax_single_record.sql: - SET compatibility = '26.6' (predates the setting) then assert count() > 1 from EXPLAIN SYNTAX, proving the pre-26.7 one-record-per-line output is restored for old clients that rely on compatibility. - Assert the EXPLAIN-local single_record = 1 option still wins over compatibility when explicitly set. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
CI failures on
Merged |
|
@alexey-milovidov the That PR was opened directly off STID 0993-386d (it cites this exact STID and the same duplicate-column JoinStep signature). Root cause: a correlated subquery decorrelated into a join whose source relation carries a column name more than once, e.g. WITH t AS (SELECT number, * FROM numbers(3))
SELECT *, (SELECT t.number WHERE t.number >= 0) FROM t
SETTINGS correlated_subqueries_default_join_kind = 'right';The |
…ocs example After this PR flips `EXPLAIN SYNTAX` to return a single `String` record with embedded newlines by default, the `optimize_syntax_fuse_functions` example on the autogenerated `docs/reference/settings/session-settings.mdx` page still used `FORMAT TSV`, which escapes the embedded line breaks as `\n` and no longer renders the multi-line query shown in the result block. Switch it to `FORMAT TSVRaw` to match the already-updated `optimize_syntax_fuse_functions` source doc in `src/Core/Settings.cpp` and the actual output. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Investigated. This recurrence is the non-clonable-source carrier of the The failing query, from SELECT count() FROM test_2.t_local
WHERE x IN (SELECT x FROM merge('test_2', '') WHERE x < 3)An AST-fuzzer draw off Root cause: I confirmed the carrier with an index-pruning discriminator rather than a failure injection, since it distinguishes the destructive path from the preserving one directly: CREATE TABLE t_local (x UInt64) ENGINE = MergeTree ORDER BY x SETTINGS index_granularity = 8;
INSERT INTO t_local SELECT number FROM numbers(800);
-- clonable source (control)
SELECT trimLeft(explain) FROM (EXPLAIN indexes = 1
SELECT count() FROM t_local WHERE x IN (SELECT x FROM t_local WHERE x < 3))
WHERE explain ILIKE '%Granules%';
-- non-clonable source
SELECT trimLeft(explain) FROM (EXPLAIN indexes = 1
SELECT count() FROM t_local WHERE x IN (SELECT x FROM merge(currentDatabase(), '^t_local$') WHERE x < 3))
WHERE explain ILIKE '%Granules%';On master both report #114983 ("Report the real error when an in-place The |
|
🕵 @groeneai, investigate these unrelated CI failures and provide fixes in separate PRs (or link existing work here):
|
|
Investigated both. They are unrelated to each other and to this PR. (a)
|
(a)
|
| failed (241) | passed | |
|---|---|---|
RemoteFSPrefetches |
3003 min / 3169 mean / 3391 max | 12 min / 183 mean / 2597 max |
memory_usage |
4.66 GiB in all 28 | 3.24 GiB max |
allow_prefetched_read_pool_for_remote_filesystem |
0 in all 28 | 0 in all 631 |
The chain: map_buckets_min_avg_size is randomized to 1 (default 32), which disables the
small-map guard in SerializationMap::calculateNumberOfBuckets, so a 2-key map takes
constant/max_buckets_in_map and gets 64 buckets instead of 1.
SerializationMap::enumerateStreams then emits a nested Array(Tuple(K, V)) per bucket, about
194 substreams for column h, and MergeTreeReaderWide::prefetchForColumn issues one prefetch,
each with its own read buffer, per substream. 4.66 GiB / 1.64 MiB is 2910 buffers; 3003 to 3391
were issued.
filesystem_prefetches_limit does not stop it because
MergeTreeReaderWide::prefetchForAllColumns compares it against the column count (2), not the
prefetch count. That specific defect is what my open #114072 fixes: it counts the prefetches
actually issued and stops at the limit, at both issuance sites. It is not merged, so it was not in
this build.
One thing #114072 does not cover, and I would rather flag it than quietly widen that PR: its bound
is per reader. This run left filesystem_prefetches_limit at the default 200, one reader
enumerates only ~194 substreams, and the 3169 prefetches are ~16 concurrent readers. So at the
default limit the bound never engages here; it engages only when the limit is randomized below
~194. Admission is per reader, exhaustion is query-wide. The plain ReadPool also has no
filesystem_prefetch_max_memory_usage budget at all (only MergeTreePrefetchedReadPool reads
that setting), and the run above never constructed the prefetched pool.
Closing that gap needs a policy decision I do not want to make unilaterally, since each option is
user-visible:
- Shared query-level admission, all-or-nothing. Preserves the contract
03394_filesystem_prefetches_limit.referencepins (10 columns at limit 5 records 0
prefetches, not 5), but a wide-Map reader can then be denied prefetching entirely under a
shared budget. - Shared query-level admission, partial. Bounds memory smoothly, changes that tested contract.
- Memory-based admission for the plain
ReadPool, giving it the budget concept it currently
lacks.
There is no shared cross-reader prefetch state today to extend: MergeTreeReaderSettings is
copied per reader, so any of these is new plumbing.
If you would rather not touch the reader for this at all, the cheap alternative is a one-line
test clamp, -- Random settings limits: map_buckets_min_avg_size=(32, None), which restores the
documented small-map guard and neutralizes the whole randomized set the minimizer reported. I did
not take it on its own because it leaves the memory blow-up reachable with non-default MergeTree
settings.
Happy to implement whichever of 1-3 you prefer. Note map_serialization_version defaults to
basic and map_buckets_min_avg_size to 32, so a 2-key map gets one bucket by default; reaching
this needs non-default settings, which is why I have not filed it as a separate bug.
# Conflicts: # tests/queries/0_stateless/04032_and_comparison_filter_optimization_2.reference
|
Root-caused the (b) half above, the The hung check's verdict was true. The measurement came from the job's own One mechanism proven on one artifact, not a claim about every |
|
Fixing PR for the mislabel half of (b): #115080. One correction to what I wrote above. I said I would extend #112952; I did not. That PR gates The stall half is unchanged and still open: the server accepted and authenticated queries without |
|
Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is just a purity/presentation thing, not a big deal.
`EXPLAIN SYNTAX` now returns the formatted query as a single record (#110479, merged into `master` on 2026-08-18), so the dump appears as one `TSV` row with escaped newlines instead of one row per line. Only the reference of `04823_explain_syntax_nested_view_throwing_table_function_legacy` was still in the old shape; verified locally that the test passes with the updated one.
Closes: #80410
Related: #107925
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
EXPLAIN SYNTAXnow returns the reformatted query as a singleStringrecord (with embedded newlines) instead of one record per line, so its output is a recoverable single row that is directly usable (for example,SELECT count() FROM (EXPLAIN SYNTAX ...)returns1). This is controlled by the newsingle_recordoption, which defaults to1; setsingle_record = 0to restore the historical one-record-per-line output. OtherEXPLAINkinds (PLAN/PIPELINE/AST) keep their per-line tree output.Description
Per the discussion on #80410,
EXPLAIN SYNTAXis a reformatted, copy-pasteable query, so returning the whole query as a single record is far more usable than splitting it across N rows.This is done in two commits:
single_recordoption toEXPLAIN SYNTAX, off by default (no behavior change). The single-record code path already existed (used byEXPLAIN PLANJSON output); this wires it to the new option for theSYNTAXkind and renames the internalsingle_lineflag tosingle_record.single_record = 1. This is backward-incompatible: existingEXPLAIN SYNTAXconsumers now see one row instead of N. Theonelineoption still controls physical-line rendering (default0, i.e. embedded newlines).The affected stateless
.referencefiles (including.oldanalyzer.referencevariants) were regenerated for the new default. Theoptimize_syntax_fuse_functionsdocstring example was switched fromFORMAT TSVtoFORMAT TSVRawso its multi-line output stays literal now that the single record carries the embedded newlines.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/110479]