@@ -236,9 +236,9 @@ pub trait JoinHashMapType {
236236 ///
237237 /// This method only compares hashes, so additional further check for actual values
238238 /// equality may be required.
239- fn get_matched_indices_with_limit_offset < ' a > (
239+ fn get_matched_indices_with_limit_offset (
240240 & self ,
241- iter : impl Iterator < Item = ( usize , & ' a u64 ) > ,
241+ iter : & [ u64 ] ,
242242 deleted_offset : Option < usize > ,
243243 limit : usize ,
244244 offset : JoinHashMapOffset ,
@@ -251,30 +251,52 @@ pub trait JoinHashMapType {
251251 let mut match_indices = UInt64BufferBuilder :: new ( 0 ) ;
252252
253253 let mut output_tuples = 0_usize ;
254- let mut next_offset = None ;
255254
256255 let hash_map: & RawTable < ( u64 , u64 ) > = self . get_map ( ) ;
257256 let next_chain = self . get_list ( ) ;
258257
259- let ( initial_idx, initial_next_idx) = offset;
260- ' probe: for ( row_idx, hash_value) in iter. skip ( initial_idx) {
261- let index = if initial_next_idx. is_some ( ) && row_idx == initial_idx {
262- // If `initial_next_idx` is zero, then input index has been processed
263- // during previous iteration, and it can be skipped now
264- if let Some ( 0 ) = initial_next_idx {
265- continue ;
258+ let to_skip = match offset {
259+ ( initial_idx, None ) => initial_idx,
260+ ( initial_idx, Some ( 0 ) ) => initial_idx + 1 ,
261+ ( initial_idx, Some ( initial_next_idx) ) => {
262+ let mut i = initial_next_idx - 1 ;
263+ loop {
264+ let match_row_idx = if let Some ( offset) = deleted_offset {
265+ // This arguments means that we prune the next index way before here.
266+ if i < offset as u64 {
267+ // End of the list due to pruning
268+ break ;
269+ }
270+ i - offset as u64
271+ } else {
272+ i
273+ } ;
274+ match_indices. append ( match_row_idx) ;
275+ input_indices. append ( initial_idx as u32 ) ;
276+ output_tuples += 1 ;
277+ // Follow the chain to get the next index value
278+ let next = next_chain[ match_row_idx as usize ] ;
279+
280+ if output_tuples >= limit {
281+ let next_offset = Some ( ( initial_idx, Some ( next) ) ) ;
282+ return ( input_indices, match_indices, next_offset) ;
283+ }
284+ if next == 0 {
285+ // end of list
286+ break ;
287+ }
288+ i = next - 1 ;
266289 }
267- // Otherwise, use `initial_next_idx` as-is
268- initial_next_idx
269- } else if let Some ( ( _, index) ) =
290+
291+ initial_idx + 1
292+ }
293+ } ;
294+
295+ let mut row_idx = to_skip;
296+ for hash_value in & iter[ to_skip..] {
297+ if let Some ( ( _, index) ) =
270298 hash_map. get ( * hash_value, |( hash, _) | * hash_value == * hash)
271299 {
272- Some ( * index)
273- } else {
274- None
275- } ;
276-
277- if let Some ( index) = index {
278300 let mut i = index - 1 ;
279301 loop {
280302 let match_row_idx = if let Some ( offset) = deleted_offset {
@@ -294,8 +316,8 @@ pub trait JoinHashMapType {
294316 let next = next_chain[ match_row_idx as usize ] ;
295317
296318 if output_tuples >= limit {
297- next_offset = Some ( ( row_idx, Some ( next) ) ) ;
298- break ' probe ;
319+ let next_offset = Some ( ( row_idx, Some ( next) ) ) ;
320+ return ( input_indices , match_indices , next_offset ) ;
299321 }
300322 if next == 0 {
301323 // end of list
@@ -304,9 +326,10 @@ pub trait JoinHashMapType {
304326 i = next - 1 ;
305327 }
306328 }
329+ row_idx += 1 ;
307330 }
308331
309- ( input_indices, match_indices, next_offset )
332+ ( input_indices, match_indices, None )
310333 }
311334}
312335
0 commit comments