Skip to content

Add allow_object_storage_cluster_distributed_join for whole-query JOIN dispatch - #2832

Open
VighneshPath wants to merge 19 commits into
Altinity:antalya-26.8from
VighneshPath:feature/antalya-26.8/object-storage-cluster-distributed-join
Open

VighneshPath wants to merge 19 commits into
Altinity:antalya-26.8from
VighneshPath:feature/antalya-26.8/object-storage-cluster-distributed-join

Conversation

@VighneshPath

@VighneshPath VighneshPath commented Nov 12, 2026 •

Copy link
Copy Markdown

Port of #2383 to antalya-26.8, with that PR's review comments addressed.

With allow_object_storage_cluster_distributed_join = 1, a JOIN query whose driving table is a DataLake catalog table with object_storage_cluster set is sent whole to that cluster. Each node runs the JOIN and any GROUP BY over its share of the driver's files, and the initiator only merges the partial aggregate states. Before this, the JOIN and GROUP BY always ran on the initiator. A query that is not eligible is planned as before, as set by object_storage_cluster_join_mode.

The setting is a separate boolean, EXPERIMENTAL and false by default, instead of a new value of object_storage_cluster_join_mode. So the existing local/global/allow modes keep their meaning, and the server setting allow_feature_tier can block it.

  • findDistributedObjectStorageCandidate walks the left side of the query, through INNER ALL/LEFT joins and through subqueries that do not combine rows, to the driver. Every other table must be a catalog table with no row policy and with SELECT access. Otherwise the whole query is planned as before.
  • buildDistributedObjectStorageQueryPlan sends the query with every table replaced by the table function its own cluster read would send: the driver as its *Cluster function, which reads the files the initiator hands out, and every other table as its plain function, which each node reads in full.
  • ReadFromClusterQuery sends the query over the same transport as ReadFromCluster. It hands out the driver's files, pruned by the driver's own filter.
  • Dispatch respects object_storage_cluster_fallback_to_local_if_empty: if the cluster is missing or empty and the read falls back to local, the query is not dispatched.
  • Workers do not receive allow_object_storage_cluster_distributed_join: it is reset in their context and removed from the query text, so older workers do not reject an unknown setting.
  • The dispatched tables and columns, including those in subqueries and CTEs, are recorded in the query access info, so they show up in system.query_log.

Related: #2383

Changelog category (leave one):

  • Experimental Feature

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

Add the experimental setting allow_object_storage_cluster_distributed_join. It sends a whole JOIN query over DataLake catalog tables to the cluster of its driving table, so that the JOIN and GROUP BY run on the cluster's nodes instead of on the initiator.

Documentation entry for user-facing changes

The setting is described in docs/reference/statements/select/join.mdx and in the settings table of docs/en/antalya/swarm.md.

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

🤖 Generated with Claude Code

VighneshPath and others added 4 commits November 12, 2026 20:20
…JOIN dispatch

With the new mode, a `JOIN` query whose driving table is a `DataLake` catalog
table with a cluster is sent whole to that cluster. Each node runs the `JOIN`
and any `GROUP BY` over its share of the driver's files, and the initiator only
merges the partial aggregate states.

- findDistributedObjectStorageCandidate walks the left side of the query, through
  `INNER ALL`/`LEFT` joins and subqueries that do not combine rows, to the driver.
  Every other table must be a catalog table with no row policy and `SELECT`
  access. The decision is made once per query, next to parallel replicas, and
  kept in `GlobalPlannerContext`.
- buildDistributedObjectStorageQueryPlan serializes the query and replaces every
  table in it with the table function its own cluster read sends: the driver's
  `*Cluster` function reads the files the initiator hands out, every other table's
  plain function reads all of them. A worker resolves no catalog table and runs
  the query as it would any cluster table function; an Iceberg table's function
  names the metadata file resolved on the initiator. A driver referenced twice
  is not dispatched.
- `ReadFromClusterQuery` sends the query over the same transport as
  `ReadFromCluster`, whose pipe building is now shared, and feeds it the driver's
  files pruned by the driver's own filter.
- An ordinary cluster read reached under the new mode behaves exactly like
  `allow`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Shorten the comments to the reason each step exists.
