Repository navigation
Add allow_object_storage_cluster_distributed_join for whole-query JOIN dispatch - #2832
Conversation
…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]>
…cluster-distributed-join
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…cluster-distributed-join
|
@codex review |
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
The whole-query dispatch now respects object_storage_cluster_fallback_to_local_if_empty
`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
|
Make sense add new option in docs: https://github.com/Altinity/ClickHouse/blob/antalya-26.8/docs/reference/statements/select/join.mdx#object_storage_cluster_join_mode-object-storage-cluster-join-mode, but is it optional, we can do it later. |
|
|
||
| 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"( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Okay, yeah this seems better
I can make the change
There was a problem hiding this comment.
Done, have added allow_object_storage_cluster_distributed_join which fall backs to object_storage_cluster_join_mode
…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]>
object_storage_cluster_join_mode='distributed' for whole-query JOIN dispatchallow_object_storage_cluster_distributed_join for whole-query JOIN dispatch
|
Settings looks good now from my point of view. New issues from AI. Medium: Partner tables are not pinned to the initiator snapshotA 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.
Trigger. Why this is a defect. The driver file list is one initiator snapshot. Each partner is sent as a plain table function, Anchor.
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 changedLow: Spark integration test passes a removed join-mode value
Trigger. The new parametrization reaches Why this is a defect. The PR adds Anchor. Fix direction. For that case set Regression test. Run The PR changes the parameter list to include SETTINGS
object_storage_cluster='cluster_simple',
object_storage_cluster_join_mode='{join_mode}' |
…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]>
|
Seems like for Iceberg catalog, And fixed the Spark Test. |
…cluster-distributed-join
…_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]>
CI triage for 761f47e5 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.
The tests run by the Community PR run had zero 1. DCO: needs a fixNone of the 14 commits has a 2. PromQL Compliance: infraThis check belongs to the This is a workflow-routing problem and not related to the code. 3. Integration tests (amd_asan_ubsan, db disk, old analyzer, 7/8): infraAll 15 errors are That tag doesn't exist under 4–5. Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 1/2 and 2/2): timeout, not test failuresShard 1/2 got to test Why I don't think this PR causes it:
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 Suggested next steps
No praktika |
Defects in #2832
Medium:
|
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]>
…cluster-distributed-join
…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]>
…cluster-distributed-join
|
New commits were added. needs review and verification again. |
|
With Setup
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 900The right answer is one row with all 1600 fact rows, under whichever city Why In Notes
|
|
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 Upstream parallel replicas seems to have the same issue with its default settings ( 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. |
Port of #2383 to
antalya-26.8, with that PR's review comments addressed.With
allow_object_storage_cluster_distributed_join = 1, aJOINquery whose driving table is aDataLakecatalog table withobject_storage_clusterset is sent whole to that cluster. Each node runs theJOINand anyGROUP BYover its share of the driver's files, and the initiator only merges the partial aggregate states. Before this, theJOINandGROUP BYalways ran on the initiator. A query that is not eligible is planned as before, as set byobject_storage_cluster_join_mode.The setting is a separate boolean,
EXPERIMENTALandfalseby default, instead of a new value ofobject_storage_cluster_join_mode. So the existinglocal/global/allowmodes keep their meaning, and the server settingallow_feature_tiercan block it.findDistributedObjectStorageCandidatewalks the left side of the query, throughINNER ALL/LEFTjoins and through subqueries that do not combine rows, to the driver. Every other table must be a catalog table with no row policy and withSELECTaccess. Otherwise the whole query is planned as before.buildDistributedObjectStorageQueryPlansends the query with every table replaced by the table function its own cluster read would send: the driver as its*Clusterfunction, which reads the files the initiator hands out, and every other table as its plain function, which each node reads in full.ReadFromClusterQuerysends the query over the same transport asReadFromCluster. It hands out the driver's files, pruned by the driver's own filter.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.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.system.query_log.Related: #2383
Changelog category (leave one):
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 wholeJOINquery overDataLakecatalog tables to the cluster of its driving table, so that theJOINandGROUP BYrun 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.mdxand in the settings table ofdocs/en/antalya/swarm.md.CI/CD Options
Exclude tests:
Regression jobs to run:
🤖 Generated with Claude Code