Skip to content

Native Common Virtuals for Remaining Storage - #102304

Merged
Michicosun merged 23 commits into
masterfrom
native_common_virtuals/Rest
Apr 11, 2026
Merged

Michicosun merged 23 commits into
masterfrom
native_common_virtuals/Rest

Conversation

@Michicosun

@Michicosun Michicosun commented Apr 9, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Unfortunately, we need to support this for backward compatibility.

Version info

  • Merged into: 26.4.1.833

@clickhouse-gh

clickhouse-gh Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a5b16de]

Summary: ❌

job_name test_name status info comment
Unit tests (asan_ubsan) failure
FunctionsStress.stress failure cidb
AllTests failure cidb
Stress test (arm_tsan) failure
Server died FAIL cidb, issue
Logical error: Cannot fold actions for projection. Node A requires input B which does not belong to projection (STID: 3673-56a1) FAIL cidb

AI Review

Summary

This PR refactors virtual-column handling by introducing VirtualsMaterializationPlace and migrating many storages to common virtual materialization paths. The direction is reasonable, but there are multiple correctness blockers in legacy Pipe read storages and in StorageWithCommonVirtualColumns exception/lifetime handling. In its current state, the PR can break regular reads and virtual-column queries for affected engines and is not safe to merge.

Findings

❌ Blockers

  • [src/Storages/StorageWithCommonVirtualColumns.cpp] std::exchange(storage_snapshot->data, nullptr) mutates a shared caller-provided StorageSnapshot, creating action-at-a-distance for later users of the same snapshot.
    Suggested fix: move ownership transfer to a cloned/local snapshot, not the shared original object.
  • [src/Storages/StorageWithCommonVirtualColumns.cpp] Exception-safety issue: storage_snapshot->data is swapped out before readImpl and restored only on the normal path; if readImpl throws, the original snapshot can lose data.
    Suggested fix: restore with RAII (SCOPE_EXIT/equivalent) on all exit paths.
  • [src/Storages/StorageStripeLog.cpp:391] _table/_database are marked VirtualsMaterializationPlace::Plan, but StorageStripeLog still uses legacy Pipe read and never reaches plan-level materialization, so queries like SELECT _table ... fail as “neither physical nor virtual”.
    Suggested fix: use Reader placement for this storage or migrate it to StorageWithCommonVirtualColumns.
  • [src/Storages/StorageStripeLog.cpp] fillVirtualColumns checks !result_columns.empty() instead of whether virtual columns were requested, causing LOGICAL_ERROR on normal non-empty reads.
    Suggested fix: gate on !virtual_columns.empty() (or early-return when virtuals are empty).
  • [src/Storages/StorageArrowFlight.cpp:196] Same placement mismatch as above: _table/_database registered as Plan while legacy read path calls splitting that accepts only Reader virtuals, so virtual-column queries fail.
    Suggested fix: set these virtuals to Reader or migrate to StorageWithCommonVirtualColumns.
Tests
  • ⚠️ Add/extend stateless coverage for legacy-read storages (StripeLog, ArrowFlight) with SELECT _table, SELECT _database, and mixed physical+virtual projections to ensure no “neither physical nor virtual” exception.
  • ⚠️ Add exception-path coverage for StorageWithCommonVirtualColumns to verify StorageSnapshot::data is preserved when readImpl throws.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ❌ Storage read/virtual-column invariants are broken in multiple touched engines
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ⚠️ Existing virtual-column queries on legacy-read storages regress
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ❌ Regressions in read behavior make rollout unsafe
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ❌ Block

Minimum required actions:

  • Fix the five blockers above (snapshot ownership/exception safety and legacy storage virtual-column materialization mismatches).
  • Add the missing regression tests for legacy storages and exception path handling.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Apr 9, 2026
@Michicosun
Michicosun force-pushed the native_common_virtuals/Rest branch from 56742b2 to d035078 Compare April 9, 2026 23:41
{
VirtualColumnsDescription desc;
desc.addEphemeral("_table", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), "");
desc.addEphemeral("_table", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), "", VirtualsMaterializationPlace::Plan);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

StorageStripeLog defines _table/_database as VirtualsMaterializationPlace::Plan, but this storage still uses the legacy Pipe read(...) path and never goes through StorageWithCommonVirtualColumns::read, so Plan-level virtuals are never materialized here.

In this same function, splitPhysicalAndVirtualColumnNames only accepts Reader-level virtuals. A query like SELECT _table FROM stripe_log_table therefore fails with Column '_table' is neither physical nor virtual.

Please register these virtuals as VirtualsMaterializationPlace::Reader for StorageStripeLog, or migrate this storage to StorageWithCommonVirtualColumns so Plan-level materialization actually runs.

Comment thread src/Storages/StorageStripeLog.cpp Resolved
Comment thread src/Storages/StorageArrowFlight.cpp Resolved

@KochetovNicolai KochetovNicolai 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

@clickhouse-gh

clickhouse-gh Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 92.37% (1513/1638) | lost baseline coverage: 133 line(s) · Uncovered code

Full report · Diff report

@Michicosun

Copy link
Copy Markdown
Member Author

FunctionsStress.stress is broken.

There are 2 problems I discovered:

  1. The printf function faces a problem in the fmtlib when a string with a single control character like % is passed.
  2. FunctionBaseDynamicAdaptor does not implement isInjective

@Michicosun
Michicosun added this pull request to the merge queue Apr 11, 2026
Merged via the queue into master with commit 00ecef1 Apr 11, 2026
161 of 164 checks passed
@Michicosun
Michicosun deleted the native_common_virtuals/Rest branch April 11, 2026 16:07
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 11, 2026
pull Bot pushed a commit to Dream-hu/ClickHouse that referenced this pull request Jun 14, 2026
Verifies that selecting `_table` and `_database` from a `Merge` over a
`Distributed` table together with a `LEFT JOIN` returns the real virtual
column values when the analyzer is enabled.

Issue: ClickHouse#84139
Fixed by:
  - ClickHouse#102304
  - ClickHouse#102471

Co-authored-by: Yakov Olkhovskiy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants