Skip to content

Commit 299a68a

Browse files
authored
Merge be9bb5e into c4e0dc4
2 parents c4e0dc4 + be9bb5e commit 299a68a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ydb/library/yql/dq/runtime/dq_output_consumer.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ using namespace NKikimr;
2020
using namespace NMiniKQL;
2121
using namespace NUdf;
2222

23+
inline ui64 SpreadHash(ui64 hash) {
24+
// https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
25+
return ((unsigned __int128)hash * 11400714819323198485llu) >> 64;
26+
}
27+
2328

2429
class TDqOutputMultiConsumer : public IDqOutputConsumer {
2530
public:
@@ -189,6 +194,9 @@ class TDqOutputHashPartitionConsumer : public IDqOutputConsumer {
189194
hash = CombineHashes(hash, HashColumn(keyId, columnValue));
190195
}
191196

197+
198+
hash = SpreadHash(hash);
199+
192200
return hash % Outputs.size();
193201
}
194202

@@ -200,6 +208,8 @@ class TDqOutputHashPartitionConsumer : public IDqOutputConsumer {
200208
hash = CombineHashes(hash, HashColumn(keyId, values[KeyColumns[keyId].Index]));
201209
}
202210

211+
hash = SpreadHash(hash);
212+
203213
return hash % Outputs.size();
204214
}
205215

@@ -303,6 +313,8 @@ class TDqOutputHashPartitionConsumerScalar : public IDqOutputConsumer {
303313
hash = CombineHashes(hash, HashColumn(keyId, values[KeyColumns_[keyId].Index]));
304314
}
305315

316+
hash = SpreadHash(hash);
317+
306318
return hash % Outputs_.size();
307319
}
308320

@@ -500,6 +512,9 @@ class TDqOutputHashPartitionConsumerBlock : public IDqOutputConsumer {
500512
}
501513
hash = CombineHashes(hash, keyHash);
502514
}
515+
516+
hash = SpreadHash(hash);
517+
503518
return hash % Outputs_.size();
504519
}
505520

0 commit comments

Comments
 (0)