Skip to content

Fix NOT_FOUND_COLUMN_IN_BLOCK for virtual columns under parallel replicas - #108451

Merged
Michicosun merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-106561-dummy-virtual-columns-parallel-replicas
Jul 2, 2026
Merged

Michicosun merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-106561-dummy-virtual-columns-parallel-replicas

Conversation

@groeneai

@groeneai groeneai commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

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

Fix NOT_FOUND_COLUMN_IN_BLOCK error (e.g. Column _part not found) when selecting virtual columns from a MergeTree table under parallel replicas, including via SELECT * with asterisk_include_virtual_columns = 1.

Description

Closes: #106561

During planning, the parallel-replicas estimation path (parallel_replicas_min_number_of_rows_per_replica > 0 over a MergeTree table) runs collectFiltersForAnalysis, which replaces the real table with a StorageDummy via replaceTableExpressionsWithDummyTables. StorageDummy::createVirtuals only registered _table/_database and dropped the original storage's own virtual columns (_part, _partition_id, ...).

When a query requested one of those virtuals together with _table/_database (for example SELECT * with asterisk_include_virtual_columns = 1, which expands to include _part), StorageWithCommonVirtualColumns::read called storage_snapshot->getSampleBlockForColumns on the dummy snapshot, which could not resolve _part and threw NOT_FOUND_COLUMN_IN_BLOCK.

The dummy already holds the original storage snapshot, so createVirtuals now preserves the original storage's virtual columns; the dummy resolves the same virtuals the real table does. _table/_database are still added at the Plan place (the dummy materializes them as constants), so their handling is unchanged.

