Skip to content

Cherry pick #122345 to 26.3: Fix LOGICAL_ERROR on lambda over an Array(Tuple(...)) - #123250

Merged
robot-clickhouse merged 10 commits into
backport/26.3/122345from
cherrypick/26.3/122345
Oct 3, 2026
Merged

robot-clickhouse merged 10 commits into
backport/26.3/122345from
cherrypick/26.3/122345

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #122345

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Ergus and others added 9 commits September 25, 2026 22:13
Address review: resolving the view source during analysis applied to every
context carrying it, including the inner query of an ordinary `VIEW`
referenced from the materialized view query. Such a view then read only the
inserted block instead of the whole table. Skip the early resolution when
`isViewInnerQuery` is set, which matches how the inner query of a view
resolved the table before.

Add `05291_mv_ordinary_view_over_source_reads_table` for that case, and make
`05241_mv_insert_alter_source_column_during_insert` wait until the first block
has passed through the view before running the `ALTER`, with more blocks left
after it, so it does not depend on timing on slow builds. Without the fix the
test fails with `Cannot capture column 3 because it has incompatible type`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The `view_source` rewrites of the right-hand side of `IN`
(`resolveFunction`) and of scalar subqueries
(`evaluateScalarSubqueryIfNeeded`) now skip the inner query of an ordinary
view (`isViewInnerQuery`), like the table resolution in
`IdentifierResolver::tryResolveTableIdentifier`. Otherwise an ordinary
view referenced from a materialized view query saw only the pushed block
in those subqueries instead of the table.

Address review: #122345 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…the table

With `analyzer_inline_views = 1`, `QueryAnalyzer::inlineViewSubqueryIfNeeded` resolves the
view body with `StorageView::getViewSubqueryContext`, which did not mark the context as the
inner query of a view, so the body inherited `view_source` and resolved the source table of a
materialized view to the inserted block. Mark that context with `setIsViewInnerQuery`, like
`getViewContext` does for a view that is not inlined.

`replaceStorageInQueryTree` also swapped the storage in every table reference of the join tree,
including those inside an inlined view body. It no longer descends into queries of a view that
is inlined into a query outside of views.

Address review: #122345 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…a materialized view query

`Context::createCopy` preserves `view_source`, so `createLocalPlan` analyzed the local shard of a
`remote` or `Distributed` read inside a materialized view query with the inserted block standing in
for the source table: `(SELECT count() FROM remote('127.0.0.1', db, src))` counted the block, not
the table. Before the early resolution in `IdentifierResolver::tryResolveTableIdentifier`, the swap
was done only on the view query's own tree, so the local shard read the table, like the remote
shards do. Clear the view source in the local shard's context.

New test `05294_mv_source_remote_local_shard_reads_table`: without the fix it prints `0` rows
for both reads, with the fix `10`.

Addresses review: #122345 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Fix LOGICAL_ERROR on lambda over an `Array(Tuple(...))`
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 1, 2026
…to 26.3

Resolve the conflict in `StorageView.cpp` and reconcile the change with 26.3:

- 26.3 does not have `Context::isViewInnerQuery` (added on master by
  #94359, not backported).
  Add the `is_view_inner_query` flag to `Context` and set it in
  `getViewContext` of `StorageView`, so the inner query of an ordinary view
  reads the table itself, not the inserted block of a materialized view.
- 26.3 does not have view inlining in the analyzer
  (`StorageView::getViewSubqueryContext`, `analyzer_inline_views`, from
  #100830). Drop that part
  and the test `05293_mv_ordinary_view_over_source_inlined`.
- Use `QueryNode::getJoinTree` instead of `getJoinTreeNodeTyped`, which
  does not exist in 26.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Resolved the conflicts by merging backport/26.3/122345 and adapted the change to 26.3:

All changed translation units compile against the 26.3 tree (checked with -fsyntax-only). Please review the adaptation before the backport goes ahead.

@robot-clickhouse
robot-clickhouse merged commit 13b7033 into backport/26.3/122345 Oct 3, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.3/122345 branch October 3, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants