Skip to content

Fix identifier resolution when a table has the same name as its database - #110976

Merged
alexey-milovidov merged 30 commits into
masterfrom
fix-table-same-name-as-database
Aug 10, 2026
Merged

alexey-milovidov merged 30 commits into
masterfrom
fix-table-same-name-as-database

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 19, 2026 •

Copy link
Copy Markdown
Member

Closes: #82084

When a table has the same name as the database it is in (e.g. db1.db1), the analyzer could not resolve fully qualified column names: SELECT db1.db1.id FROM db1.db1 failed with UNKNOWN_IDENTIFIER. The first part of the identifier was bound to the table name, resolution of the rest (db1.id) as a column failed, and an exception was thrown without attempting the other interpretations of the identifier. The same problem affected the qualified matcher (SELECT db1.db1.* FROM db1.db1), subcolumn access (SELECT db1.db1.t.x FROM db1.db1), and fully qualified column names of other tables joined with such a table (SELECT db1.tbl.id FROM db1.db1 JOIN db1.tbl USING (id)). All these queries work with the old infrastructure (enable_analyzer = 0).

Now, when the identifier first part also matches the database name, resolution with a single-part qualifier is allowed to fail, and the remaining interpretations are attempted next: qualification with the database name and the table name, or resolution from another table expression.

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):

Fixes the resolution of fully qualified column names such as db.table.column in the analyzer for tables that have the same name as their database. Closes #82084.

Version info

  • Merged into: 26.8.1.1149 (included in 26.8 and later)

When a table has the same name as the database it is in (e.g. `db1.db1`),
the analyzer could not resolve fully qualified column names:
`SELECT db1.db1.id FROM db1.db1` failed with `UNKNOWN_IDENTIFIER`.
The identifier first part was bound to the table name, resolution of the
rest of the identifier as a column failed, and an exception was thrown
without attempting the other interpretations of the identifier. The same
problem affected the qualified matcher, subcolumn access, and fully
qualified column names of other tables joined with such a table.

Now, when the identifier first part also matches the database name,
resolution with a single-part qualifier is allowed to fail, and the
remaining interpretations are attempted next: qualification with the
database name and the table name, or resolution from another table
expression.

Closes #82084

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov requested a review from novikd July 19, 2026 07:38
@clickhouse-gh

clickhouse-gh Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aeb923e]

Summary: ✅


AI Review

Summary

This PR fixes analyzer resolution for db.table.column when the first token can also bind as a table name, alias, or materialized CTE name, and extends that behavior through qualified matchers, analyzer_compatibility_prefer_alias_over_subcolumn, forced qualification under multiple joins, correlated subqueries, and the identifier-resolve cache. I reviewed the current head, the full diff, and every existing review thread/reply; the earlier resolver gaps raised during review are covered by the follow-up code and focused regressions, and I did not find any remaining correctness issues in the final state.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.90% +0.10%

