Skip to content

Commit

Permalink
fix(joins): Strengthen nullptr check for null aware hash joins with f…
Browse files Browse the repository at this point in the history
…ilters (#11620)

Summary:

The mayHaveNulls() method sometimes returns true when there are in fact no nulls. This change will make sure that a nullptr isn't passed to memcpy.

Reviewed By: Yuhta

Differential Revision: D66333546
  • Loading branch information
Daniel Hunte authored and facebook-github-bot committed Dec 9, 2024
1 parent 1b87969 commit ae2fe49
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions velox/exec/HashProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,21 +1220,24 @@ void HashProbe::prepareFilterRowsForNullAwareJoin(
filterInputColumnDecodedVector_.decode(
*filterInput->childAt(projection.outputChannel), filterInputRows_);
if (filterInputColumnDecodedVector_.mayHaveNulls()) {
SelectivityVector nullsInActiveRows(numRows);
memcpy(
nullsInActiveRows.asMutableRange().bits(),
filterInputColumnDecodedVector_.nulls(&filterInputRows_),
bits::nbytes(numRows));
// All rows that are not active count as non-null here.
bits::orWithNegatedBits(
nullsInActiveRows.asMutableRange().bits(),
filterInputRows_.asRange().bits(),
0,
numRows);
// NOTE: the false value of a raw null bit indicates null so we OR
// with negative of the raw bit.
bits::orWithNegatedBits(
rawNullRows, nullsInActiveRows.asRange().bits(), 0, numRows);
if (const uint64_t* nulls =
filterInputColumnDecodedVector_.nulls(&filterInputRows_)) {
SelectivityVector nullsInActiveRows(numRows);
memcpy(
nullsInActiveRows.asMutableRange().bits(),
nulls,
bits::nbytes(numRows));
// All rows that are not active count as non-null here.
bits::orWithNegatedBits(
nullsInActiveRows.asMutableRange().bits(),
filterInputRows_.asRange().bits(),
0,
numRows);
// NOTE: the false value of a raw null bit indicates null so we OR
// with negative of the raw bit.
bits::orWithNegatedBits(
rawNullRows, nullsInActiveRows.asRange().bits(), 0, numRows);
}
}
}
nullFilterInputRows_.updateBounds();
Expand Down

0 comments on commit ae2fe49

Please sign in to comment.