Skip to content

Revert "Revert "Fix LOGICAL_ERROR for reused materialized CTE filtered by IN over another materialized CTE"" - #106796

Merged
novikd merged 2 commits into
masterfrom
revert-106795-revert-105041-fix-mat-cte
Jun 9, 2026
Merged

novikd merged 2 commits into
masterfrom
revert-106795-revert-105041-fix-mat-cte

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Reverts #106795

Version info

  • Backported to: 26.5.3.13, 26.4.5.14

@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b951368]

Summary: ❌

job_name test_name status info comment
BuzzHouse (arm_asan_ubsan) FAIL
Logical error: Mutation of Memory table produced incomplete output: A (STID: 2380-3043) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR restores the materialized CTE planner/runtime fix that was reverted, including the two-pass CTE materialization resolution, runtime-set safety-net stripping, lazy MaterializingCTETransform initialization for EXPLAIN, and focused stateless coverage for reused/nested materialized CTEs. I did not find a new correctness, safety, or performance issue in the restored code.

Missing context / blind spots
  • ⚠️ I could not run the added stateless tests locally because this checkout has no usable build directory or clickhouse binary; the PR checks were still pending during review. Passing the added materialized CTE tests in CI would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 9, 2026
The test `04295_04278_materialized_cte_in_union_runtime_set` failed
reproducibly (3/3 reruns) only in the
`Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel)`
configuration, with:

  Code: 60. UNKNOWN_TABLE: Unknown table expression identifier
  '_materialized_cte_ct_<hash>' in scope
  SELECT __table2.b AS b FROM _materialized_cte_ct_<hash> ...
  : While executing Remote.

A materialized CTE's temporary `StorageMemory` is created only on the
initiator. With parallel replicas enabled, the `IN (... UNION ALL ...)`
runtime-set subquery that references the CTE is shipped to the replicas
as part of the remote query. The replicas re-analyze it but have no such
temporary table registered, so resolution fails in `QueryAnalyzer`
during `initializeQueryJoinTreeNode`.

This is a pre-existing limitation of materialized CTEs under parallel
replicas (the storage is not sent to replicas for non-GLOBAL runtime
sets), independent of the planner fix this test guards. Exclude the test
from parallel-replicas runs.

CI history (failures only in the ParallelReplicas config):
https://play.clickhouse.com/play?user=play#V0lUSAogICAgOTAgQVMgaW50ZXJ2YWxfZGF5cwpTRUxFQ1QKICAgIHRvU3RhcnRPZkRheShjaGVja19zdGFydF90aW1lKSBBUyBkYXksCiAgICBjb3VudCgpIEFTIGZhaWx1cmVzLAogICAgZ3JvdXBVbmlxQXJyYXkocHVsbF9yZXF1ZXN0X251bWJlcikgQVMgcHJzCkZST00gY2hlY2tzCldIRVJFIHRlc3RfbmFtZSA9ICcwNDI5NV8wNDI3OF9tYXRlcmlhbGl6ZWRfY3RlX2luX3VuaW9uX3J1bnRpbWVfc2V0JwogICAgQU5EIHRlc3Rfc3RhdHVzIElOICgnRkFJTCcsICdFUlJPUicpCkdST1VQIEJZIGRheQpPUkRFUiBCWSBkYXkgREVTQwo=

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.50% 84.60% +0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.20% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 177/201 (88.06%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@novikd novikd self-assigned this Jun 9, 2026
@novikd
novikd added this pull request to the merge queue Jun 9, 2026
@novikd novikd added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jun 9, 2026
Merged via the queue into master with commit c2f22e4 Jun 9, 2026
164 of 166 checks passed
@novikd
novikd deleted the revert-106795-revert-105041-fix-mat-cte branch June 9, 2026 15:40
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 9, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 9, 2026
robot-ch-test-poll1 added a commit that referenced this pull request Jun 9, 2026
Cherry pick #106796 to 26.4: Revert "Revert "Fix LOGICAL_ERROR for reused materialized CTE filtered by IN over another materialized CTE""
robot-clickhouse added a commit that referenced this pull request Jun 9, 2026
…d materialized CTE filtered by IN over another materialized CTE""
robot-ch-test-poll1 added a commit that referenced this pull request Jun 9, 2026
Cherry pick #106796 to 26.5: Revert "Revert "Fix LOGICAL_ERROR for reused materialized CTE filtered by IN over another materialized CTE""
robot-clickhouse added a commit that referenced this pull request Jun 9, 2026
…d materialized CTE filtered by IN over another materialized CTE""
alexey-milovidov added a commit that referenced this pull request Jun 10, 2026
Backport #106796 to 26.5: Revert "Revert "Fix LOGICAL_ERROR for reused materialized CTE filtered by IN over another materialized CTE""
alexey-milovidov added a commit that referenced this pull request Jun 10, 2026
Backport #106796 to 26.4: Revert "Revert "Fix LOGICAL_ERROR for reused materialized CTE filtered by IN over another materialized CTE""
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 10, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
… for reused materialized CTE filtered by IN over another materialized CTE""
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…6796

Backport ClickHouse#106796 to 26.4: Revert "Revert "Fix LOGICAL_ERROR for reused materialized CTE filtered by IN over another materialized CTE""
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-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog 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.

5 participants