Skip to content

Commit 4e09bb9

Browse files
authored
Merge d95780d into f1765fb
2 parents f1765fb + d95780d commit 4e09bb9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ydb/library/yql/minikql/comp_nodes/mkql_wide_combine.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <util/string/cast.h>
1818

19+
#include <contrib/libs/xxhash/xxhash.h>
20+
1921
namespace NKikimr {
2022
namespace NMiniKQL {
2123

@@ -485,7 +487,8 @@ class TSpillingSupportState : public TComputationValue<TSpillingSupportState> {
485487
}
486488

487489
auto hash = Hasher(ViewForKeyAndState.data());
488-
auto bucketId = hash % SpilledBucketCount;
490+
XXH64_hash_t hashed_hash = XXH64(&hash, sizeof(hash), 0);
491+
auto bucketId = hashed_hash % SpilledBucketCount;
489492
auto& bucket = SpilledBuckets[bucketId];
490493

491494
if (bucket.BucketState == TSpilledBucket::EBucketState::InMemory) {
@@ -592,8 +595,9 @@ class TSpillingSupportState : public TComputationValue<TSpillingSupportState> {
592595
SplitStateSpillingBucket = -1;
593596
}
594597
while (const auto keyAndState = static_cast<NUdf::TUnboxedValue *>(InMemoryProcessingState.Extract())) {
595-
auto hash = Hasher(keyAndState); //Hasher uses only key for hashing
596-
auto bucketId = hash % SpilledBucketCount;
598+
auto hash = Hasher(keyAndState); //Hasher uses only key for hashing
599+
XXH64_hash_t hashed_hash = XXH64(&hash, sizeof(hash), 0);
600+
auto bucketId = hashed_hash % SpilledBucketCount;
597601
auto& bucket = SpilledBuckets[bucketId];
598602

599603
bucket.LineCount++;
@@ -842,6 +846,12 @@ class TSpillingSupportState : public TComputationValue<TSpillingSupportState> {
842846
break;
843847
}
844848
case EOperatingMode::ProcessSpilled: {
849+
std::sort(SpilledBuckets.begin(), SpilledBuckets.end(), [](const TSpilledBucket& lhs, const TSpilledBucket& rhs) {
850+
bool lhs_in_memory = lhs.BucketState == TSpilledBucket::EBucketState::InMemory;
851+
bool rhs_in_memory = rhs.BucketState == TSpilledBucket::EBucketState::InMemory;
852+
return lhs_in_memory > rhs_in_memory;
853+
});
854+
845855
YQL_LOG(INFO) << "switching Memory mode to ProcessSpilled";
846856
MKQL_ENSURE(EOperatingMode::Spilling == Mode, "Internal logic error");
847857
MKQL_ENSURE(SpilledBuckets.size() == SpilledBucketCount, "Internal logic error");

0 commit comments

Comments
 (0)