Reproducer (from the issue, https://fiddle.clickhouse.com/cbdef536-f180-4922-8ad3-9495d97d9a13):

CREATE TABLE t0 (c0 Int) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t0 VALUES (1), (2), (3);
SELECT * FROM t0
SETTINGS asterisk_include_virtual_columns = 1, enable_parallel_replicas = 1,
         max_parallel_replicas = 2, parallel_replicas_for_non_replicated_merge_tree = 1,
         parallel_replicas_min_number_of_rows_per_replica = 1;

Version info

  • Merged into: 26.7.1.434 (included in 26.7 and later)

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE t0 (c0 Int) ENGINE=MergeTree ORDER BY tuple(); SELECT * FROM t0 SETTINGS asterisk_include_virtual_columns=1, enable_parallel_replicas=1, max_parallel_replicas=2, parallel_replicas_for_non_replicated_merge_tree=1, parallel_replicas_min_number_of_rows_per_replica=1 throws NOT_FOUND_COLUMN_IN_BLOCK: Column _part not found every time on master HEAD.
b Root cause explained? The estimation path (parallel_replicas_min_number_of_rows_per_replica > 0 over MergeTree) runs collectFiltersForAnalysis, which swaps the real table for a StorageDummy. StorageDummy::createVirtuals registered only _table/_database and dropped _part/_partition_id/... . * with asterisk_include_virtual_columns expands to include _part; StorageWithCommonVirtualColumns::read (line 87) then calls getSampleBlockForColumns on the dummy snapshot, which cannot resolve _part -> throw.
c Fix matches root cause? Yes. The dummy already holds the original storage snapshot; createVirtuals now preserves the original storage's virtuals so the dummy resolves the same virtuals the real table does. Fix is at the source of the divergence, not a guard at the throw site.
d Test intent preserved / new tests added? New stateless test 03600_asterisk_virtual_columns_parallel_replicas added, covering SELECT * + asterisk_include_virtual_columns, explicit reader-place virtuals, plan-place virtuals, and the mixed case, all under the estimation path.
e Both directions demonstrated? Yes. Unfixed binary: test FAILS with NOT_FOUND_COLUMN_IN_BLOCK at StorageSnapshot.cpp:137 / StorageWithCommonVirtualColumns.cpp:87 (matches the issue stack). Fixed binary: 20/20 runs PASS with full randomization.
f Fix is general across code paths? Yes. The fix is in StorageDummy::createVirtuals, the single chokepoint for all dummy-table replacement sites (collectFiltersForAnalysis, findParallelReplicasQuery, getHeaderForProcessingStage, buildQueryTreeForShard, ...). Verified the Distributed/StorageView triggers of the same path also resolve virtuals now. Not specific to _part or to asterisk: any reader-place virtual + a plan-place virtual reproduced it.
g Fix generalizes across inputs? Yes. Confirmed for _part, _partition_id, _part_index, and the mixed reader+plan virtual case; _table/_database still materialize as constants (kept at Plan place). Iterating metadata->virtuals carries each virtual's original type, so all virtual datatypes are preserved.
h Backward compatible? Yes. No setting, format, or default change. The dummy is an internal planning-only storage; this only adds the original virtuals to its in-memory metadata. No SettingsChangesHistory change needed.
i Invariants and contracts preserved? Yes. _table/_database are still added exactly once at the Plan place (the originals, registered at other places, are skipped to avoid changing their materialization), so StorageWithCommonVirtualColumns's constant-materialization contract is unchanged. add() rejects duplicates; the skip prevents any DUPLICATE_COLUMN. ReadFromDummy already builds its own header from the original snapshot, so its behavior is unaffected.

Session id: cron:clickhouse-worker-slot-0:20260625-074000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @nickitat could you review this? It fixes #106561: under the parallel-replicas estimation path, collectFiltersForAnalysis replaces the table with a StorageDummy whose createVirtuals dropped the storage's own virtual columns (_part, _partition_id, ...), so SELECT * with asterisk_include_virtual_columns threw NOT_FOUND_COLUMN_IN_BLOCK. The dummy now preserves the original storage's virtuals (it already holds the original snapshot); _table/_database handling is unchanged.

Comment thread src/Storages/StorageDummy.cpp Resolved
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [16e7aeb]

Summary: ✅


AI Review

Summary

This PR fixes NOT_FOUND_COLUMN_IN_BLOCK in the parallel-replicas planning path by making StorageDummy preserve the original storage snapshot's virtual-column metadata, and adds a focused stateless regression for SELECT * with asterisk_include_virtual_columns. I did not find any new correctness, safety, or PR metadata issues in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 25, 2026
…icas

The parallel-replicas estimation path (parallel_replicas_min_number_of_rows_per_replica > 0 over a MergeTree table) runs collectFiltersForAnalysis, which replaces the real table with a StorageDummy. StorageDummy::createVirtuals registered only _table/_database and dropped the original storage's own virtuals (_part, _partition_id, ...), so a query expanding those (e.g. SELECT * with asterisk_include_virtual_columns = 1) threw NOT_FOUND_COLUMN_IN_BLOCK when the dummy snapshot was asked for the sample block.

The dummy already holds the original storage snapshot, so just copy its virtual columns. Falls back to _table/_database when there is no original snapshot.

Closes: ClickHouse#106561

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the groeneai/fix-106561-dummy-virtual-columns-parallel-replicas branch from a20c0f0 to e0eb326 Compare June 25, 2026 12:32
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done, both addressed.

  • `createVirtuals` now just copies the original storage snapshot's virtuals (with the `_table`/`_database` fallback for the no-snapshot callers). Diff is now +7/-2 in the cpp.
  • Test reduced to the single-line repro, comments removed.

One note: the repro has to stay the bare `SELECT *` (kept it as `... FORMAT Null` to avoid printing the unstable `_part_uuid`/etc. columns). Wrapping it (`SELECT c0 FROM (SELECT * ...)`) or selecting an explicit virtual does not reproduce, the outer projection prunes `_part` before it reaches the dummy. Verified the test fails with NOT_FOUND_COLUMN_IN_BLOCK without the fix and passes with it (30/30 under randomization).

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — e0eb326

CI has fully finished (Finish Workflow passed; last check 2026-06-25 16:23). This PR is a StorageDummy virtual-columns fix (parallel-replicas planning, #106561); none of the failures below are caused by it. Every red check has an owner; only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6) / test_quorum_inserts_parallel::test_parallel_quorum_actually_quorum flaky (chronic: 38 hits / 29 PRs / 6 master in 30d) #108433 (ours, open)
Stress test (amd_asan_ubsan) / Hung check failed, possible deadlock found deadlock (chronic shutdown-deadlock family: 976 hits / 433 PRs / 327 master) #105905 / #101680 (ours, open)
Stress test (arm_asan_ubsan, s3) / Hung check failed, possible deadlock found deadlock (same family) #105905 / #101680 (ours, open)
Stress test (arm_msan) / Logical error: Block structure mismatch in UnionStep stream (STID 0993-27f0) query-planner UnionStep Const-vs-non-Const header mismatch on a fuzzed WITH TOTALS query — chronic trunk (74 hits / 60 PRs / 9 master in 30d) #107719 (ours, open)
Mergeable Check / PR — rollups of the reds above
CH Inc sync — CH Inc sync (private, not actionable by us)

The fix (StorageDummy::createVirtuals plain copy per @ Michicosun's request) + minimal single-line repro test are green. None of the four reds touch StorageDummy or the parallel-replicas planning path. Ready for review.

Session id: cron:our-pr-ci-monitor:20260625-170000

@Michicosun

Copy link
Copy Markdown
Member

@groeneai merge master

@groeneai

Copy link
Copy Markdown
Collaborator Author

@Michicosun merged current master into the branch (head 16e7aeba60c). Diff unchanged: 4 files, +22/-3. CI re-running.

Comment thread src/Storages/StorageDummy.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 262b6db

Every failure below has an owner: a fixing PR (ours or external). Only CH Inc sync is exempt. None are PR-caused (the StorageDummy virtual-columns change is unrelated to all three).

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan) / Hung check, possible deadlock deadlock (chronic) #105905 / #101680 (ours, open)
Stress test (arm_ubsan) / Bad cast ColumnNullable to ColumnString (STID 3336-3cad) crash (group_by_use_nulls trunk bug, reproduced + verified) #104350 (ours, open)
Stateless tests (arm_binary, parallel) / 03518_alter_logical_race flaky (37 hits / 33 PRs / 3 master, 30d) #108060 (external, open)
CH Inc sync / Mergeable Check / PR rollups CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260627-023000

@Michicosun
Michicosun added this pull request to the merge queue Jun 29, 2026
@Michicosun
Michicosun removed this pull request from the merge queue due to a manual request Jun 29, 2026
Comment thread src/Storages/StorageDummy.cpp Resolved
@groeneai
groeneai force-pushed the groeneai/fix-106561-dummy-virtual-columns-parallel-replicas branch from 262b6db to 16e7aeb Compare June 29, 2026 10:16
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 11/13 (84.62%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 16e7aeb

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt. Neither failure is PR-caused — this PR's diff is StorageDummy.cpp/StorageDummy.h + a stateless test, which cannot affect expression-JIT codegen or the upgrade-check background-pool logging.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug) / "Both operands to FCmp not same type" (STID 1154-240e) crash (LLVM JIT codegen: FunctionComparison<Equals> emits FCmp over f64 vs i32 without common-type promotion; 1 PR / 0 master / 30d) a fix task is created (investigating at full effort — fixing PR link to follow on this PR)
Upgrade check (amd_release) / "Error message in clickhouse-server.log" flaky / infra (mysqlxx::Pool / DatabaseMySQL background-pool connection errors to the fake 192.0.2.1 host; chronic upgrade-check log noise, unrelated to this PR) a fix task is moved to pending (investigating at full effort — fixing PR link to follow on this PR)
CH Inc sync — CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260629-140000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 16e7aeb (corrected)

Correction to the prior ledger comment: the Upgrade-check line has an existing open fixing PR (#108560, ours), so it is linked here per the ledger rule (a fixing PR is always preferred over a fix-task disposition). Neither failure is PR-caused — this PR's diff is StorageDummy.cpp/StorageDummy.h + a stateless test, which cannot affect expression-JIT codegen or the upgrade-check background-pool logging.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug) / "Both operands to FCmp not same type" (STID 1154-240e) crash (LLVM JIT codegen: FunctionComparison<Equals> emits FCmp over f64 vs i32 without common-type promotion; 1 PR / 0 master / 30d) a fix task is created (investigating at full effort — fixing PR link to follow on this PR)
Upgrade check (amd_release) / "Error message in clickhouse-server.log" flaky / infra (mysqlxx::Pool / DatabaseMySQL / PostgreSQLConnectionPool background-pool connection errors to the unreachable test host 192.0.2.1; chronic upgrade-check log noise, unrelated to this PR) #108560 (ours, open)
CH Inc sync — CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260629-140000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger: owner update for STID 1154-240e

Completing the previously-placeholdered AST-fuzzer line. The fixing PR is now identified and the failure is reproduced and root-caused locally.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug) / "Both operands to FCmp not same type" (STID 1154-240e) LLVM JIT abort from the group_by_use_nulls correlated-subquery decorrelation trunk bug (reproduced and verified; 1 PR / 0 master / 30d) #104350 (ours, open)

Correction to the earlier parenthetical ("FunctionComparison emits FCmp over f64 vs i32 without common-type promotion"): that preliminary read was wrong. FunctionComparison::compileImpl already promotes both operands to a common type via nativeCast before CompileOp::compile (FunctionsComparison.h:1674-1677). Verified locally: plain float = int JIT comparisons (all of = != < <= > >=, and equals in a projection) compile and run correctly, so there is no generic comparison-codegen gap.

Actual root cause: the group_by_use_nulls correlated-subquery decorrelation family (issue #106377, fixed by #104350). This is the same family already owning the sibling Bad cast ColumnNullable to ColumnString line (STID 3336-3cad) above. The recovered fuzzed query is a correlated scalar subquery referencing an outer GROUP BY key (b = number / number, Float64) under WITH ROLLUP:

SELECT a, (SELECT b WHERE and(1048575, materialize(7), NULL) GROUP BY 1, '' QUALIFY equals(b, -2147483648)), '\0'
FROM numbers_mt(65536) WHERE toDecimal256('-1', NULL)
GROUP BY (number / number) AS b, number AS a, '...', '2.57' WITH ROLLUP WITH TOTALS LIMIT 1048576

Under ROLLUP the decorrelated correlated column is fed as Nullable, but the analyzer left the inner reference at its non-Nullable type (the QueryAnalyzer::resolveExpressionNode nullable_group_by_keys scope-walk stops at the first enclosing QUERY scope, which is exactly what #104350 fixes). The resulting ActionsDAG node's declared type no longer matches the value it produces; the interpreter is lenient (returns the correct 0 / NULL), but the JIT bakes the declared types and emits CreateFCmpOEQ(double, i32), hitting FCmpInst::AssertOK. Confirmed locally on a debug JIT build: aborts with compile_expressions=1, returns the correct result with compile_expressions=0. This is the FCmp/equals sibling of STID 1176-28cc (minus/BinaryOperator) documented in #106377.

Not PR-caused: this PR's diff is StorageDummy.cpp/StorageDummy.h plus a stateless test, which cannot affect expression-JIT codegen or the analyzer decorrelation path. Tracking #104350 to merge.

Session id: cron:clickhouse-worker-slot-0:20260629-142400

@Michicosun
Michicosun added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 3174567 Jul 2, 2026
337 of 339 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
alexey-milovidov added a commit that referenced this pull request Jul 2, 2026
…o-read-setting

The branch was ~11.7k commits behind (last merge 2026-06-20) and red. The
diff vs. `master` is still the single randomizer line — no functional change:

    "parallel_replicas_min_number_of_rows_per_replica": lambda: random.randint(0, 1),

Reason to re-merge now: the parallel-replicas owners have landed several
directly relevant fixes since 2026-06-20, so refreshing CI on today's
`master` will narrow the remaining set of genuine product bugs this PR is
meant to surface:
- #108451 (`Fix NOT_FOUND_COLUMN_IN_BLOCK for virtual columns under parallel
  replicas`, closes #106561) — should clear the tracked
  `04098_asterisk_include_virtual_columns_mergetree` failure.
- #101434 (`Reimplement reading in order for parallel replicas`) — bears
  directly on the `max_rows_to_read`-not-honored class
  (`02155_read_in_order_max_rows_to_read`, `00945_bloom_filter_index`).
- #109003 (`Fix server abort on GROUPING SETS in a set operation with
  parallel replicas`) — a "Server died" class fix.
- Flaky-test fix for `04051_pk_analysis_stats`.

Conflicts were all in files the branch does not intentionally change (its
only intended change is the one `tests/clickhouse-test` line); they were
resolved by taking `master`'s version. No pinning/blacklisting of the
affected parallel-replicas tests — that would mask the very signal this PR
exists to produce.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…1-dummy-virtual-columns-parallel-replicas

Fix NOT_FOUND_COLUMN_IN_BLOCK for virtual columns under parallel replicas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors 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.

NOT_FOUND_COLUMN_IN_BLOCK with asterisk_include_virtual_columns and parallel replicas

4 participants