Skip to content

Fix reads of a reloaded table created AS an object storage table function with parallel replicas - #132315

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-reloaded-create-as-table-function-cluster
Nov 24, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-reloaded-create-as-table-function-cluster

Conversation

@groeneai

@groeneai groeneai commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #132278
Related: #113389
Related: #115095

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

Fixed reading a table created AS an object storage table function (s3, azureBlobStorage, hdfs, icebergLocal, deltaLake and others) after the table was loaded back from its metadata (ATTACH DATABASE, a server restart) on a server whose default profile enables parallel replicas: every read of it failed, for example with THERE_IS_NO_COLUMN. Closes #132278.

Description

On 26.10.4.207, every read of a table created AS icebergLocal(...) fails with THERE_IS_NO_COLUMN once the table is reloaded on a server whose default profile enables parallel replicas (the ParallelReplicas CI configuration, #132278): a single SELECT sum(id) fails on the replicas, and the second branch of UNION ALL fails on the initiator.

CREATE ... AS f(...) executes the table function with is_insert_query = true, so it builds a plain object storage. Reloading executes the stored definition with the server context and is_insert_query = false, so with parallel replicas in the profile it becomes StorageObjectStorageCluster. Queries name the table, which that storage cannot rewrite into a *Cluster call: each replica resolves its own reloaded table again, and the reads fail. Fixing only the by-name header match in StorageTableFunctionProxy::read moves the failure to the replicas (measured).

Stored columns reach a table function only from CREATE and its replay, never from an ad-hoc call, so a definition with stored columns now resolves to the storage its creation selected, the rule url already follows (#115095). After a reload such a table is read without the cluster, as it already was right after CREATE; an ad-hoc call of the function in a query still reads through the cluster.

The new stateless test reloads such a table and reads it. With the ParallelReplicas profile it fails on master (THERE_IS_NO_COLUMN on the replicas) and passes with the change (50 of 50 runs against a local server with that profile); with the default profile it passes on master too. 05569_lazy_load_tables_iceberg_snapshot_per_select can leave parallel_replicas_blacklist.txt in #113389 once this is merged.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/132315]

Version info

  • Merged into: 26.12.1.394-master (included in 26.12 and later)

…hout the cluster

`CREATE TABLE t AS s3(...)` (and every other object storage table function
with a `*Cluster` variant) executes the table function with
`is_insert_query = true`, so it never builds the parallel replicas cluster
storage. When the table is loaded back from its metadata (ATTACH DATABASE,
a server restart), `createTableFromAST` executes the same definition with
the loader's global context and `is_insert_query = false`, so on a server
whose default profile enables parallel replicas the table became a
`StorageObjectStorageCluster`. Queries reference that table by name, which
the cluster storage cannot rewrite into a `*Cluster` table function call,
so every replica resolved its own `db.t` again, and every read failed with
THERE_IS_NO_COLUMN (on the replicas for a single SELECT, on the initiator
for the second branch of UNION ALL, where the proxy matched a
WithMergeableState header by name).

Stored columns only accompany a table definition (CREATE and replay), never
an ad-hoc call, so a definition with stored columns now resolves to the
storage its creation selected. This is the rule `TableFunctionURL` already
applies for `url` (ClickHouse#115095).

Closes ClickHouse#132278

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review of the diff (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 The changelog entry named THERE_IS_NO_COLUMN for every object storage function, but it was measured only for icebergLocal (a function with a static structure is not wrapped in StorageTableFunctionProxy, ITableFunction.cpp:118) AGREE, fixed in the description The entry now says every read failed, with THERE_IS_NO_COLUMN as the example
2 💡 The "stored columns keep the creation storage choice" rule is now in two table functions (TableFunctionURL.cpp:300 and here) DISAGREE These are the only two table functions with the substitution; *Cluster functions cannot create tables (ITableFunctionCluster.h:49). A shared rule would need a new executeImpl parameter for every table function, since is_insert_query also selects the read-only object storage

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261117-095100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Server profile with parallel replicas (tests/config/users.d/enable_parallel_replicas.xml), CREATE TABLE db.tf (id Int64) AS icebergLocal(...), DETACH/ATTACH DATABASE db: every read of db.tf fails on every run (master 9b10750 and the official 26.10.4.207 build).
b Root cause explained? CREATE ... AS f() passes is_insert_query = true, so it builds a plain object storage; the reload passes false with the server context, so the same definition becomes StorageObjectStorageCluster. A name-referenced read cannot be rewritten into a *Cluster call, so each replica re-resolves its own reloaded table and the proxy's by-name conversion throws ([__table1.id]); on the initiator the second UNION ALL branch trips the by-name match first (sum(__table3.id)).
c Fix matches root cause? Yes. The replay now builds the storage creation built (cached_columns non-empty only for CREATE and replay), the rule url follows since #115095. Fixing only the proxy's header match was measured to move the failure to the replicas.
d Test intent preserved / new tests added? New integration test test_parallel_replicas_create_as_table_function: a guard that the profile really reads an ad-hoc call through the cluster, the plan before vs after the reload, a single read and the UNION ALL from the report.
e Both directions demonstrated? Run against a local server with the module's configs: on master the test body fails (each of its three post-reload checks fails on its own); with the fix it passes 50 of 50 runs, also with serialize_query_plan = 1.
f Fix is general across code paths? One template instantiated by every object storage table function with a *Cluster variant; url already had the rule (verified: works on master); file() has no substitution; *Cluster functions cannot create tables. Short ATTACH TABLE already took the CREATE path (verified).
g Fix generalizes across inputs (params/datatypes/wrappers)? The storage choice does not depend on column types. Measured with an explicit column list and with an inferred two-column structure; aggregating and non-aggregating UNION ALL, SELECT *, count(), query-level enable_parallel_replicas = 0.
h Backward compatible? (maintainer-approved exception only) No setting, format or metadata change. A reloaded table created AS a table function is read without the cluster, as right after CREATE; there was no working cluster read of it before (every read failed). Servers without parallel replicas in the profile: byte-identical behaviour (measured).
i Invariants and contracts preserved? executeImpl still returns a started storage; the branch taken on replay is the one CREATE already takes. No lock, ownership or lifetime change.

Session id: cron:clickhouse-impl-slot-4:20261117-092700

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [80f9756]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL IGNORED

AI Review

Summary

The stored-column guard keeps tables created with CREATE TABLE ... AS an object storage table function on StorageObjectStorage after metadata reload, matching creation and preserving parallel replicas for ad hoc calls. No actionable findings in the current diff or prior discussion. The new regression test passes in the current ParallelReplicas CI job.

The remaining CI gate failure is the previously discussed new_tests_check.py limitation: default-profile bugfix validation passes on the reference binary, while reproducing this bug requires parallel replicas in the server profile. The documented before/after reproduction and profile-specific regression coverage support the requested ci-skip-new-tests-check exception.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Nov 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 80f9756e5 with master c7ec7ba2e (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f09bb52

Every failure below has an owner: a fixing PR (mine 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.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Logical error: Context has expired (STID: 1805-3f9b) not from this PR: the server that aborted is the previous release 26.10.4.207 in the stress phase, in FunctionKQLMultiply::executeImpl (FunctionKQLMultiply.cpp:83). Master has the fix (#131363); its 26.10 backport is merged, but neither the aborting 26.10.4.207 binary nor the newer v26.10.5.57 contains it. The same abort hit 20 other PRs since 2026-11-14 #132081 (external, merged)
Upgrade check (amd_release) / Cannot count the mutations left unfinished by the stress phase, Cannot list the mutations left unfinished by the stress phase, Cannot list the row policies left by the stress phase, Cannot run the mutation entries left behind by the killed mutations, Cannot submit the mutation that has to survive the upgrade cascade of the abort above: the old server is gone #132081 (external, merged)
Mergeable Check praktika rollup of the Upgrade check rows #132081 (external, merged)
PR praktika rollup of the rows above #132081 (external, merged)

The other CIDB FAIL rows on this head are Config Workflow / Pre Hooks and Finish Workflow / Post Hooks of the run before the can be tested label. CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261117-140019

alexey-milovidov added a commit to evillique/ClickHouse that referenced this pull request Nov 20, 2026
…e` and `05569_lazy_load_tables_iceberg_snapshot_per_select`

`02354_vector_search_drop_cache_for_table_lazy_proxy_rename` was added on master and checks that
`system.tables.engine` is `TableProxy` for a table behind a proxy. This PR reports the engine from
the `CREATE` query instead, so check `is_loaded` too.

`05569_lazy_load_tables_iceberg_snapshot_per_select` hits the known failure of a table created `AS`
a data lake table function with parallel replicas in the server profile:
ClickHouse#132278 (fix in progress:
ClickHouse#132315), so it is tagged `no-parallel-replicas`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113389&sha=a4d7e8c6bb086fc1110ca9b69e14803a174fa498&name_0=PR
PR: ClickHouse#113389

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim PedroTadim self-assigned this Nov 20, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai The fix looks right: only CREATE ... AS f(...) and the DatabaseOnDisk replay pass stored columns to ITableFunction::execute (every ad-hoc path passes {}), so cached_columns.empty() picks out exactly the replay, and a reloaded table gets the storage it had right after CREATE.

One suggestion about the test: a new integration module with its own cluster is the most expensive kind of test, and the integration test guidelines ask for one only when a stateless test cannot cover the behavior. Here one probably can. The bug needs a server whose default profile enables parallel replicas, and the stateless ParallelReplicas CI job runs with exactly that profile (it is where #132278 was found). A stateless test that creates a table AS icebergLocal(...), runs DETACH DATABASE / ATTACH DATABASE and reads it would exercise this path in that job; in the other jobs it just passes. Removing 05569_lazy_load_tables_iceberg_snapshot_per_select from parallel_replicas_blacklist.txt (as the description mentions for #113389) would also cover it there. Could you replace the integration test with a stateless one?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Will do: I'll replace the integration module with a stateless test (a table created AS icebergLocal(...), DETACH DATABASE / ATTACH DATABASE, a plain read and the UNION ALL) and post the commit here.

Two notes. 05569_lazy_load_tables_iceberg_snapshot_per_select exists only on #113389, so taking it out of parallel_replicas_blacklist.txt is a step for that PR once this one merges. And Bugfix validation runs the default profile, where the new test passes on master too, so the new-tests check will report that the bug was not reproduced; it would need the ci-skip-new-tests-check label, which I can't add.

The bug needs a server whose default profile enables parallel replicas,
which is the profile of the stateless ParallelReplicas CI job, so a
stateless test covers it there instead of a separate integration module
with its own cluster (review request on ClickHouse#132315). In the other jobs the
test passes on master too.

Measured against local servers: with the ParallelReplicas profile
(tests/config/users.d/enable_parallel_replicas.xml) master fails 3 of 3
(`Cannot find column id ... [__table1.id]` on the replica), the PR head
passes 50 of 50 with random settings; with the default profile master
passes 5 of 5.

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

Copy link
Copy Markdown
Collaborator Author

Done in 80f9756: the integration module is replaced by the stateless 05871_reloaded_create_as_table_function_parallel_replicas. Against a local server with the ParallelReplicas profile it fails on master (Cannot find column id, [__table1.id] on the replica) and passes with the fix 50 of 50; with the default profile it passes on master as well. The description is updated.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 80f9756

Every failure below has an owner: a fixing PR (mine 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.

Check / test Reason Owner / fixing PR
Finish Workflow / Post Hooks (new_tests_check.py) expected for the requested test kind: 05871_reloaded_create_as_table_function_parallel_replicas reproduces the bug only under the ParallelReplicas server profile, while both functional Bugfix validation jobs run the default profile, where master passes it (Bug does not reproduce on this arch - bugfix validation N/A), so no per-arch job validated the bug PR-caused by design and owned by this PR (#132315): the resolution is the reviewer's decision on ci-skip-new-tests-check for this test
Mergeable Check / PR praktika rollups of the row above PR-caused by design and owned by this PR (#132315)

The Bugfix validation (functional tests, ...) FAIL rows in CIDB are the arch-N/A inversion (the new test passed on the master binary). CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261124-003024

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai, please investigate the CI failures in this PR (commit 80f9756) and fix them, or link existing fixes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=132315&sha=80f9756e540c15e4a2e8cb3c4d6da6caef1fa621&name_0=PR

Failures without a known issue:

  • python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py in Finish Workflow

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 24, 2026
Merged via the queue into ClickHouse:master with commit 2c466c2 Nov 24, 2026
380 of 383 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

The only red is new_tests_check.py, and it is the expected result of the requested stateless test: 05871_reloaded_create_as_table_function_parallel_replicas reproduces the bug only under the ParallelReplicas server profile, while both functional Bugfix validation jobs run the default profile and reported it as not reproducing, so no job validated the fix (ledger). There is nothing to fix in the code.

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 comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). 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.

A table created AS a data lake table function fails in the second branch of UNION ALL with parallel replicas in the server profile

3 participants