- `DistributedObjectStorageCandidate` keeps only the dispatch boundary and the
  driver's `TableNode`; its storage and filter key are derived from it.
- `findDriverOnLeftSpine` returns `std::optional` instead of an `unusable` flag.
- Rename `isSafeDataLakeLeaf` to `isSafeCatalogTable`.
- Move the driver filter extraction into `buildDriverFilter`.
- Replace the `prepareForWholeQueryDispatch` hook with lazy initialization in
  `StorageObjectStorageCluster::getTaskIteratorExtension`, limited to data lake
  configurations, and drop the test of the hook.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- `QueryNode::getJoinTree` and `JoinNode::getLeftTableExpression` now return a
  reference that asserts the node exists; use `getJoinTreeNode` and
  `getLeftTableExpressionNode`, which can still be null.
- Do not dispatch when `build_logical_plan` is set: that plan is serialized for
  a shard, and `ReadFromClusterQuery` has no serialized form. Plan-based
  parallel replicas step aside for the same reason.
- Strip initiator-only settings such as `limit` from the context sent to
  workers, as `ReadFromCluster::updateSettings` now does. A worker applying
  them would cut its partial result before the initiator merges it.
- The analyzer now checks table access while resolving identifiers, so the
  access tests analyze as a user with grants and check the candidate as one
  without.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Decline dispatch when a nested subquery or CTE has its own `SETTINGS`
  clause. The eligibility checks read the outer query's settings, so a nested
  `additional_table_filters` was not rejected, and a nested
  `object_storage_cluster` was ignored when choosing the driver's cluster.
- Reuse `hasAggregateFunctionNodes` and `hasWindowFunctionNodes` instead of a
  local copy of the same traversal.
- Rename `ReadFromClusterQuery::updateSettings` to `createRemoteContext`: it
  creates a new context rather than updating one. Build it with
  `Context::createCopy` and `setSetting`.

Related: Altinity#2383

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

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T20:19:22.843905Z 46dd813 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ianton-ru

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46dd813705

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


/// Initiator-only settings such as `limit` would cut each worker's partial result, as in `ReadFromCluster`.
Settings settings = remote_context->getSettingsCopy();
ClusterProxy::stripInitiatorOnlySettings(settings);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Downgrade the join mode before dispatching to workers

When this mode is enabled during a rolling upgrade, settings still marks object_storage_cluster_join_mode=distributed as changed after this strip, so RemoteQueryExecutor sends that value in the settings packet. A worker from before this commit already knows the setting name but cannot parse the new enum value, causing every otherwise eligible dispatched JOIN to fail before execution; mirror ReadFromCluster::updateSettings and change it to allow in this remote context.

Useful? React with 👍 / 👎.

@VighneshPath VighneshPath Nov 16, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

distributed is no longer a value of object_storage_cluster_join_mode, so older workers can no longer fail to parse it.

return false;

const auto & storage = static_cast<const IStorageCluster &>(*table_node.getStorage());
return !storage.getClusterName(context).empty();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor local fallback before selecting the driver

When object_storage_cluster_fallback_to_local_if_empty=1 and the configured object-storage cluster is missing or has no nodes, getClusterName still returns its nonempty configured name, so this accepts a whole-query candidate. The custom path subsequently uses the throwing getClusterImpl in readPreparedClusterQuery instead of resolveClusterRead, causing a qualifying JOIN to fail although the setting promises an ordinary local read; resolve the cluster or decline dispatch before returning the candidate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The whole-query dispatch now respects object_storage_cluster_fallback_to_local_if_empty

VighneshPath and others added 2 commits November 13, 2026 14:34
`object_storage_cluster_join_mode = 'distributed'` sends a query whole only
when its tables come from a `DataLake` catalog. Every other query ran as under
`allow`, keeping the `JOIN` on the initiator, although `global` is faster for
some of them. The new setting chooses that mode: `allow` (the default, so
nothing changes) or `global`.

`getEffectiveObjectStorageClusterJoinMode` resolves `distributed` to the
fallback, and every place that checks for `global` uses it. Workers receive
the resolved mode, as before.

