From be189131cf2d4ace3d8e37e3916402e7f30bfb99 Mon Sep 17 00:00:00 2001 From: Daniel Hunte Date: Mon, 9 Dec 2024 14:10:55 -0800 Subject: [PATCH] fix(joins): Strengthen nullptr check for null aware hash joins with filters (#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 --- velox/exec/HashProbe.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/velox/exec/HashProbe.cpp b/velox/exec/HashProbe.cpp index 2b0111353f89..60ad9d69c329 100644 --- a/velox/exec/HashProbe.cpp +++ b/velox/exec/HashProbe.cpp @@ -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();