@@ -532,24 +532,29 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
532532
533533 hash = BID_HASH_FUNC (ctx -> bid );
534534 slot1 = hash % PtrackContentNblocks ;
535- slot2 = ((hash << 32 ) | (hash >> 32 )) % PtrackContentNblocks ;
536535
537536 update_lsn1 = pg_atomic_read_u64 (& ptrack_map -> entries [slot1 ]);
538- update_lsn2 = pg_atomic_read_u64 (& ptrack_map -> entries [slot2 ]);
539537
540538 if (update_lsn1 != InvalidXLogRecPtr )
541539 elog (DEBUG3 , "ptrack: update_lsn1 %X/%X of blckno %u of file %s" ,
542540 (uint32 ) (update_lsn1 >> 32 ), (uint32 ) update_lsn1 ,
543541 ctx -> bid .blocknum , ctx -> relpath );
544542
545- if (update_lsn2 != InvalidXLogRecPtr )
546- elog (DEBUG3 , "ptrack: update_lsn2 %X/%X of blckno %u of file %s" ,
547- (uint32 ) (update_lsn1 >> 32 ), (uint32 ) update_lsn2 ,
548- ctx -> bid .blocknum , ctx -> relpath );
543+ /* Only probe the second slot if the first one is marked */
544+ if (update_lsn1 >= ctx -> lsn )
545+ {
546+ slot2 = ((hash << 32 ) | (hash >> 32 )) % PtrackContentNblocks ;
547+ update_lsn2 = pg_atomic_read_u64 (& ptrack_map -> entries [slot2 ]);
549548
550- /* Block has been changed since specified LSN. Mark it in the bitmap */
551- if (update_lsn1 >= ctx -> lsn && update_lsn2 >= ctx -> lsn )
552- datapagemap_add (& pagemap , ctx -> bid .blocknum % ((BlockNumber ) RELSEG_SIZE ));
549+ if (update_lsn2 != InvalidXLogRecPtr )
550+ elog (DEBUG3 , "ptrack: update_lsn2 %X/%X of blckno %u of file %s" ,
551+ (uint32 ) (update_lsn1 >> 32 ), (uint32 ) update_lsn2 ,
552+ ctx -> bid .blocknum , ctx -> relpath );
553+
554+ /* Block has been changed since specified LSN. Mark it in the bitmap */
555+ if (update_lsn2 >= ctx -> lsn )
556+ datapagemap_add (& pagemap , ctx -> bid .blocknum % ((BlockNumber ) RELSEG_SIZE ));
557+ }
553558
554559 ctx -> bid .blocknum += 1 ;
555560 }
0 commit comments