Repository navigation
Open
Description
I have this data
SELECT *
FROM s3Cluster(replicated_cluster, 'http://minio:9000/warehouse/data3/data/**.parquet', 'admin', 'password')1. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
2. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
3. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
4. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
5. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
6. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
7. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
8. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 12:00:00.000000 │ 2024-01-01 │ 1970-01-01 12:00:00.000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
└─────────────┴──────────┴────────────┴────────────┴────────────────────────────┴────────────┴────────────────────────────┴────────────────────────────┴─────────────┴───────────┴─────────────┘
8 rows in set. Elapsed: 0.119 sec.
SELECT *
FROM icebergS3Cluster(replicated_cluster, 'http://minio:9000/warehouse/data1', 'admin', 'password')1. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
2. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
3. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
4. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
5. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
6. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
7. │ true │ 1000 │ 456.78 │ Alice │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 1000 │ 456.78 │ 456.78 │
8. │ false │ 2000 │ 456.78 │ Bob │ 2024-01-01 13:00:00.000000 │ 2024-01-01 │ 43200000000 │ 2024-01-01 12:00:00.000000 │ 2000 │ 456.78 │ 456.78 │
└─────────────┴──────────┴────────────┴────────────┴────────────────────────────┴────────────┴─────────────┴────────────────────────────┴─────────────┴───────────┴─────────────┘
8 rows in set. Elapsed: 0.132 sec.
I also have merge tree tables with same exact data and expected join result is calculated using those merge tree tables:
SELECT *
FROM table_3898404a_3a8b_11f1_995b_de7b9eea348f AS t1
ANY INNER JOIN table_38c3eb3c_3a8b_11f1_995b_de7b9eea348f AS t2 ON (t1.boolean_col = t2.boolean_col) AND (t1.string_col = t2.string_col)
ORDER BY tuple(*) ASC
FORMAT TabSeparatedQuery id: 46d4e498-66ab-4038-a7cb-21572550a760
false 2000 456.78 Bob 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 2000 456.78 456.78 false 2000 456.78 Bob 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 2000 456.78 456.78
true 1000 456.78 Alice 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 1000 456.78 456.78 true 1000 456.78 Alice 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 1000 456.78 456.78
2 rows in set. Elapsed: 0.010 sec.
The same join but with object_storage_cluster_join_mode = 'global', object_storage_cluster = 'replicated_cluster' returnes 6 rows instead of 2:
SELECT *
FROM s3Cluster(replicated_cluster, 'http://minio:9000/warehouse/data3/data/**.parquet', 'admin', 'password') AS t1
ANY INNER JOIN icebergS3Cluster(replicated_cluster, 'http://minio:9000/warehouse/data1', 'admin', 'password') AS t2 ON (t1.boolean_col = t2.boolean_col) AND (t1.string_col = t2.string_col)
ORDER BY tuple(*) ASC
SETTINGS object_storage_cluster_join_mode = 'global', object_storage_cluster = 'replicated_cluster'
FORMAT TabSeparatedQuery id: af48112f-995c-47fe-b5e1-a5466955f9be
false 2000 456.78 Bob 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 2000 456.78 456.78 false 2000 456.78 Bob 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 2000 456.78 456.78
false 2000 456.78 Bob 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 2000 456.78 456.78 false 2000 456.78 Bob 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 2000 456.78 456.78
false 2000 456.78 Bob 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 2000 456.78 456.78 false 2000 456.78 Bob 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 2000 456.78 456.78
true 1000 456.78 Alice 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 1000 456.78 456.78 true 1000 456.78 Alice 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 1000 456.78 456.78
true 1000 456.78 Alice 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 1000 456.78 456.78 true 1000 456.78 Alice 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 1000 456.78 456.78
true 1000 456.78 Alice 2024-01-01 12:00:00.000000 2024-01-01 1970-01-01 12:00:00.000000 2024-01-01 12:00:00.000000 1000 456.78 456.78 true 1000 456.78 Alice 2024-01-01 13:00:00.000000 2024-01-01 43200000000 2024-01-01 12:00:00.000000 1000 456.78 456.78
6 rows in set. Elapsed: 0.427 sec.
Activity
alsugiliazova commentedon Apr 17, 2026
Root Cause Analysis: Issue #1661 — ANY INNER JOIN duplicates with
object_storage_cluster_join_mode='global'Issue: Altinity/ClickHouse #1661
Branch:
feature/antalya-26.1/json_part2(PR #1527 — Cluster Joins part 2)Confirmed defect
Severity: High — correctness failure, returns wrong number of rows under realistic workload.
Title:
ANY INNER JOINdeduplication is per-shard instead of global inobject_storage_cluster_join_mode='global'Impact: Queries using
ANY INNER JOIN(or otherANYstrictness variants) between cluster table functions withobject_storage_cluster_join_mode='global'returnnum_shards × expected_rowsinstead ofexpected_rows.Affected file/function:
src/Storages/IStorageCluster.cpp—IStorageCluster::getQueryProcessingStageProof sketch
ANY INNER JOINin ClickHouse's HashJoin usesused_flags.setUsedOnce()to output only one row per unique join key — the first left row that matches a right key claims that key; all subsequent left rows with the same key are filtered out (src/Interpreters/HashJoin/HashJoinMethodsImpl.h, lines 438–448).In LOCAL mode,
getQueryProcessingStagereturnsFetchColumnswhen a join is detected (line 654). This means shards only send raw left-side data back to the initiator, and the join executes once on the initiator. ThesetUsedOncetracking works globally — correct result.In GLOBAL mode, there is no special handling in
getQueryProcessingStage— it falls through toWithMergeableState(line 661). This means each shard independently executes the fullANY INNER JOINquery (with the right side materialized into a temp table). Each shard has its own localused_flags, sosetUsedOncefires independently on every shard. Each shard that has left-side rows matching a key produces one output row for that key.Results from all shards are concatenated by the initiator (
ReadFromCluster::initializePipeline, line 534) with no re-application ofANYdeduplication.With a 3-shard cluster where each shard has left-side rows for both keys (Alice/true and Bob/false): each shard outputs 2 rows → total 6 rows instead of 2.
Reproduction steps
replicated_cluster.SELECT * FROM s3Cluster(...) AS t1 ANY INNER JOIN icebergS3Cluster(...) AS t2 ON ... SETTINGS object_storage_cluster_join_mode = 'global'.Likely fix direction
Handle GLOBAL mode in
getQueryProcessingStageto avoid pushingANY-strictness joins down to shards — either returnFetchColumns(same as LOCAL), or add a post-join deduplication step on the initiator, or rewriteANYtoALLin the shard query and re-applyANYsemantics on the initiator.Regression test direction
Add a test that verifies
ANY INNER JOINbetween cluster table functions withobject_storage_cluster_join_mode='global'returns the same row count as the equivalent single-node MergeTree join.Affected subsystem and blast radius
Affects all
ANY-strictness joins (ANY INNER,ANY LEFT) executed viaobject_storage_cluster_join_mode='global'on any cluster table function (s3Cluster,icebergS3Cluster, etc.). TheLOCALandALLOWmodes are not affected.Coverage summary
IStorageCluster::getQueryProcessingStage,IStorageCluster::updateQueryWithJoinToSendIfNeeded(GLOBAL path),buildQueryTreeForShard,rewriteJoinToGlobalJoin,ReadFromCluster::initializePipeline, HashJoinANY INNERimplementation.ANYstrictness in GLOBAL mode.ianton-ru commentedon Apr 20, 2026
Join over cluster function reuses algorithm of join over distributed tables.
Join over distributed tables has the same issue in upstream.
On upstream version 26.2.4.23:
Cluster 'shards' has three shard, each with one replica.
See ClickHouse#65478 for example
Issue confirmed, but more global than current PR.