Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions datafusion/physical-plan/src/joins/hash_join/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ impl JoinLeftData {
&self.batch
}

/// Returns `true` if the build side physically contains rows.
///
/// This is distinct from [`Self::has_matchable_build_rows`]: a build side
/// can hold rows while its hash map is empty (see that method).
pub(super) fn has_build_rows(&self) -> bool {
self.batch().num_rows() > 0
}

/// Returns `true` if the build-side hash map has any matchable entries.
///
/// Under [`NullEquality::NullEqualsNothing`] build rows whose join key is
/// NULL are omitted from the map, so this can be `false` even when
/// [`Self::has_build_rows`] is `true`.
pub(super) fn has_matchable_build_rows(&self) -> bool {
!self.map().is_empty()
}

/// returns a reference to the build side expressions values
pub(super) fn values(&self) -> &[ArrayRef] {
&self.values
Expand Down
6 changes: 3 additions & 3 deletions datafusion/physical-plan/src/joins/hash_join/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,12 @@ impl HashJoinStream {
join_type: JoinType,
left_data: &JoinLeftData,
) -> HashJoinStreamState {
let build_empty = left_data.batch().num_rows() == 0;
let build_empty = !left_data.has_build_rows();
// The map can be empty even when the build side has rows: under
// `NullEqualsNothing`, build rows with a NULL join key are omitted. For
// join types whose every output row requires a build match, that still
// guarantees an empty result, so we can skip scanning the probe side.
let map_empty = left_data.map().is_empty();
let map_empty = !left_data.has_matchable_build_rows();

if (build_empty && join_type.empty_build_side_produces_empty_result())
|| (map_empty && join_type.empty_map_produces_empty_result())
Expand Down Expand Up @@ -779,7 +779,7 @@ impl HashJoinStream {
}
}

let is_empty = build_side.left_data.map().is_empty();
let is_empty = !build_side.left_data.has_matchable_build_rows();

if is_empty {
let result = build_batch_empty_build_side(
Expand Down