A dispatched query now reaches workers with
`object_storage_cluster_join_mode = 'allow'`. They ran it under the effective
mode before, so the fallback would also have changed how a worker plans its
copy of the `JOIN`. It also lets a worker that does not know `distributed`
parse the settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…age-cluster-distributed-join' into feature/antalya-26.8/object-storage-cluster-distributed-join
@ianton-ru

Copy link
Copy Markdown

Comment thread src/Core/Settings.cpp Outdated

See [Distributed JOIN](../../sql-reference/statements/select/join.md#object-storage-cluster-join-mode).
)", 0) \
DECLARE(ObjectStorageClusterJoinMode, object_storage_cluster_join_mode_fallback, ObjectStorageClusterJoinMode::ALLOW, R"(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Topic for discussion.
I think this setting makes all too confusing.
May be better to make the next:
object_storage_cluster_join_mode has the same options as before, without distributed
New setting like allow_object_storage_cluster_distributed_join with boolean values.
If value is true - do distributed request if possible, or fallback to object_storage_cluster_join_mode.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Okay, yeah this seems better
I can make the change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, have added allow_object_storage_cluster_distributed_join which fall backs to object_storage_cluster_join_mode

VighneshPath and others added 2 commits November 16, 2026 10:52
…ster_distributed_join`

`object_storage_cluster_join_mode = 'distributed'` mixed two questions: whether
a whole `JOIN` query is dispatched to the cluster, and how a query that is not
dispatched is planned. Dispatch is now the boolean
`allow_object_storage_cluster_distributed_join`, and a query that cannot be
dispatched is planned as set by `object_storage_cluster_join_mode`, which has
its previous values again. `object_storage_cluster_join_mode_fallback` and
`getEffectiveObjectStorageClusterJoinMode` are removed.

Workers no longer receive the new setting.

Add the setting to the `JOIN` and Swarm documentation.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- Remove `allow_object_storage_cluster_distributed_join` from the query sent
  to workers with `removeSettingsFromQuery`, which handles `name = DEFAULT`
  and detaches a clause left empty. The previous removal could send a bare
  `SETTINGS`, which does not parse on the worker.
- Resolve the cluster of a dispatch with `resolveClusterRead`, as an ordinary
  read does, and decline dispatch for a table that
  `object_storage_cluster_fallback_to_local_if_empty` reads locally.
- Record the original catalog tables and columns of a dispatched query in the
  initiator's access info, so they appear in `system.query_log`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@VighneshPath VighneshPath changed the title Add object_storage_cluster_join_mode='distributed' for whole-query JOIN dispatch Add allow_object_storage_cluster_distributed_join for whole-query JOIN dispatch Nov 16, 2026
@ianton-ru

Copy link
Copy Markdown

@VighneshPath

Settings looks good now from my point of view.

New issues from AI.

Medium: Partner tables are not pinned to the initiator snapshot

A commit to any non-driver table while a dispatched join runs makes different driver partitions join different partner snapshots. The initiator merges those partial aggregates into one result that matches no single snapshot.

object_storage_cluster_join_mode = 'allow' and 'global' read each partner once on the initiator, so they do not mix snapshots.

Trigger. allow_object_storage_cluster_distributed_join = 1 on a catalog JOIN, and a commit to the partner (Iceberg or Delta) after workers start.

Why this is a defect. The driver file list is one initiator snapshot. Each partner is sent as a plain table function, object_storage_cluster is cleared on the worker, and iceberg_metadata_file_path is copied only when that storage setting was already changed. Each worker then resolves the partner's current snapshot on its own.

Anchor.

  • replaceTablesWithTableFunctions in src/Planner/buildDistributedObjectStorageQueryPlan.cpp
  • IStorageCluster::getTableFunctionToSend in src/Storages/IStorageCluster.cpp
  • ReadFromClusterQuery::createRemoteContext in src/Storages/IStorageCluster.cpp
  • DataLakeConfiguration::createArgsWithAccessData in src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h

Fix direction. Put the initiator's resolved metadata path or snapshot id into every partner table function before send.

Regression test. Start a dispatched join, commit the partner after the first worker has planned, and assert the merged aggregate equals the pre-commit or the post-commit snapshot, not a mix.

const bool is_driver = it->second->getStorage() == driver.getStorage();
auto table_function = storage->getTableFunctionToSend(it->second->getStorageSnapshot(), context, /*read_initiator_file_tasks=*/is_driver);
// non-driver references are plain table functions, not *Cluster
return is_driver ? 1 : 0;
ASTPtr IStorageCluster::getTableFunctionToSend(..., bool read_initiator_file_tasks)
{
    // make_cluster_function is false for every partner
    updateQueryToSendIfNeeded(query, storage_snapshot, context, /*make_cluster_function=*/read_initiator_file_tasks);
    auto table_function = extractTableFunctionASTPtrFromSelectQuery(query);
    return table_function;
}
/// Partners read locally. Only the driver's explicit `*Cluster` function consumes the initiator's file tasks.
remote_context->setSetting("object_storage_cluster", String{});
ASTPtr createArgsWithAccessData() const override
{
    auto res = BaseStorageConfiguration::createArgsWithAccessData();
    auto iceberg_metadata_file_path = (*settings)[DataLakeStorageSetting::iceberg_metadata_file_path];
    if (iceberg_metadata_file_path.changed)
    {
        // snapshot path is copied only when the setting was already changed

Low: Spark integration test passes a removed join-mode value

test_cluster_joins will throw BAD_ARGUMENTS for join_mode='distributed' and will not run the new dispatch against Spark-written Iceberg. object_storage_cluster_join_mode accepts only local, global, and allow.

Trigger. The new parametrization reaches object_storage_cluster_join_mode='distributed'.

Why this is a defect. The PR adds "distributed" to the parameter list and does not switch that case to allow_object_storage_cluster_distributed_join.

Anchor. tests/integration/test_storage_iceberg_with_spark/test_cluster_joins.py

Fix direction. For that case set allow_object_storage_cluster_distributed_join = 1 and keep object_storage_cluster_join_mode as allow or global.

Regression test. Run test_cluster_joins with the distributed parameter and expect the existing row assertions, not an unknown enum value.

The PR changes the parameter list to include "distributed". The query still interpolates that value into the old setting:

            SETTINGS
                object_storage_cluster='cluster_simple',
                object_storage_cluster_join_mode='{join_mode}'

VighneshPath and others added 2 commits November 17, 2026 09:02
…joins`

`distributed` is no longer a value of `object_storage_cluster_join_mode`, so the
`distributed` parametrization failed with `BAD_ARGUMENTS`. Run that case with
`object_storage_cluster_join_mode='allow'` and
`allow_object_storage_cluster_distributed_join=1`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…snapshot

A worker resolves every table that the initiator's file tasks do not drive on
its own. A partner without a pinned snapshot would be read at the latest
snapshot by each worker, so a commit during the query could give different
driver files different partner snapshots.

Add `IStorageCluster::isSnapshotPinnedByTableFunction`, which is false by
default. `StorageObjectStorageCluster` returns true for an Iceberg table whose
sent table function carries `iceberg_metadata_file_path`, which a catalog table
gets from the catalog's metadata location. `replaceTablesWithTableFunctions`
declines the dispatch for any other partner, such as a `DeltaLake` or `Paimon`
table, and the query is planned as before.

`test_database_iceberg` now also checks that the driver and the partner reach a
worker with `iceberg_metadata_file_path`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@VighneshPath

Copy link
Copy Markdown
Author

Seems like for Iceberg catalog, DatabaseDataLake sets iceberg_metadata_file_path from the catalog's metadata location, and it is sent to workers with the partner's table function.
Though that is not the case for DeltaLake and Paimon so we added a commit that declines it for those.

And fixed the Spark Test.

ianton-ru
ianton-ru previously approved these changes Nov 17, 2026

@ianton-ru ianton-ru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

…_back`

The local `Memory` table name embedded a UUID with hyphens and was not quoted, so
`CREATE TABLE` failed with a syntax error before the test reached the dispatch.

CI report: https://github.com/Altinity/ClickHouse/actions/runs/44022863330

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
ianton-ru
ianton-ru previously approved these changes Nov 17, 2026
@ianton-ru ianton-ru added the port-antalya PRs to be ported to all new Antalya releases label Nov 17, 2026
@ianton-ru

Copy link
Copy Markdown

@blau-ai

@blau-ai

blau-ai commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

CI triage for 761f47e

5 failing checks: 1 needs action by the author (DCO, a process check rather than a code problem), 4 are infra or environment. None of the failures comes from the code in this PR.

Check Classification PR-caused?
DCO No Signed-off-by on any commit Process only. Needs author action
PromQL Compliance Infra: PR workflow config job produced no output No
Integration tests (amd_asan_ubsan, db disk, old analyzer, 7/8) Infra: old-version docker image missing No
Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 1/2) Job timeout (3.5h) on a Community PR runner No (evidence below)
Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 2/2) Same No

The tests run by the Community PR run had zero [ FAIL ] results. The PR's own test 05484_s3_cluster_join_mode_distributed_fallback ran 7 times (new tests are repeated) and passed: [ OK ] 3.52 sec.


1. DCO: needs a fix

None of the 14 commits has a Signed-off-by: trailer. That includes the merge commit 46dd813705 from @ianton-ru.
Fix: either the author signs off the commits (git rebase --signoff origin/antalya-26.8 followed by a force-push, which only the author can do), or a maintainer marks DCO as passed in the DCO app if that's the usual practice for this repo. No code change is needed.

2. PromQL Compliance: infra

This check belongs to the PR workflow (run 44062648576). In that run every job except this one was skipped, because the PR ran through the Community PR workflow instead. PromQL Compliance then failed because the config job had produced no output:

RuntimeError: Job output [data] of the [Config Workflow] job is empty or missing.

This is a workflow-routing problem and not related to the code.

3. Integration tests (amd_asan_ubsan, db disk, old analyzer, 7/8): infra

All 15 errors are ERROR at setup in test_backward_compatibility/* (test_const_node_optimization, test_adaptive_codec, test_parallel_replicas_protocol, test_block_marshalling, test_native_type_names_secondary_query, …). The fixture failed to pull an image:

node1 Error manifest for clickhouse/clickhouse-server:23.3.19.33.altinitystable not found: manifest unknown

That tag doesn't exist under clickhouse/clickhouse-server (Altinity stable images live under a different repo name). The same shard passes on base antalya-26.8 MasterCI (0aa837e: Failures: 0/1004), so the problem is likely specific to the Community PR environment. The previous run of this PR (44022863330) failed shards 4/8 and 7/8 as well; I didn't check whether shard 4/8 failed for the same reason. Not caused by this PR.

4–5. Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 1/2 and 2/2): timeout, not test failures

WARNING: Job timed out: [Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 1/2)], timeout [12600], exit code [-15]

Shard 1/2 got to test 3374 / 6891 before it was killed. Every test that finished was OK or SKIPPED. Throughput was about 65 tests/min for the first 30 minutes, then dropped to about 10/min from roughly 12:00 UTC until the timeout. That pattern looks like the runner degrading, not a single hung test.

Why I don't think this PR causes it:

  • The same shard timed out on an unrelated PR running on the same Community PR runners (fix-sccache-bucket, run 43923185057, Job timed out … timeout [12600] at 4971 / 6890, on a github-hetzner-runner-*).
  • On base antalya-26.8 MasterCI (0aa837e) the same shards pass in 2.2h and 2.5h (Failed: 0, Passed: 6743 and 6790). That run used the regular CI runners, not the Hetzner ones.
  • The new code can't run unless the user opts in. allow_object_storage_cluster_distributed_join defaults to false, and findDistributedObjectStorageCandidate returns on that check first, so ordinary stateless queries skip the new planner path entirely.
  • Stateless tests (amd_binary, cas s3 storage, parallel) passed in this same run.

One caveat: this PR got through fewer tests (49%) than the unrelated PR did (72%), so runner speed clearly varies. If you want a definitive answer, re-run these two shards, or check whether the regular PR workflow can run them on the standard runners.


Suggested next steps

  1. Fix DCO (sign off the commits, or a maintainer override).
  2. Re-run the two asan cas-s3 stateless shards. They are timeouts with no failed tests.
  3. Raise the integration 7/8 image-tag problem (clickhouse/clickhouse-server:23.3.19.33.altinitystable) with CI/infra. It's independent of this PR.
  4. Ignore PromQL Compliance. It's a side effect of the PR workflow config being skipped.

No praktika result_pr.json was uploaded for this commit (the Community PR workflow runs with an empty S3_ARTIFACT_BUCKET), so this triage is based on the GitHub Actions logs.

@Selfeer

Selfeer commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Defects in #2832

Medium: x IN db.table is sent to workers as a catalog table name

Description

With allow_object_storage_cluster_distributed_join = 1, a query that uses the short form x IN db.table against a DataLakeCatalog table is still dispatched. That table is sent to the workers by name instead of as a table function.

The analyzer keeps the right side of IN as a TableNode (resolveFunction.cpp). The eligibility check (allWorkerLocalTableReferencesAreSafe) accepts it as a safe catalog table. When serialized, a TableNode becomes a plain ASTTableIdentifier (TableNode::toASTImpl). replaceTablesWithTableFunctions only rewrites tables inside an ASTTableExpression, so this name is never replaced. The driver count stays at 1, so the query is dispatched with IN db.table unchanged.

Each worker then has to resolve db.table itself:

  • If the worker has no such catalog database, which is the usual case for swarm nodes, the query fails. The same query works with the setting off, or when written as IN (SELECT k FROM db.table).
  • If the worker does have the database, it resolves the latest snapshot itself. That breaks the guarantee this PR added in "Dispatch a whole JOIN only when its partner tables are pinned to a snapshot": workers can see different snapshots of the IN table during a concurrent commit.

Steps to reproduce

  1. On the initiator only, create a DataLakeCatalog database dl whose tables use object_storage_cluster = 'swarm'. The workers in swarm do not define dl. Create three Iceberg tables: ns.facts (id Int64, k Int64), ns.dim (k Int64, name String) and ns.keys (k Int64), and insert a few rows into each.

  2. Look at the query the initiator would send:

    EXPLAIN actions = 1
    SELECT d.name, count()
    FROM dl.`ns.facts` AS f
    INNER JOIN dl.`ns.dim` AS d ON f.k = d.k
    WHERE f.k IN dl.`ns.keys`
    GROUP BY d.name
    SETTINGS allow_object_storage_cluster_distributed_join = 1;

    In the Query: line of the ReadFromClusterQuery step, facts and dim have become table functions, but the filter still reads IN dl.`ns.keys` .

  3. Run the same SELECT without EXPLAIN.

  • Expected: the same result as with allow_object_storage_cluster_distributed_join = 0.
  • Actual: a worker fails with UNKNOWN_DATABASE for dl. Writing WHERE f.k IN (SELECT k FROM dl.ns.keys) instead returns the correct result.

@Selfeer Selfeer added the verified Approved for release label Nov 19, 2026
VighneshPath and others added 2 commits November 23, 2026 19:37
The short form `x IN db.table` keeps the right side as a `TableNode`. It is
serialized as a bare `ASTTableIdentifier`, outside any table expression, so
`replaceTablesWithTableFunctions` does not replace it and the worker receives the
catalog table name. A worker without the catalog database fails with
`UNKNOWN_DATABASE`, and cluster reads skip that error, so the failure can go
unreported. A worker that has the database reads the table's latest snapshot
instead of the one the initiator resolved.

Decline the dispatch when any table name is left after the rewrite, and plan the
query as before. `x IN (SELECT ... FROM db.table)` is a table expression and is
still dispatched.

Related: Altinity#2832

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: VighneshPath <[email protected]>
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 5d0d315
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 71f8322
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 27463bb
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 1498722
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 15de517
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: b9f715e
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: e942cd0
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 7f73306
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 31d7185
I, VighneshPath <[email protected]>, hereby add my Signed-off-by to this commit: 761f47e

Signed-off-by: VighneshPath <[email protected]>
VighneshPath and others added 3 commits November 23, 2026 19:49
…tion

`antalya-26.8` added the `add_structure_and_format` parameter to
`IStorageCluster::updateQueryToSendIfNeeded`. The merge into this branch left
`getTableFunctionToSend` with the old four arguments, so `IStorageCluster.cpp`
did not compile. Pass `true`, as both read paths do: a dispatched query is a
`SELECT`, so every node needs the structure and format to produce the
initiator's header.

CI report: https://github.com/Altinity/ClickHouse/actions/runs/45192929403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: VighneshPath <[email protected]>
@zvonand zvonand removed the verified Approved for release label Nov 24, 2026
@zvonand

zvonand commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

New commits were added. needs review and verification again. verified label removed

@ianton-ru ianton-ru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@Selfeer

Selfeer commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

With allow_object_storage_cluster_distributed_join = 1, a non-deterministic subquery on the right side of the JOIN is computed separately by each worker. Workers can pick different values, and the initiator then adds up results that no single run of the subquery would give. The query succeeds and returns wrong totals. With the setting off, this never happened.

Setup

  • A 2-node cluster default_cluster with an Iceberg REST catalog, mounted on both nodes as rest (DataLakeCatalog).
  • rest.`demo.fact`: 16 data files of 100 rows each, all with tag = 1 (1600 rows), so both nodes get fact files.
  • rest.`demo.dim`: 8 one-row data files, all with id = 1, with city alternating berlin / paris.

Query, run 40 times with each setting value:

SELECT d.city, count() AS c
FROM rest.`demo.fact` AS f
INNER JOIN
(
    SELECT id, any(city) AS city
    FROM rest.`demo.dim`
    GROUP BY id
) AS d ON f.tag = d.id
GROUP BY d.city
ORDER BY d.city
SETTINGS object_storage_cluster = 'default_cluster',
         allow_object_storage_cluster_distributed_join = 0;  -- then 1

-- Setting 0 (40 runs): always one row
-- 21x  berlin  1600
-- 19x  paris   1600

-- Setting 1 (40 runs): 4 runs split id = 1 across both cities
-- 36x  paris   1600
--  2x  berlin  900  |  paris  700
--  2x  berlin  700  |  paris  900

The right answer is one row with all 1600 fact rows, under whichever city any() picks. A split result means the two workers picked different cities. The split sizes are exactly the fact rows each node read. In system.query_log, each node ran the whole query, any(city) ... GROUP BY id included, as a secondary query, and each read all 8 dim rows itself (read_rows 708 and 908 = 700 / 900 fact rows + 8 dim rows).

Why

In src/Planner/findDistributedObjectStorageCandidate.cpp, isSafeIntermediateSubquery (rejects GROUP BY, aggregates, LIMIT, OFFSET, DISTINCT) is applied only on the left side of the join, the side that leads to the driving table (findDriverOnLeftSpine). allWorkerLocalTableReferencesAreSafe checks only that the other tables are catalog tables, so a right-side subquery is never checked.

Notes

  • It is a race: about 10% of runs split here (3/40, 4/40 and 4/40 in three runs). A passing run does not mean the query is safe.
  • The INNER JOIN (SELECT * FROM dim LIMIT 1) form did not reproduce with this data: 0 of 320 runs split, always paris with the setting on (with it off, the city varies). Each worker probably reads dim in the same pinned file order, so all keep the same row. I did not check that. The code path is the same, and other data might expose it.
  • A plain catalog table as the partner is not affected: every worker reads the same pinned snapshot.

@VighneshPath

Copy link
Copy Markdown
Author

Hey @Selfeer ,

I confirmed it. Snapshot pinning makes every worker read the same data. It doesn't make them compute the same result from it. Each worker computes a partner subquery itself, so any(), LIMIT without ORDER BY or rand() can give a different value on each worker.

Upstream parallel replicas seems to have the same issue with its default settings (parallel_replicas_prefer_local_join = 1). I reproduced your query on 26.10. With parallel_replicas_prefer_local_join = 0, the initiator computes the subquery once, and no run split.

I can decline the dispatch when a subquery outside the driver path is non-deterministic, so the query runs the normal way. The setting is experimental and off by default, so I can fix it in a new PR and link the issue here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

antalya antalya-26.8 antalya-26.8.39.20001 port-antalya PRs to be ported to all new Antalya releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants