From 9f13008aae92f0163bd1193253800236cc489d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lisen=20=E6=9D=A8?= Date: Mon, 13 May 2024 14:53:06 +0800 Subject: [PATCH] tweak default sharding rule for one shard stream with primary keys --- src/Interpreters/Streaming/DDLHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/Streaming/DDLHelper.cpp b/src/Interpreters/Streaming/DDLHelper.cpp index 51a2caadee9..bb2a9706f99 100644 --- a/src/Interpreters/Streaming/DDLHelper.cpp +++ b/src/Interpreters/Streaming/DDLHelper.cpp @@ -175,9 +175,9 @@ void prepareEngine(ASTCreateQuery & create, ContextPtr ctx) if (expr.empty()) { /// Default sharding expr: - /// 1) If has primary keys, default is `weak_hash32()` + /// 1) If has multiple shards and has primary keys, default is `weak_hash32()` /// 2) Otherwise, default is `rand()` - if (create.storage->primary_key) + if (shards > 1 && create.storage->primary_key) sharding_expr = makeASTFunction("weak_hash32", create.storage->primary_key->clone()); else sharding_expr = makeASTFunction("rand");