Repository navigation
Closed
Labels
analyzerIssues and pull-requests related to new analyzerbugConfirmed user-visible misbehaviour in official releasecomp-query-analyzerSemantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules).
Description
Company or project name
https://www.innervate.com/
Describe what's wrong
query fails with the enabled analyzer
Does it reproduce on the most recent release?
Yes
How to reproduce
CREATE TABLE test
(
x String,
xx String alias concat(x, 'aaa')
)
ENGINE = MergeTree
ORDER BY x as SELECT 'x';
SELECT x, xx
FROM remote('127.0.0.{1,2}', default, test)
ORDER BY x ASC;
┌─x─┬─xx───┐
1. │ x │ xaaa │
2. │ x │ xaaa │
└───┴──────┘
SELECT now(), x, xx --- now()
FROM remote('127.0.0.{1,2}', default, test)
ORDER BY x ASC;
DB::Exception: Cannot parse datetime: Cannot parse DateTime from String
SELECT
generateUUIDv4(), x, xx
FROM remote('127.0.0.{1,2}', default, test)
ORDER BY x ASC;
DB::Exception: Cannot parse uuid xaaa: Cannot parse UUID from String:
set enable_analyzer=0;
┌───────────────now()─┬─x─┬─xx───┐
1. │ 2026-02-24 21:18:55 │ x │ xaaa │
2. │ 2026-02-24 21:18:55 │ x │ xaaa │
└─────────────────────┴───┴──────┘
┌─generateUUIDv4()─────────────────────┬─x─┬─xx───┐
1. │ ca6fff7e-5b62-4361-8139-71ada17d9e63 │ x │ xaaa │
2. │ 344003a7-b043-44d3-ad3b-741ef8c40cca │ x │ xaaa │
└──────────────────────────────────────┴───┴──────┘
Expected behavior
No errors
Error message and/or stacktrace
No response
Additional context
No response
Version info
- Resolved by: fix column order for distributed alias columns #107675
- Merged into:
26.7.1.245(included in26.7and later) - Backported to:
26.6.2.46,26.5.6.28,26.4.5.115,26.3.17.34,25.8.29.10
Metadata
Metadata
Assignees
Labels
analyzerIssues and pull-requests related to new analyzerbugConfirmed user-visible misbehaviour in official releasecomp-query-analyzerSemantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules).
Activity
spider-yamet commentedon Feb 25, 2026
@den-crane @Algunenano May I open a PR for this?
den-crane commentedon Feb 25, 2026
Yes, please. As this is an open-source project, you have the same privileges as all contributors, so you’re welcome to proceed without requesting prior approval.
den-crane commentedon Feb 25, 2026
it seems there is a silly workaround, create a column without alias against distributed table.
KochetovNicolai commentedon Feb 27, 2026
A bit smaller example: https://fiddle.clickhouse.com/8251d476-b408-4898-bb91-1dc240e7ff9c
Looks like it was always broken.
UnamedRus commentedon Feb 28, 2026
Isn't it essentially the same #88276 ?
But, it should have been fixed by Misha. #94644 (but prev example still broken in master)
fm4v commentedon Jun 15, 2026
@groeneai please fix
vdimir commentedon Jun 15, 2026
@groeneai check if issue is fixed by github.com//pull/106404
clickgapai commentedon Jun 15, 2026
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
TL;DR
Errors with alias columns and distributed tables and functions
ClickGap verified: reproduced it with the script below on
master; tested 6 version(s) — 6 affected, 0 clean (see Affects); confirmed it predates the oldest available release (pre-existing).Reproduction
▶ Run on ClickHouse Fiddle
Bisect
v24.8.14.39— reproduces on every release line tested down to there; the introducer predates the oldest release with a downloadable binary, so a single commit isn't pinnable from release binaries (not a recent regression).Affects
master, 26.5, 26.4, 26.3, 26.2, 26.1Suggested next step
Manual triage of the
comp-query-analyzerpath is needed. The reproducer above should be a fast first check.Component:
comp-query-analyzerSeverity:
P2ClickGap · Finding:
h_issue_97899Triage metadata
comp-query-analyzercomp-distributedcomp-query-analyzer): @KochetovNicolai @novikdgroeneai commentedon Jun 15, 2026
@fm4v root cause found, deterministic repro on master (26.6.1, debug build). @vdimir (assignee) could you confirm the fix layer before I open a PR?
The alias value is misrouted by a position-based header rename, not by alias inlining.
Trigger (all required):
enable_analyzer=1, 2+ shards,ORDER BYpresent, and a non-storage function column (now(),rand(),generateUUIDv4()) placed before a plain column and itsALIAScolumn. Single shard, noORDER BY, or the function placed last all work.rand()fails the same way, so this is not constant-specific.For a remote read at
WithMergeableState,getQueryPlanForTableExpression(src/Planner/PlannerJoinTree.cpp, theelse if (!is_trivial_count_applied)branch around line 1583) inserts a rename from theReadFromRemoteplan header to the outer planner's expected header usingActionsDAG::MatchColumnsMode::Position. The two headers are in different column orders:Position matching pairs the shard's
concat(x,'aaa')(String "xaaa") with thenow()slot and emits_CAST(concat(x,'aaa'), DateTime), i.e. parse "xaaa" as DateTime -> CANNOT_PARSE_DATETIME.EXPLAIN actions=1confirms:FUNCTION _CAST(concat(__table1.x, 'aaa') :: 2, DateTime :: 4)and finalPositions: 0 4 5. Soxx's value lands in the function column's slot.The divergence: the read plan emits the alias column after the function column, the outer planner emits it before. Position was chosen here (the PR #94644 region) because constant columns like
now()/randConstant()get value-dependent action-node names that differ between the two planner runs, so a pure Name match would break on those.Two fix layers I see:
getColumnIdentifierOrNullmap already used a few lines above), falling back to position only for the value-dependent constant columns, instead of pure Position.ReadFromRemoteplan emit columns in the order the outer planner expects when an alias column coexists with a function column.I lean toward (1) as the more contained change, but it is in a core analyzer + distributed path you own, so I would rather confirm the direction first. Which layer do you prefer? I have the reproducer ready and will add a
tests/queries/0_statelessregression covering now()/rand()/generateUUIDv4 over a 2-shard remote with an alias column. This is distinct from #94644 (alias-vs-alias order) and #88276.groeneai commentedon Jun 15, 2026
@vdimir #106404 does not fix #97899. Re-tested on master including #106404 (eb2c089): the three queries still fail identically.
On the same binary, #106404's own scenarios now pass (
SELECT a1, toString(x)andSELECT a1, a1over the distributed table), so it is a distinct bug: #106404 fixes the shard-side output-name dedup inbuildQueryTreeDistributed, while #97899 is the initiator-side header rename.EXPLAIN header=1is unchanged.ReadFromRemoteemits[__table1.x, _CAST(now())::DateTime, concat(x,'aaa')::String], but the "Change remote column names to local column names" step (PlannerJoinTree.cpp:1583,MatchColumnsMode::Position) expects[__table1.x, __table1.xx::String, _CAST(now())::DateTime]. Position pairs the shard'sconcat(x,'aaa')("xaaa") with thenow()slot.Which fix layer do you prefer:
getColumnIdentifierOrNullmap used just above), falling back to Position only for the value-dependent constant columns.ReadFromRemoteplan emit columns in the outer planner's expected order when an alias column coexists with a function column.Reproducer and a now()/rand()/generateUUIDv4 regression test are ready.
1 remaining item
groeneai commentedon Jun 15, 2026
Opened #107514 implementing option (2): the local/
ReadFromRemoteplan columns are reordered to the outer planner's expected order before theMatchColumnsMode::Positionconvert inPlannerJoinTree.cpp, so the shard's alias value is no longer paired with the function column slot.Verified both directions on Build-ID-checked debug builds (2-shard
remote('127.0.0.{1,2}', ...)): the repro fails before the change and passes after, with correct values. The new test04339_distributed_alias_column_with_functioncovers now()/rand()/generateUUIDv4(), the silent wrong-result UInt32 case, and several alias/function interleavings.One separate, pre-existing issue surfaced while testing:
SELECT a1, a1 FROM remote(...) ORDER BY x(duplicate alias, no plain column in the projection) throws NUMBER_OF_COLUMNS_DOESNT_MATCH on both patched and unpatched master, so it is a distinct size-mismatch bug outside this position-reorder fix. Left for a follow-up unless you'd prefer it folded in here.@vdimir review please.
Fix wrong results for alias columns with functions over distributed t…
Fix wrong results for alias columns with functions over distributed t…
Fix wrong results for alias columns with functions over distributed t…
Add now/generateUUIDv4/rand regression cases to 04339
vdimir commentedon Jun 17, 2026
@groeneai check that this issue is fixed by #107675
groeneai commentedon Jun 17, 2026
Confirmed, #107675 fixes #97899.
Verified its
ActionsChain.cppchange in isolation on clean master (eb2c089, debug), 2-shardremote('127.0.0.{1,2}', ...)withenable_analyzer=1+ORDER BY:now()-> CANNOT_PARSE_DATETIME,generateUUIDv4()-> CANNOT_PARSE_UUID,rand()-> CANNOT_PARSE_TEXTAlso correct on the harder shapes: the silent wrong-result
UInt32case, two-alias-two-function, thetoDateTime(...) AS f/7 AS fconstants, andax+1000 AS f, a, ay-> 1107, 7, 207. That last one (a function referencing an alias) is the case my #107514 only handled via the positional fallback, so #107675 is the more general fix. Closing #107514 in favor of it.