Changed lines: Changed C/C++ lines covered: 140/168 (83.33%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 19, 2026
alexey-milovidov and others added 2 commits July 19, 2026 22:14
The fix is analyzer-only; the queries already succeed with the old
infrastructure (`enable_analyzer = 0`). Force `SET enable_analyzer = 1`
at the top of the test so it always exercises the resolver change in
`IdentifierResolver`, per review feedback from `clickhouse-gh`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed the AI review / clickhouse-gh feedback: added SET enable_analyzer = 1; at the top of 04612_table_same_name_as_database.sql so the regression test always exercises the analyzer-only resolver change in IdentifierResolver (the queries already succeed with enable_analyzer = 0). Verified locally that the test output still matches the reference with the freshly built binary.

Also merged master to bring the branch current. The previous CI reds are unrelated to this change:

…st part is a database name anywhere in scope

The `can_be_not_found` gate only triggered when the identifier first part
matched the current table expression's own `database_name`. When the first
part matches the name of one table expression while being the database name
of a different table expression in the same scope (a table named like
another database), the single-part qualifier lookup still threw
`UNKNOWN_IDENTIFIER` before the database-qualified interpretation could be
attempted. Check the database names of all table expressions in the scope
instead, and extend `04612_table_same_name_as_database` with this shape.

Note: the review's alias example (`FROM (SELECT 1 AS id) AS db1 JOIN
db1.other`) is not resolvable by the old analyzer either — the alias
shadows the database name during table expression resolution — so only the
table-name carrier is reachable and covered.
… `analyzer_compatibility_prefer_alias_over_subcolumn`

When `analyzer_compatibility_prefer_alias_over_subcolumn = 1`, `tryResolveIdentifierFromJoin`
restricts resolution to the JOIN side whose table name or alias matches the first identifier part.
`qualifierBindsToJoinSubtree` did not consider that the same token can be the `database_name` of
the other side, so for `SELECT db1.tbl.value FROM db1.db1 JOIN db1.tbl USING (id)` the right
subtree was pruned and the `db.table.column` interpretation was never attempted.

Now a leaf table expression also binds the qualifier when it matches its `database_name`,
but only for identifiers with at least three parts, since a database-qualified column
reference needs `db.table.column`. `04612_table_same_name_as_database` is extended with
both join shapes under the setting.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110976&sha=77008ff44e53b9a94ebe60e1a8860e9adebf528f&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%201%2F6%29 (test_backup_restore_on_cluster/test_concurrency.py::test_kill_mutation_during_backup — Sanitizer assert found for instance zoo2-1) and provide a fix in a separate PR. If the fix is already in progress, link it here. The failure is unrelated to this PR, which only changes identifier resolution in the analyzer and a stateless test.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed unrelated to this PR. test_kill_mutation_during_backup itself PASSED; the error is raised at module teardown. The start_cluster fixture in test_concurrency.py calls cluster.shutdown(), which greps the container logs for the sanitizer banner and attributes it to zoo2-1, so it attaches to whichever test happened to run last in the module.

The banner is a genuine TSAN report in Keeper (zoo2-1), in the lock-free response queue, not in analyzer code:

  • Read (T14): NonblockingBoundedQueue<KeeperResponseForSession>::tryPop -> move-assign at KeeperCommon.h:51, from KeeperRequestDispatcher::responseThread (KeeperRequestDispatcher.cpp:1153).
  • Previous write (T31): the same move-assign via tryPush, from the commit path (KeeperStateMachine::commit -> onResponse, KeeperRequestDispatcher.cpp:420).

A fix is already in progress by @ al13n321: #107083 "Suppress TSAN error in NonblockingBoundedQueue" (follow-up to the closed #106801). It marks tryPush/tryPop NO_SANITIZE_THREAD; the acquire/release on slot.pos already establishes happens-before (isomorphic to Vyukov's queue), so this is a TSAN false positive on the plain slot.value accesses. No separate PR needed from me.

…related identifiers

Resolution from a parent scope (a correlated identifier) is attempted only after the
current scope returns no result, so `identifier_first_part_is_database_name_in_scope`
must also account for tables of parent scopes: an inner table named like a database that
exists only in the parent scope (e.g. `SELECT (SELECT count() FROM db2.db1 WHERE ...) FROM db1.tbl`)
threw `UNKNOWN_IDENTIFIER` from `tryResolveIdentifierFromStorage` before the outer
`db1.tbl.column` interpretation could be tried. Walk the parent scopes in the
`can_be_not_found` gate and add a correlated regression test.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The only CI red on 9d9c0c0 is 04507_mvt_encode_state_serialize (Stateless amd_llvm_coverage, ParallelReplicas, s3 storage) — unrelated to this PR (it is an AggregateFunction state-serialization test failing under parallel replicas). A fix is already in progress: #111148.

@novikd novikd self-assigned this Jul 21, 2026
alexey-milovidov and others added 3 commits July 21, 2026 18:49
…first identifier part is a database name in scope

A materialized CTE can have the same name as a database. When resolving a
fully qualified `db.table.column`, if the first identifier part matched a
materialized CTE named like the database, the `isMaterializedCTE` branch
retried the one-part qualifier with `can_be_not_found = false` and threw before
the `db.table.column` interpretation could reach the real table in that
database.

Make that branch honor `identifier_first_part_is_database_name_in_scope` the
same way the table-name / alias branch above it does: allow the lookup to fail
and fall through so the database-qualified interpretation is attempted next.

Repro (previously threw `UNKNOWN_IDENTIFIER`):

    CREATE DATABASE db1;
    CREATE TABLE db1.tbl (id Int32, value Int32) ENGINE = Memory;
    WITH db1 AS MATERIALIZED (SELECT 42 AS id)
    SELECT db1.tbl.value FROM db1 JOIN db1.tbl USING (id)
    SETTINGS enable_analyzer = 1, enable_materialized_cte = 1;

Extended `04612_table_same_name_as_database` with the materialized-CTE shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ed-CTE case to a `.sh` test

The materialized-CTE-named-like-a-database query used a query parameter
(`{CLICKHOUSE_DATABASE:Identifier}`) as the CTE name, but the parser does
not accept a query parameter in the CTE-name position of a `WITH` clause
(`ParserWithElement` uses `ParserIdentifier` with `allow_query_parameter = false`),
so the query failed to parse with `SYNTAX_ERROR` at the CTE subquery's opening
bracket. Because that query is run in the middle of the multi-query `.sql` test,
it aborted the whole test - and, since #110976 is a bug-fix PR, it also left the
per-arch Bugfix Validation jobs with nothing to validate.

Move that single scenario into a companion shell test
`04613_materialized_cte_same_name_as_database.sh`, where the database name is
substituted into the query text by the shell so the CTE name is a literal
identifier, and drop the corresponding line from the `.sql` reference.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110976&sha=4520626d0f3e701c53f0488bc2cce53c925b5672&name_0=PR&name_1=Fast%20test
…didate

The retry after a failed lookup behind a table name (or a materialized CTE
name) was keyed only to the first identifier part matching any database
name in scope, so it also fired when no database-and-table interpretation
existed: a two-part `db.x` against the table `db.db` could fall through
and resolve a sibling column literally named `db.x` instead of throwing
`UNKNOWN_IDENTIFIER`.

Allow the lookup to fail only when some table expression in this scope or
in a parent scope is the table `identifier[1]` inside the database
`identifier[0]` (for a two-part identifier that interpretation is the
table itself, e.g. a matcher qualifier `db.db.*`; for three and more
parts it is `db.table.column`). The same gate applies to the
materialized-CTE branch. Add `04614_two_part_identifier_table_same_name_as_database`
covering the two-part and three-part dotted-column shapes.

Addresses the AI review blocker.

Co-Authored-By: Claude Fable 5 <[email protected]>
…review

A plain two-part identifier such as `db.db` selected from the table `db.db` has no
expression-level `db.table.column` interpretation (the database-and-table interpretation is
the table expression itself, not a column), so a failed qualifier lookup must throw
`UNKNOWN_IDENTIFIER` as before instead of falling through and letting a sibling column
literally named `db.db` win. The only context that needs the two-part miss to fall through
is the qualifier of a qualified matcher (`db.db.*`), which is resolved as an expression
first and then as a table expression: such lookups are now marked with
`IdentifierLookup::is_matcher_qualifier`.

Also address review comments from novikd:
- The database-and-table candidate check is no longer computed for every table expression
  analysis: the qualifier lookup always runs with `can_be_not_found = true` first, and the
  scope-chain scan runs lazily, only after a failed lookup. When no candidate exists, the
  lookup is repeated with `can_be_not_found = false` to throw the proper exception.
- `qualifierBindsToJoinSubtree` takes the identifier instead of a
  `qualifier_can_be_database_name` flag and binds a leaf on its database name only when the
  table name also matches the second identifier part.
- The `identifier_first_part_matches_database_name` flag declared far from its single use is
  inlined into the condition.

Extended `04614_two_part_identifier_table_same_name_as_database` with the two-part
`db.db` sibling-column regression and the qualified-matcher shape that must keep working.
…t a competing binding

Under `analyzer_compatibility_prefer_alias_over_subcolumn = 1`, `qualifierBindsToJoinSubtree`
treated a database-qualified match (`db.table.column` against a side's database and table names)
as an equal competitor to an alias / table-name match on the other side. When the lookup behind
the table-name qualifier succeeded (a real Tuple subcolumn), both sides resolved and the query
threw `AMBIGUOUS_IDENTIFIER` instead of honoring the precedence the setting establishes:
`SELECT db1.tbl.value FROM default.db1 JOIN db1.tbl USING (id)` with `default.db1` having a
column `tbl Tuple(value Int32)`.

The database-qualified binding is now attempted only when the alias / table-name pruning
restricted resolution to one side and that side produced no result. Extended
`04612_table_same_name_as_database` with the successful-subcolumn shape.

Addresses the AI review finding in #110976
…in JOIN-side pruning

Under `analyzer_compatibility_prefer_alias_over_subcolumn = 1`, `qualifierBindsToJoinSubtree`
matched only aliases and table names, and a materialized CTE is registered in
`table_expression_node_to_data` under its internal temporary table name. The visible
`cte_name` therefore never bound as a qualifier, so for
`WITH db1 AS MATERIALIZED (...) SELECT db1.tbl.value FROM db1 JOIN db1.tbl USING (id)`
both JOIN sides were searched, and when the CTE side resolved the identifier the
database-qualified side competed with it, ending in `AMBIGUOUS_IDENTIFIER`
(observable with `single_join_prefer_left_table = 0`; the default silently preferred
the left side). Now the CTE name binds like a table name, resolution is pruned to the
CTE side, and the database-qualified interpretation stays a miss-only rescue.

Extended `04613_materialized_cte_same_name_as_database.sh` with the shape (a column
literally named `tbl.value` rather than a Tuple subcolumn, because selecting a Tuple
subcolumn out of a materialized CTE through a JOIN hits a pre-existing planner
limitation - `NOT_FOUND_COLUMN_IN_BLOCK`, reproducible on 26.7 with a collision-free
CTE name - that is unrelated to identifier resolution).

Co-Authored-By: Claude Fable 5 <[email protected]>
… name

`tryBindIdentifierToTableExpression` recognized only `table_expression_data.table_name`, the alias
and `database.table`. A materialized CTE is registered under an internal temporary table name, so
the binder did not see a CTE named like a table:

- a matcher-expanded column of another table expression stopped one qualification step too early
  (`tbl.id` instead of `db.tbl.id`, colliding with the CTE's own qualified name), and
- a qualifier matching both a materialized CTE and a table was not reported as ambiguous, so
  `tbl.*` silently picked the table, unlike the same query with a regular CTE.

The CTE name is now accepted there as well, both for table expression lookups and for the generic
multi-part binding. Regression tests added to
`04613_materialized_cte_same_name_as_database.sh`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

CI triage for f1f800d — all three failures are unrelated to this PR (it only touches analyzer identifier resolution):

@groeneai, could you investigate the AST fuzzer double-free (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110976&sha=f1f800dd52062e379a722146b714f740fdbab393&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29) and provide a fix in a separate PR? If a fix is already in progress, please link it here. There is no tracking issue for it yet.

Also pushed: the round-12 review fix (materialized CTE visible name in tryBindIdentifierToTableExpression) and a master merge.

@groeneai

Copy link
Copy Markdown
Collaborator

Yes, a fix is in progress, and it is not the PR you found: #111622 (open, mine).

Mechanism. ReadFromMergeTree::initializePipeline replaces the snapshot data in place:

if (enable_remove_parts_from_snapshot_optimization || query_info.isStream())
{
    ...
    storage_snapshot->data = std::move(stripped_snapshot_data);   // master, ReadFromMergeTree.cpp:4060
}

DirectJoinMergeTreeEntity::getByKeys is const and runs on every JoiningTransform lane concurrently. Each lane clones lookup_plan, and ReadFromMergeTree::clone copies storage_snapshot as a shared shared_ptr, so two lanes unique_ptr::reset the same StorageSnapshot::Data. That is the 56-byte region in your report, and it is why the double-freeing thread (T270) and the freeing thread (T277) have byte-identical stacks.

PlannerJoinTree already tries to prevent exactly this by calling disableMergeTreePartsSnapshotRemoval on the lookup step (PlannerJoinTree.cpp:2378, comment "initializePipeline is done multiple times concurrently, so not to remove parts snapshot"). It is insufficient: the guard above is erpfso || query_info.isStream(), so a STREAM right table re-arms the strip regardless, and the fuzzer arms it for ordinary shapes by drawing enable_shared_storage_snapshot_in_query = 0. #111622 changes that one line to storage_snapshot = storage_snapshot->clone(std::move(stripped_snapshot_data)), so the step rebinds its own member instead of mutating an object other lanes still hold.

The reproduction of this exact STID is already on record in #111622's CI rather than asserted. Its Bugfix validation (functional tests, aarch64) run on fc640c09fae220299acfc1802b97c44ae27a2c73 executes only the new test 04545_direct_join_stream_mergetree_added_column, first against the master-HEAD arm_asan_ubsan build (REFs/master/500c68df3825bae672007f575bd958ffe7c4db51/build_arm_asan_ubsan), and that master server died with AddressSanitizer: attempting double-free, the frame chain ReadFromMergeTree::initializePipeline -> ISourceStep::updatePipeline -> QueryPlan::buildQueryPipeline -> DirectJoinMergeTreeEntity::executePlan -> getByKeys, and STID 3942-460f. The reported site there is ReadFromMergeTree.cpp:3968, which is precisely where storage_snapshot->data = std::move(...) sits in 500c68df3825ba; it is :3979 in your f1f800dd5206 and :4060 on master today, pure churn in that file. The same test passes on the PR build under arm_asan_ubsan (5/5 targeted, plus azure parallel, plus 5/5 amd flaky check), so that job is a red-on-master / green-on-PR demonstration under ASan.

45-day CIDB has three rows for the STID: master 6b5099c5 on 07-18, that master-HEAD validation arm on 07-24, and your f1f800dd5206 on 07-28. Neither PR is merged and master still carries the in-place assignment, so recurrence on unrelated PRs is expected until one lands.

On #109932, which you named: it fixes the shared PrewhereInfo facet of the same concurrent-lookup family, and it additionally gives each clone its own snapshot. That removes the sharing for clone-produced steps only, not for ReadFromMergeTree instances built through the constructor. Both PRs touch this function, so instead of opening a third PR I will reconcile the two: keep the strip-site rebind from #111622 as the general fix and drop the now-redundant snapshot hunk from #109932, leaving that PR with the PREWHERE fix.

No action needed on the other two failures, both attributions look right to me.

I have not filed a tracking issue; the analysis lives on #111622. Happy to open one if you prefer it tracked separately.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

CI triage for 311c0e10d7d — both reds are unrelated to this PR (it only touches analyzer identifier resolution):

Merged master (1142 commits behind); the merge was clean and touched no identifier-resolution code, and both changed translation units (IdentifierResolver.cpp, QueryAnalyzer.cpp) compile against the merged tree.

The only remaining unresolved thread is @novikd's CTE-priority design question, which is his call.

…-as-database

# Conflicts:
#	src/Analyzer/Resolve/IdentifierResolver.cpp
…lity path

Address review: under `analyzer_compatibility_prefer_alias_over_subcolumn = 1`,
`tryResolveIdentifierFromTableExpression` took the alias-prefix strip path only when the first
identifier part matched `table_expression_data.table_name` or the table expression alias. A
materialized CTE is stored under an internal temporary table name, so its visible CTE name never
matched and the compatibility path was never taken for it.

As a result `WITH cte AS MATERIALIZED (SELECT 1 AS id, CAST(tuple(2), 'Tuple(id Int32)') AS cte)
SELECT cte.id FROM cte` preferred the `id` element of the CTE column `cte` over the qualified
column `id`, while the same shape with a regular CTE or a subquery alias preferred the qualified
column. In this particular shape the subcolumn interpretation is not even executable and the query
failed with `NOT_FOUND_COLUMN_IN_BLOCK`.

The visible `getMaterializedCTE()->cte_name` is now accepted there as a third qualifier carrier,
matching the other places in this file where a materialized CTE is addressable by its CTE name.

Extended `04613_materialized_cte_same_name_as_database.sh` with the alias-vs-subcolumn shape and
with the regular-CTE baseline it has to match.
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 127/141 (90.07%) · Uncovered code

Full report · Diff report

alexey-milovidov and others added 2 commits August 7, 2026 22:20
Address review: the `analyzer_compatibility_multiple_joins_qualify_column_names`
forced-qualification branch of `qualifyColumnNodesWithProjectionNames` still used
`getTemporaryTableName` for a `TableNode` backed by a materialized CTE, so with two
or more JOINs the matcher expansion leaked the internal temporary table name
(`_materialized_cte_cte_<random>.k`) into projection names, and an outer reference
such as `cte.Date` over such a subquery threw `UNKNOWN_IDENTIFIER`. The branch now
uses `getMaterializedCTE()->cte_name`, the same as the normal qualification path.

Extended `04613_materialized_cte_same_name_as_database.sh` with the outer-reference
shape, its regular-CTE baseline, and a `TSVWithNames` header check.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI triage for 9413b0d (report): all three failures are unrelated to this PR (analyzer identifier resolution).

None of these have a fix merged into master yet, so there is nothing to pull in by re-merging (the branch merged master yesterday).

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Both failures you flagged for me already have an open fix PR, and you are right that neither is merged, so there is nothing to pull in by re-merging.

test_keeper_dynamic_log_level::test_adjust_log_level (Integration tests, amd_msan 4/8)

The failing row is the assert 0 >= 1 on the <Trace> grep. The fix is your own PR: #113571 (open, 08-05), which replaces the fixed time.sleep(3) with wait_condition polling because ConfigReloader::run only re-reads the config after config_reload_interval_ms.

One thing worth flagging: there is a second open PR of yours for the same test and the same root cause, #113938 (08-08, "poll for the log level change"). Neither references the other, so one is likely redundant.

My own measurement matches your figures: 24 failing rows across 24 distinct PRs on 08-07, 20 rows across 19 PRs plus one master run on 08-06, and 9 rows so far on 08-08. I am not opening a duplicate.

joinPipelinesYShaped "one output port, got 3 and 1" (Stress test, arm_tsan)

This row is STID 4488-4e11, and the fix in progress is mine: #109393 (open since 07-04, awaiting review).

The stack frame is QueryPipelineBuilder.cpp:374 in joinPipelinesYShaped, which is still the unpatched else if on master, and that is exactly the line #109393 replaces. JoinStep::updatePipeline computes use_sharding = !primary_key_sharding.empty() && getNumStreams(left) == getNumStreams(right), so when sharding is planned but the two sides end up with different stream counts at build time, it falls back to joinPipelinesYShaped, which required exactly one stream per side and so raised a logical error (an abort in debug and sanitizer builds). #109393 merges the diverging streams with a MergingSortedTransform on the join keys instead.

Over the last 30 days I measure 19 rows across 19 distinct PRs for 4488-4e11, plus 15 more rows for two sibling STIDs of the same message family (4488-4a91, 4488-4590), all on PRs and none on master in that window. The varying port counts (1 and 8, 1 and 4, 3 and 1 here) are just the stream counts at build time, so they do not indicate separate defects.

#109393 is currently 5715 commits behind master, so I will rebase it and re-run CI to get it back into a reviewable state.

@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing aeb923ed9 with master e493bf79b (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 2b2987cc1; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.67 MiB 687.65 MiB -3.02 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

23 translation units recompiled, 125 s compile time in total, 23 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.92 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -13.1 s (-10%) in total before that adjustment.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI triage for 561948e (report): the only two reds are both AST fuzzer (amd_debug, targeted) hitting the same known unrelated exception — Cannot serialize FutureSetFromSubquery with no query plan over merge() with optimize_inverse_dictionary_lookup = 1 (plan-based parallel replicas over a Merge table). Tracked in #112848, fix in progress in #112849 (still open, so there is nothing to pull in by re-merging master). This PR only touches analyzer identifier resolution and stateless tests. The AI review verdict on this head is ✅ "No new findings"; everything else is green.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't like the complications, but all the feedback has been addressed.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Aug 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 10, 2026
Merged via the queue into master with commit 3e334cf Aug 10, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-table-same-name-as-database branch August 10, 2026 23:38
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 11, 2026
@novikd novikd added the post-rejected Should've been rejected, but got merged. label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-rejected Should've been rejected, but got merged. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identifier resolution error in select when table has same name as database

4 participants