Skip to content

Fix qualified matcher resolve with non-compound column clash - #109078

Merged
vdimir merged 3 commits into
masterfrom
vdimir/fix-qualified-matcher-alias-over-column
Jul 13, 2026
Merged

vdimir merged 3 commits into
masterfrom
vdimir/fix-qualified-matcher-alias-over-column

Conversation

@vdimir

@vdimir vdimir commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

  • Fixed an error when using a qualified asterisk like b.* in a query where b is a table (or subquery/CTE) alias that shares its name with a non-compound column of another table. Such queries no longer fail and correctly select all columns of b.

Closes: #82151

Version info

  • Merged into: 26.7.1.854 (included in 26.7 and later)
  • Backported to: 26.6.8.7

vdimir added 2 commits July 1, 2026 14:58
Fixed an error when using a qualified asterisk like `b.*` in a query where `b` is a table (or subquery/CTE) alias that shares its name with a non-compund column of another table. Such queries no longer fail and correctly select all columns of b.
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1dbb590]

Summary: ✅


AI Review

Summary

This PR fixes the qualified-matcher case where b.* should bind to a table alias even when another visible non-compound expression is also named b, and the follow-up commit closes the remaining JOIN USING type-correction path that still re-resolved b.col through aliases / lambda arguments first. The current head adds focused regression coverage for plain joins, USING, scalar WITH aliases, lambda arguments, and the guard where a real compound expression named b must still win. I did not find any unresolved correctness issue in the current diff.

PR Metadata

Changelog category is correct for the change. Changelog entry is required and is specific enough, but it has a typo. Exact replacement: Fixed an error when using a qualified asterisk like b.* in a query where b is a table (or subquery/CTE) alias that shares its name with a non-compound column of another table. Such queries no longer fail and correctly select all columns of b.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 1, 2026
Comment thread src/Analyzer/Resolve/QueryAnalyzer.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.50% +0.00%
Functions 92.60% 92.70% +0.10%
Branches 77.70% 77.70% +0.00%

Changed lines: Changed C/C++ lines covered: 39/40 (97.50%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR is an analyzer-only fix: it changes how a qualified matcher (alias.*) resolves when a column and a table share the same name, affecting query analysis, not execution. None of the flagged ClickBench (Q13/Q14/Q15/Q30) or TPC-H (Q2/Q7/Q8) queries use that construct, so neither the flagged regressions nor the improvements can plausibly be caused by this change. With opposite-direction deltas across benchmarks and only 6 source runs against 30 baseline runs, these are consistent with run-to-run variance, so all flagged queries were downgraded. No actionable performance impact from this change.

clickbench

⚠️ 5 inconclusive

Flagged queries (5 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 13 not_sure 456 514 +12.7% <0.0001 PR only changes qualified-matcher (alias.*) name resolution; Q13 never exercises it. Off-path, run-to-run variance.
⚠️ 14 not_sure 354 402 +13.6% <0.0001 Analyzer-only alias.* fix; Q14 doesn't use qualified matchers. Delta unrelated to this PR.
⚠️ 15 not_sure 239 213 -10.9% <0.0001 Flagged improvement but PR touches only alias.* resolution; Q15 off-path. Likely variance, not a real gain.
⚠️ 30 not_sure 273 315 +15.4% <0.0001 PR is an analysis-time matcher fix; Q30 execution path untouched. Off-path, variance.
⚠️ 32 not_sure 1312 1392 +6.1% 0.0386 Already not_sure; noisy measurements and off-path from this analyzer-only PR.

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

⚠️ 3 inconclusive

Flagged queries (3 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 2 not_sure 76 63 -17.1% <0.0001 Flagged improvement but PR only changes alias.* resolution; Q2 off-path. Not a real PR effect.
⚠️ 7 not_sure 633 535 -15.5% <0.0001 Analyzer-only fix cannot speed up Q7 execution; off-path improvement is run-to-run variance.
⚠️ 8 not_sure 214 168 -21.5% <0.0001 Q8 doesn't use qualified matchers; -21.5% is off-path variance, not caused by this PR.

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 28cf4478-aec6-4535-b838-7286dbbedf6e
  • MIRAI run: 1c37e225-f3d9-4035-a0dd-ca22ed995d6a
  • PR check IDs:
    • clickbench_481944_1783499555
    • clickbench_481950_1783499555
    • clickbench_481956_1783499555
    • tpch_adapted_1_official_481962_1783499555
    • tpch_adapted_1_official_481969_1783499555
    • tpch_adapted_1_official_481980_1783499555

@jkartseva jkartseva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the buffer over-read.

@jkartseva

Copy link
Copy Markdown
Member

Sorry, that^ was from another review.

@jkartseva jkartseva self-assigned this Jul 13, 2026

@jkartseva jkartseva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jkartseva

Copy link
Copy Markdown
Member

s/non-compund/non-compound in the changelog entry

@vdimir
vdimir added this pull request to the merge queue Jul 13, 2026
Merged via the queue into master with commit 8b9a8c2 Jul 13, 2026
174 checks passed
@vdimir
vdimir deleted the vdimir/fix-qualified-matcher-alias-over-column branch July 13, 2026 10:30
@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Fix qualified matcher resolve with non-compound column clash

ClickGap verified: reproduced it with the script below on 26.6; tested 7 version(s) — 6 affected, 1 clean (see Affects); present since the feature was introduced in v24.8 (not a recent regression).

Reproduction

CREATE TABLE t1 (a UInt32, b Float64) ENGINE = MergeTree ORDER BY a;
CREATE TABLE t2 (x UInt32, y String) ENGINE = MergeTree ORDER BY x;
INSERT INTO t1 VALUES (1, 3.14);
INSERT INTO t2 VALUES (1, 'hello');
SET enable_analyzer = 1;
-- `b` also names the scalar column t1.b (Float64); `b.*` must expand the table aliased `b` (t2).
SELECT a, b.* FROM t1 JOIN t2 AS b ON t1.a = b.x ORDER BY a;
-- Before the fix: fails with UNSUPPORTED_METHOD "Qualified matcher b.* found a non-compound expression t1.b with type Float64".
-- After the fix: returns  1  1  hello

▶ Run on ClickHouse Fiddle

Bisect

  • The reproducer requires enable_analyzer, introduced in v24.8 — so this is not pre-existing: it was introduced no earlier than v24.8, and the introducing change is in the 24.8–master range (most likely the change that added the feature). Every release line down to there reproduces.

Affects

  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.6, 26.5, 26.4, 26.3, 26.2, 26.1
  • Does NOT reproduce on: master
  • Backport needed: 26.6, 26.5, 26.4, 26.3, 26.2, 26.1

Suggested next step

The fix has landed on master; the affected release branches above still need the backport.

Component: comp-query-analyzer
Severity: P2


ClickGap · Finding: phase_d_pr109078

Triage metadata

  • Primary component: comp-query-analyzer
  • Secondary components: comp-testing
  • Component owners (comp-query-analyzer): @KochetovNicolai @novikd

@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 13, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.1, 26.2, 26.3, 26.4, 26.5, 26.6. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…fied-matcher-alias-over-column

Fix qualified matcher resolve with non-compound column clash
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 15, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 15, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 15, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 15, 2026
Backport #109078 to 26.6: Fix qualified matcher resolve with non-compound column clash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DB:Exception: Qualified matcher reservation.* found a non-compound expression

6 participants