You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/11/21 22:54:33 UTC
[impala] branch master updated: IMPALA-9126: part 1: hash join
build partition cleanup
This is an automated email from the ASF dual-hosted git repository.
tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
The following commit(s) were added to refs/heads/master by this push:
new abdd5ab IMPALA-9126: part 1: hash join build partition cleanup
abdd5ab is described below
commit abdd5ab7de8144b21ca320a9ad20565d543f01e6
Author: Tim Armstrong <ta...@cloudera.com>
AuthorDate: Mon Nov 4 16:59:24 2019 -0800
IMPALA-9126: part 1: hash join build partition cleanup
Clarify some invariants (e.g. which join modes actually
require build partition data to be attached to row batches).
Move some logic for maintenance of the hash partitions to
the builder.
Testing:
Ran exhaustive tests. We should already have adequate coverage for
spilling and non-spilling hash joins.
Change-Id: Ife8d0fa5dd14c7d3f3d726dd38c07d8cbceabadb
Reviewed-on: http://gerrit.cloudera.org:8080/14632
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
be/src/exec/blocking-join-node.cc | 10 +--
be/src/exec/blocking-join-node.h | 11 +--
be/src/exec/join-op.h | 48 +++++++++++++
be/src/exec/nested-loop-join-node.cc | 2 +-
be/src/exec/partitioned-hash-join-builder.cc | 27 ++++++-
be/src/exec/partitioned-hash-join-builder.h | 65 +++++++++--------
be/src/exec/partitioned-hash-join-node.cc | 103 ++++++++++++---------------
be/src/exec/partitioned-hash-join-node.h | 6 +-
8 files changed, 166 insertions(+), 106 deletions(-)
diff --git a/be/src/exec/blocking-join-node.cc b/be/src/exec/blocking-join-node.cc
index fabfc5f..a352c70 100644
--- a/be/src/exec/blocking-join-node.cc
+++ b/be/src/exec/blocking-join-node.cc
@@ -54,9 +54,7 @@ BlockingJoinNode::BlockingJoinNode(const string& node_name, const TJoinOp::type
Status BlockingJoinNode::Init(const TPlanNode& tnode, RuntimeState* state) {
RETURN_IF_ERROR(ExecNode::Init(tnode, state));
- DCHECK((join_op_ != TJoinOp::LEFT_SEMI_JOIN && join_op_ != TJoinOp::LEFT_ANTI_JOIN &&
- join_op_ != TJoinOp::RIGHT_SEMI_JOIN && join_op_ != TJoinOp::RIGHT_ANTI_JOIN &&
- join_op_ != TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN) || conjuncts_.size() == 0);
+ DCHECK(!IsSemiJoin(join_op_) || conjuncts_.size() == 0);
runtime_profile_->AddLocalTimeCounter(
bind<int64_t>(&BlockingJoinNode::LocalTimeCounterFn,
runtime_profile_->total_time_counter(),
@@ -123,9 +121,7 @@ Status BlockingJoinNode::Prepare(RuntimeState* state) {
probe_tuple_row_size_ = num_left_tuples * sizeof(Tuple*);
build_tuple_row_size_ = num_build_tuples * sizeof(Tuple*);
- if (join_op_ == TJoinOp::LEFT_ANTI_JOIN || join_op_ == TJoinOp::LEFT_SEMI_JOIN ||
- join_op_ == TJoinOp::RIGHT_ANTI_JOIN || join_op_ == TJoinOp::RIGHT_SEMI_JOIN ||
- join_op_ == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN) {
+ if (IsSemiJoin(join_op_)) {
semi_join_staging_row_ = reinterpret_cast<TupleRow*>(
new char[probe_tuple_row_size_ + build_tuple_row_size_]);
}
@@ -273,7 +269,7 @@ Status BlockingJoinNode::GetFirstProbeRow(RuntimeState* state) {
} else if (probe_side_eos_) {
// If the probe side is exhausted, set the eos_ to true for only those
// join modes that don't need to process unmatched build rows.
- eos_ = !NeedToProcessUnmatchedBuildRows();
+ eos_ = !NeedToProcessUnmatchedBuildRows(join_op_);
return Status::OK();
}
probe_batch_->Reset();
diff --git a/be/src/exec/blocking-join-node.h b/be/src/exec/blocking-join-node.h
index 2f1c161..015738d 100644
--- a/be/src/exec/blocking-join-node.h
+++ b/be/src/exec/blocking-join-node.h
@@ -24,11 +24,10 @@
#include <string>
#include "exec/exec-node.h"
+#include "exec/join-op.h"
#include "util/promise.h"
#include "util/stopwatch.h"
-#include "gen-cpp/PlanNodes_types.h" // for TJoinOp
-
namespace impala {
class RowBatch;
@@ -154,14 +153,6 @@ class BlockingJoinNode : public ExecNode {
/// This is replaced by codegen.
void CreateOutputRow(TupleRow* out_row, TupleRow* probe_row, TupleRow* build_row);
- /// Returns true if the join needs to process unmatched build rows, false
- /// otherwise.
- bool NeedToProcessUnmatchedBuildRows() {
- return join_op_ == TJoinOp::RIGHT_ANTI_JOIN ||
- join_op_ == TJoinOp::RIGHT_OUTER_JOIN ||
- join_op_ == TJoinOp::FULL_OUTER_JOIN;
- }
-
/// This function calculates the "local time" spent in the join node.
///
/// The definition of "local time" is the wall clock time where this exec node is
diff --git a/be/src/exec/join-op.h b/be/src/exec/join-op.h
new file mode 100644
index 0000000..ce857a0
--- /dev/null
+++ b/be/src/exec/join-op.h
@@ -0,0 +1,48 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Helpers for working with the different join operations.
+#pragma once
+
+#include "gen-cpp/PlanNodes_types.h" // for TJoinOp
+
+namespace impala {
+
+/// Returns true if this is a semi-join that does not return tuple data from the
+/// build rows.
+inline bool IsLeftSemiJoin(TJoinOp::type join_op) {
+ return join_op == TJoinOp::LEFT_ANTI_JOIN || join_op == TJoinOp::LEFT_SEMI_JOIN
+ || join_op == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN;
+}
+
+/// Returns true if this is a semi-join that does not return tuple data from the
+/// probe rows.
+inline bool IsRightSemiJoin(TJoinOp::type join_op) {
+ return join_op == TJoinOp::RIGHT_ANTI_JOIN || join_op == TJoinOp::RIGHT_SEMI_JOIN;
+}
+
+inline bool IsSemiJoin(TJoinOp::type join_op) {
+ return IsLeftSemiJoin(join_op) || IsRightSemiJoin(join_op);
+}
+
+/// Returns true if the join needs to process unmatched build rows, false
+/// otherwise.
+inline bool NeedToProcessUnmatchedBuildRows(TJoinOp::type join_op) {
+ return join_op == TJoinOp::RIGHT_ANTI_JOIN || join_op == TJoinOp::RIGHT_OUTER_JOIN
+ || join_op == TJoinOp::FULL_OUTER_JOIN;
+}
+} // namespace impala
diff --git a/be/src/exec/nested-loop-join-node.cc b/be/src/exec/nested-loop-join-node.cc
index 8545348..2278258 100644
--- a/be/src/exec/nested-loop-join-node.cc
+++ b/be/src/exec/nested-loop-join-node.cc
@@ -640,7 +640,7 @@ Status NestedLoopJoinNode::NextProbeRow(RuntimeState* state, RowBatch* output_ba
// memory referenced by this batch to be deleted (see IMPALA-2191).
if (output_batch->AtCapacity()) return Status::OK();
if (probe_side_eos_) {
- eos_ = !NeedToProcessUnmatchedBuildRows();
+ eos_ = !NeedToProcessUnmatchedBuildRows(join_op_);
return Status::OK();
} else {
RETURN_IF_ERROR(child(0)->GetNext(state, probe_batch_.get(), &probe_side_eos_));
diff --git a/be/src/exec/partitioned-hash-join-builder.cc b/be/src/exec/partitioned-hash-join-builder.cc
index f896571..818017d 100644
--- a/be/src/exec/partitioned-hash-join-builder.cc
+++ b/be/src/exec/partitioned-hash-join-builder.cc
@@ -451,6 +451,28 @@ vector<unique_ptr<BufferedTupleStream>> PhjBuilder::TransferProbeStreams() {
return std::move(spilled_partition_probe_streams_);
}
+void PhjBuilder::DoneProbing(const bool retain_partition[PARTITION_FANOUT],
+ list<Partition*>* output_partitions, RowBatch* batch) {
+ DCHECK(output_partitions->empty());
+ for (int i = 0; i < PARTITION_FANOUT; ++i) {
+ PhjBuilder::Partition* partition = hash_partitions_[i];
+ if (partition->IsClosed()) continue;
+ if (partition->is_spilled()) {
+ DCHECK(partition->hash_tbl() == nullptr) << DebugString();
+ DCHECK_EQ(partition->build_rows()->BytesPinned(false), 0)
+ << "Build was fully unpinned in BuildHashTablesAndPrepareProbeStreams()";
+ // Release resources associated with completed partitions.
+ if (!retain_partition[i]) partition->Close(nullptr);
+ } else if (NeedToProcessUnmatchedBuildRows(join_op_)) {
+ output_partitions->push_back(partition);
+ } else {
+ // No more processing is required for this partition.
+ partition->Close(batch);
+ }
+ }
+ hash_partitions_.clear();
+}
+
void PhjBuilder::CloseAndDeletePartitions(RowBatch* row_batch) {
// Close all the partitions and clean up all references to them.
for (unique_ptr<Partition>& partition : all_partitions_) partition->Close(row_batch);
@@ -458,7 +480,10 @@ void PhjBuilder::CloseAndDeletePartitions(RowBatch* row_batch) {
hash_partitions_.clear();
null_aware_partition_ = NULL;
for (unique_ptr<BufferedTupleStream>& stream : spilled_partition_probe_streams_) {
- stream->Close(row_batch, RowBatch::FlushMode::NO_FLUSH_RESOURCES);
+ // Streams need to be cleaned up, but were never handed off to probe, so won't have
+ // any data in them.
+ DCHECK_EQ(0, stream->num_rows());
+ stream->Close(nullptr, RowBatch::FlushMode::NO_FLUSH_RESOURCES);
}
spilled_partition_probe_streams_.clear();
}
diff --git a/be/src/exec/partitioned-hash-join-builder.h b/be/src/exec/partitioned-hash-join-builder.h
index bbdc472..7e9fdf7 100644
--- a/be/src/exec/partitioned-hash-join-builder.h
+++ b/be/src/exec/partitioned-hash-join-builder.h
@@ -20,18 +20,19 @@
#include <boost/scoped_ptr.hpp>
#include <memory>
+#include <list>
+#include <vector>
#include "common/object-pool.h"
#include "common/status.h"
#include "exec/data-sink.h"
#include "exec/filter-context.h"
#include "exec/hash-table.h"
+#include "exec/join-op.h"
#include "runtime/buffered-tuple-stream.h"
#include "runtime/bufferpool/buffer-pool.h"
#include "runtime/bufferpool/suballocator.h"
-#include "gen-cpp/PlanNodes_types.h"
-
namespace impala {
class RowDescriptor;
@@ -70,6 +71,23 @@ class ScalarExprEvaluator;
/// The full hash join algorithm is documented in PartitionedHashJoinNode.
class PhjBuilder : public DataSink {
public:
+ /// Number of initial partitions to create. Must be a power of two.
+ static const int PARTITION_FANOUT = 16;
+
+ /// Needs to be log2(PARTITION_FANOUT).
+ static const int NUM_PARTITIONING_BITS = 4;
+
+ /// Maximum number of times we will repartition. The maximum build table we
+ /// can process is:
+ /// MEM_LIMIT * (PARTITION_FANOUT ^ MAX_PARTITION_DEPTH). With a (low) 1GB
+ /// limit and 64 fanout, we can support 256TB build tables in the case where
+ /// there is no skew.
+ /// In the case where there is skew, repartitioning is unlikely to help (assuming a
+ /// reasonable hash function).
+ /// Note that we need to have at least as many SEED_PRIMES in HashTableCtx.
+ /// TODO: we can revisit and try harder to explicitly detect skew.
+ static const int MAX_PARTITION_DEPTH = 16;
+
class Partition;
PhjBuilder(int join_node_id, const std::string& join_node_label, TJoinOp::type join_op,
@@ -105,16 +123,23 @@ class PhjBuilder : public DataSink {
/// writing with a write buffer allocated.
std::vector<std::unique_ptr<BufferedTupleStream>> TransferProbeStreams();
- /// Clears the current list of hash partitions. Called after probing of the partitions
- /// is done. The partitions are not closed or destroyed, since they may be spilled or
- /// may contain unmatched build rows for certain join modes (e.g. right outer join).
- void ClearHashPartitions() { hash_partitions_.clear(); }
+ /// Called after probing of the partitions is done. Appends in-memory partitions that
+ /// may contain build rows to output to 'output_partitions' for build modes like
+ /// right outer join that output unmatched rows. Close other in-memory partitions,
+ /// attaching any tuple data to 'batch' if 'batch' is non-NULL. Closes spilled
+ /// partitions if 'retain_spilled_partition' is false for that partition index.
+ /// Invalid to call hash_partition() after this is called.
+ void DoneProbing(const bool retain_spilled_partition[PARTITION_FANOUT],
+ std::list<Partition*>* output_partitions, RowBatch* batch);
/// Close the null aware partition (if there is one) and set it to NULL.
- void CloseNullAwarePartition(RowBatch* out_batch) {
- if (null_aware_partition_ != NULL) {
- null_aware_partition_->Close(out_batch);
- null_aware_partition_ = NULL;
+ void CloseNullAwarePartition() {
+ if (null_aware_partition_ != nullptr) {
+ // We don't need to pass in a batch because the anti-join only returns tuple data
+ // from the probe side - i.e. the RowDescriptor for PartitionedHashJoinNode does
+ // not include the build tuple.
+ null_aware_partition_->Close(nullptr);
+ null_aware_partition_ = nullptr;
}
}
@@ -150,23 +175,6 @@ class PhjBuilder : public DataSink {
std::string DebugString() const;
- /// Number of initial partitions to create. Must be a power of two.
- static const int PARTITION_FANOUT = 16;
-
- /// Needs to be log2(PARTITION_FANOUT).
- static const int NUM_PARTITIONING_BITS = 4;
-
- /// Maximum number of times we will repartition. The maximum build table we
- /// can process is:
- /// MEM_LIMIT * (PARTITION_FANOUT ^ MAX_PARTITION_DEPTH). With a (low) 1GB
- /// limit and 64 fanout, we can support 256TB build tables in the case where
- /// there is no skew.
- /// In the case where there is skew, repartitioning is unlikely to help (assuming a
- /// reasonable hash function).
- /// Note that we need to have at least as many SEED_PRIMES in HashTableCtx.
- /// TODO: we can revisit and try harder to explicitly detect skew.
- static const int MAX_PARTITION_DEPTH = 16;
-
/// A partition containing a subset of build rows.
///
/// A partition may contain two data structures: the build rows and optionally a hash
@@ -474,7 +482,8 @@ class PhjBuilder : public DataSink {
/// store all the rows for which 'build_expr_evals_' evaluated over the row returns
/// NULL (i.e. it has a NULL on the eq join slot).
/// NULL if the join is not null aware or we are done processing this partition.
- /// This partitions starts off in memory but can be spilled.
+ /// Always NULL once we are done processing the level 0 partitions.
+ /// This partition starts off in memory but can be spilled.
Partition* null_aware_partition_;
/// Populated during the hash table building phase if any partitions spilled.
diff --git a/be/src/exec/partitioned-hash-join-node.cc b/be/src/exec/partitioned-hash-join-node.cc
index 42385d0..fd9703f 100644
--- a/be/src/exec/partitioned-hash-join-node.cc
+++ b/be/src/exec/partitioned-hash-join-node.cc
@@ -208,7 +208,7 @@ Status PartitionedHashJoinNode::Reset(RuntimeState* state, RowBatch* row_batch)
state_ = PARTITIONING_BUILD;
ht_ctx_->set_level(0);
CloseAndDeletePartitions(row_batch);
- builder_->Reset(row_batch);
+ builder_->Reset(IsLeftSemiJoin(join_op_) ? nullptr : row_batch);
memset(hash_tbls_, 0, sizeof(HashTable*) * PARTITION_FANOUT);
if (output_unmatched_batch_ != nullptr) {
output_unmatched_batch_->TransferResourceOwnership(row_batch);
@@ -336,7 +336,8 @@ Status PartitionedHashJoinNode::NextSpilledProbeRowBatch(
ResetForProbe();
} else {
// Finished processing spilled probe rows from this partition.
- if (state_ == PROBING_SPILLED_PARTITION && NeedToProcessUnmatchedBuildRows()) {
+ if (state_ == PROBING_SPILLED_PARTITION
+ && NeedToProcessUnmatchedBuildRows(join_op_)) {
// If the build partition was in memory, we are done probing this partition.
// In case of right-outer, right-anti and full-outer joins, we move this partition
// to the list of partitions that we need to output their unmatched build rows.
@@ -365,6 +366,8 @@ Status PartitionedHashJoinNode::NextSpilledProbeRowBatch(
return Status::OK();
}
+// TODO: refactor this method to better separate the logic operating on the builder
+// vs probe data structures.
Status PartitionedHashJoinNode::PrepareSpilledPartitionForProbe(
RuntimeState* state, bool* got_partition) {
VLOG(2) << "PrepareSpilledPartitionForProbe\n" << NodeDebugString();
@@ -376,6 +379,7 @@ Status PartitionedHashJoinNode::PrepareSpilledPartitionForProbe(
return Status::OK();
}
+ // TODO: the builder should choose the spilled partition to process.
input_partition_ = std::move(spilled_partitions_.front());
spilled_partitions_.pop_front();
PhjBuilder::Partition* build_partition = input_partition_->build_partition();
@@ -383,8 +387,8 @@ Status PartitionedHashJoinNode::PrepareSpilledPartitionForProbe(
if (input_partition_->probe_rows()->num_rows() == 0) {
// If there are no probe rows, there's no need to build the hash table, and
// only partitions with NeedToProcessUnmatcheBuildRows() will have been added
- // to 'spilled_partitions_' in CleanUpHashPartitions().
- DCHECK(NeedToProcessUnmatchedBuildRows());
+ // to 'spilled_partitions_' in DoneProbing().
+ DCHECK(NeedToProcessUnmatchedBuildRows(join_op_));
bool got_read_buffer = false;
RETURN_IF_ERROR(input_partition_->build_partition()->build_rows()->PrepareForRead(
true, &got_read_buffer));
@@ -400,6 +404,8 @@ Status PartitionedHashJoinNode::PrepareSpilledPartitionForProbe(
}
// Make sure we have a buffer to read the probe rows before we build the hash table.
+ // TODO: we should set aside the reservation without allocating the buffer, then
+ // move the repartitioning logic into the builder.
RETURN_IF_ERROR(input_partition_->PrepareForRead());
ht_ctx_->set_level(build_partition->level());
@@ -515,7 +521,7 @@ Status PartitionedHashJoinNode::GetNext(
RETURN_IF_ERROR(QueryMaintenance(state));
if (!output_build_partitions_.empty()) {
- DCHECK(NeedToProcessUnmatchedBuildRows());
+ DCHECK(NeedToProcessUnmatchedBuildRows(join_op_));
// Flush the remaining unmatched build rows of any partitions we are done
// processing before moving onto the next partition.
@@ -610,7 +616,7 @@ Status PartitionedHashJoinNode::GetNext(
// Finished up all probe rows for 'hash_partitions_'. We may have already cleaned up
// the hash partitions, e.g. if we had to output some unmatched build rows below.
if (builder_->num_hash_partitions() != 0) {
- RETURN_IF_ERROR(CleanUpHashPartitions(state, out_batch));
+ RETURN_IF_ERROR(DoneProbing(state, out_batch));
if (out_batch->AtCapacity()) break;
}
@@ -654,7 +660,7 @@ Status PartitionedHashJoinNode::GetNext(
Status PartitionedHashJoinNode::OutputUnmatchedBuild(RowBatch* out_batch) {
SCOPED_TIMER(probe_timer_);
- DCHECK(NeedToProcessUnmatchedBuildRows());
+ DCHECK(NeedToProcessUnmatchedBuildRows(join_op_));
DCHECK(!output_build_partitions_.empty());
if (output_unmatched_batch_iter_.get() != NULL) {
@@ -795,7 +801,7 @@ Status PartitionedHashJoinNode::OutputNullAwareNullProbe(RuntimeState* state,
RETURN_IF_ERROR(null_probe_rows_->GetNext(probe_batch_.get(), &eos));
if (probe_batch_->num_rows() == 0 && eos) {
// All done.
- builder_->CloseNullAwarePartition(out_batch);
+ builder_->CloseNullAwarePartition();
null_aware_probe_partition_->Close(out_batch);
null_aware_probe_partition_.reset();
// Flush out the resources to free up memory.
@@ -1094,8 +1100,7 @@ Status PartitionedHashJoinNode::EvaluateNullProbe(
return Status::OK();
}
-Status PartitionedHashJoinNode::CleanUpHashPartitions(
- RuntimeState* state, RowBatch* batch) {
+Status PartitionedHashJoinNode::DoneProbing(RuntimeState* state, RowBatch* batch) {
DCHECK_EQ(probe_batch_pos_, -1);
// At this point all the rows have been read from the probe side for all partitions in
// hash_partitions_.
@@ -1108,62 +1113,48 @@ Status PartitionedHashJoinNode::CleanUpHashPartitions(
// rows.
DCHECK_EQ(builder_->num_hash_partitions(), PARTITION_FANOUT);
DCHECK_EQ(probe_hash_partitions_.size(), PARTITION_FANOUT);
+ // The build partitions we need to retain for further processing.
+ bool retain_spilled_partition[PARTITION_FANOUT] = {false};
for (int i = 0; i < PARTITION_FANOUT; ++i) {
ProbePartition* probe_partition = probe_hash_partitions_[i].get();
- PhjBuilder::Partition* build_partition = builder_->hash_partition(i);
- if (build_partition->IsClosed()) {
- DCHECK(probe_partition == NULL);
- continue;
- }
- if (build_partition->is_spilled()) {
- DCHECK(probe_partition != NULL);
- DCHECK(build_partition->hash_tbl() == NULL) << NodeDebugString();
+ if (probe_partition == nullptr) {
+ // Partition was not spilled.
+ if (join_op_ == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN) {
+ // For NAAJ, we need to try to match the NULL probe rows with this build partition
+ // before we are done with it.
+ PhjBuilder::Partition* build_partition = builder_->hash_partition(i);
+ if (!build_partition->IsClosed()) {
+ RETURN_IF_ERROR(EvaluateNullProbe(state, build_partition->build_rows()));
+ }
+ }
+ } else if (probe_partition->probe_rows()->num_rows() != 0 ||
+ NeedToProcessUnmatchedBuildRows(join_op_)) {
+ retain_spilled_partition[i] = true;
// Unpin the probe stream to free up more memory. We need to free all memory so we
// can recurse the algorithm and create new hash partitions from spilled partitions.
- // TODO: we shouldn't need to unpin the build stream if we stop spilling
- // while probing.
- RETURN_IF_ERROR(
- build_partition->build_rows()->UnpinStream(BufferedTupleStream::UNPIN_ALL));
- DCHECK_EQ(build_partition->build_rows()->BytesPinned(false), 0);
RETURN_IF_ERROR(
probe_partition->probe_rows()->UnpinStream(BufferedTupleStream::UNPIN_ALL));
-
- if (probe_partition->probe_rows()->num_rows() != 0
- || NeedToProcessUnmatchedBuildRows()) {
- // Push newly created partitions at the front. This means a depth first walk
- // (more finely partitioned partitions are processed first). This allows us
- // to delete blocks earlier and bottom out the recursion earlier.
- spilled_partitions_.push_front(std::move(probe_hash_partitions_[i]));
- } else {
- // There's no more processing to do for this partition, and since there were no
- // probe rows we didn't return any rows that reference memory from these
- // partitions, so just free the resources.
- build_partition->Close(NULL);
- probe_partition->Close(NULL);
- COUNTER_ADD(num_hash_table_builds_skipped_, 1);
- }
+ // Push newly created partitions at the front. This means a depth first walk
+ // (more finely partitioned partitions are processed first). This allows us
+ // to delete blocks earlier and bottom out the recursion earlier.
+ spilled_partitions_.push_front(std::move(probe_hash_partitions_[i]));
} else {
- DCHECK(probe_partition == NULL);
- if (NeedToProcessUnmatchedBuildRows()) {
- DCHECK(output_unmatched_batch_iter_.get() == NULL);
- if (output_build_partitions_.empty()) {
- hash_tbl_iterator_ = build_partition->hash_tbl()->FirstUnmatched(ht_ctx_.get());
- }
- output_build_partitions_.push_back(build_partition);
- } else if (join_op_ == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN) {
- // For NAAJ, we need to try to match all the NULL probe rows with this partition
- // before closing it. The NULL probe rows could have come from any partition
- // so we collect them all and match them at the end.
- RETURN_IF_ERROR(EvaluateNullProbe(state, build_partition->build_rows()));
- build_partition->Close(batch);
- } else {
- build_partition->Close(batch);
- }
+ // There's no more processing to do for this partition, and since there were no
+ // probe rows we didn't return any rows that reference memory from these
+ // partitions, so just free the resources.
+ probe_partition->Close(nullptr);
+ COUNTER_ADD(num_hash_table_builds_skipped_, 1);
}
}
-
- builder_->ClearHashPartitions();
probe_hash_partitions_.clear();
+
+ builder_->DoneProbing(retain_spilled_partition, &output_build_partitions_,
+ IsLeftSemiJoin(join_op_) ? nullptr : batch);
+ if (!output_build_partitions_.empty()) {
+ DCHECK(output_unmatched_batch_iter_.get() == nullptr);
+ hash_tbl_iterator_ =
+ output_build_partitions_.front()->hash_tbl()->FirstUnmatched(ht_ctx_.get());
+ }
return Status::OK();
}
diff --git a/be/src/exec/partitioned-hash-join-node.h b/be/src/exec/partitioned-hash-join-node.h
index 8ad4d4a..b771e32 100644
--- a/be/src/exec/partitioned-hash-join-node.h
+++ b/be/src/exec/partitioned-hash-join-node.h
@@ -355,7 +355,7 @@ class PartitionedHashJoinNode : public BlockingJoinNode {
/// unmatched rows.
/// - If the build partition did not have a hash table, meaning both build and probe
/// rows were spilled, move the partition to 'spilled_partitions_'.
- Status CleanUpHashPartitions(RuntimeState* state, RowBatch* batch) WARN_UNUSED_RESULT;
+ Status DoneProbing(RuntimeState* state, RowBatch* batch) WARN_UNUSED_RESULT;
/// Get the next row batch from the probe (left) side (child(0)). If we are done
/// consuming the input, sets 'probe_batch_pos_' to -1, otherwise, sets it to 0.
@@ -467,7 +467,7 @@ class PartitionedHashJoinNode : public BlockingJoinNode {
/// The list of probe partitions that have been spilled and still need more
/// processing. These partitions could need repartitioning, in which case more
/// partitions will be added to this list after repartitioning.
- /// This list is populated at CleanUpHashPartitions().
+ /// This list is populated at DoneProbing().
std::list<std::unique_ptr<ProbePartition>> spilled_partitions_;
/// The current spilled probe partition being processed as input to repartitioning,
@@ -476,7 +476,7 @@ class PartitionedHashJoinNode : public BlockingJoinNode {
/// In the case of right-outer and full-outer joins, this is the list of the partitions
/// for which we need to output their unmatched build rows.
- /// This list is populated at CleanUpHashPartitions().
+ /// This list is populated at DoneProbing().
std::list<PhjBuilder::Partition*> output_build_partitions_;
/// Whether this join is in a state outputting rows from OutputNullAwareProbeRows().