Skip to content

Commit

Permalink
Backport #59606 to 24.1: Fix distributed table with a constant shardi…
Browse files Browse the repository at this point in the history
…ng key
  • Loading branch information
robot-clickhouse committed Feb 6, 2024
1 parent 50ce0f2 commit 4b0ad9d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Storages/StorageDistributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,10 +1540,7 @@ ClusterPtr StorageDistributed::getOptimizedCluster(
IColumn::Selector StorageDistributed::createSelector(const ClusterPtr cluster, const ColumnWithTypeAndName & result)
{
const auto & slot_to_shard = cluster->getSlotToShard();

const IColumn * column = result.column.get();
if (const auto * col_const = typeid_cast<const ColumnConst *>(column))
column = &col_const->getDataColumn();

// If result.type is DataTypeLowCardinality, do shard according to its dictionaryType
#define CREATE_FOR_TYPE(TYPE) \
Expand Down
7 changes: 7 additions & 0 deletions tests/queries/0_stateless/02983_const_sharding_key.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1
2
3
4
5
6
7
26 changes: 26 additions & 0 deletions tests/queries/0_stateless/02983_const_sharding_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Tags: distributed, no-parallel

DROP DATABASE IF EXISTS shard_0;
DROP DATABASE IF EXISTS shard_1;
DROP TABLE IF EXISTS t_distr;

CREATE DATABASE IF NOT EXISTS shard_0;
CREATE DATABASE IF NOT EXISTS shard_1;

CREATE TABLE shard_0.t_local (a Int) ENGINE = Memory;
CREATE TABLE shard_1.t_local (a Int) ENGINE = Memory;
CREATE TABLE t_distr (a Int) ENGINE = Distributed(test_cluster_two_shards_different_databases, '', 't_local', 1000);

SET distributed_foreground_insert=0;
INSERT INTO t_distr VALUES (1), (2), (3);

SET distributed_foreground_insert=1;
INSERT INTO t_distr VALUES (4), (5), (6), (7);

SYSTEM FLUSH DISTRIBUTED t_distr;

SELECT * FROM t_distr ORDER BY a;

DROP TABLE t_distr;
DROP DATABASE shard_0;
DROP DATABASE shard_1;

0 comments on commit 4b0ad9d

Please sign in to comment.