Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize single partition spilling (#6271) #396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions velox/exec/Spiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,25 @@ void Spiller::fillSpillRuns(SpillRows* rowsFromNonSpillingPartitions) {
constexpr int32_t kHashBatchSize = 4096;
std::vector<uint64_t> hashes(kHashBatchSize);
std::vector<char*> rows(kHashBatchSize);
VELOX_CHECK((type_ != Type::kOrderBy) || bits_.numPartitions() == 1);
const bool isSinglePartition =
(type_ == Type::kOrderBy || bits_.numPartitions() == 1);
for (;;) {
auto numRows = container_->listRows(
&iterator, rows.size(), RowContainer::kUnlimited, rows.data());
// Calculate hashes for this batch of spill candidates.
auto rowSet = folly::Range<char**>(rows.data(), numRows);
for (auto i = 0; i < container_->keyTypes().size(); ++i) {
container_->hash(i, rowSet, i > 0, hashes.data());
if (!isSinglePartition) {
for (auto i = 0; i < container_->keyTypes().size(); ++i) {
container_->hash(i, rowSet, i > 0, hashes.data());
}
}

// Put each in its run.
for (auto i = 0; i < numRows; ++i) {
// TODO: consider to cache the hash bits in row container so we only need
// to calculate them once.
const auto partition = (type_ == Type::kOrderBy)
const auto partition = isSinglePartition
? 0
: bits_.partition(hashes[i], state_.maxPartitions());
VELOX_DCHECK_GE(partition, 0);
Expand Down
Loading