@@ -1381,43 +1381,43 @@ pub(crate) fn build_batch_from_indices(
13811381/// For correlated scalar `NOT IN`, `null_indices_bitmap` carries the same UNKNOWN
13821382/// decision per build row, scoped by the correlated equality keys.
13831383///
1384+ /// When present, `build_key_nulls` is aligned with the output rows in
1385+ /// `build_indices`, rather than indexed by the original build row number.
1386+ ///
13841387/// This is the helper equivalent of the paper's "null bucket" and `hadNull` handling.
13851388/// It is intentionally scoped to scalar null-aware mark joins.
13861389pub ( crate ) fn build_null_aware_left_mark_column (
13871390 build_indices : & UInt64Array ,
13881391 probe_indices : & UInt32Array ,
1389- build_key_column : & dyn Array ,
1392+ build_key_nulls : Option < & NullBuffer > ,
13901393 null_indices_bitmap : Option < & BooleanBufferBuilder > ,
13911394 probe_side_has_null : bool ,
13921395 probe_side_non_empty : bool ,
13931396) -> ArrayRef {
1394- let build_key_nulls = build_key_column. logical_nulls ( ) ;
1395-
13961397 // Whether an unmatched build row's mark is NULL (UNKNOWN) instead of FALSE:
13971398 // correlated joins precomputed this per row in `null_indices_bitmap`; the
13981399 // uncorrelated rules are cases 1-4 in the doc above.
1399- let unmatched_mark_is_null = |build_idx : usize | match null_indices_bitmap {
1400- Some ( bitmap) => bitmap. get_bit ( build_idx) ,
1401- None if build_key_nulls
1402- . as_ref ( )
1403- . is_some_and ( |nulls| nulls. is_null ( build_idx) ) =>
1404- {
1405- probe_side_non_empty
1406- }
1407- None => probe_side_has_null,
1408- } ;
1400+ let unmatched_mark_is_null =
1401+ |build_idx : usize , output_idx : usize | match null_indices_bitmap {
1402+ Some ( bitmap) => bitmap. get_bit ( build_idx) ,
1403+ None if build_key_nulls. is_some_and ( |nulls| nulls. is_null ( output_idx) ) => {
1404+ probe_side_non_empty
1405+ }
1406+ None => probe_side_has_null,
1407+ } ;
14091408
14101409 let marks: BooleanArray = build_indices
14111410 . iter ( )
14121411 . zip ( probe_indices. iter ( ) )
1413- . map ( |( build_idx, probe_idx) | {
1412+ . enumerate ( )
1413+ . map ( |( output_idx, ( build_idx, probe_idx) ) | {
14141414 if probe_idx. is_some ( ) {
14151415 return Some ( true ) ;
14161416 }
14171417 let build_idx = build_idx
14181418 . expect ( "LeftMark final indices should always contain build-side rows" )
14191419 as usize ;
1420- if unmatched_mark_is_null ( build_idx) {
1420+ if unmatched_mark_is_null ( build_idx, output_idx ) {
14211421 None
14221422 } else {
14231423 Some ( false )
0 commit comments