@@ -91,6 +91,11 @@ static CustomExecMethods crossmatch_exec_methods;
91
91
IsA(lsecond(((FuncExpr *) (arg))->args), Var) \
92
92
)
93
93
94
+ #define HeapFetchVisibleTuple (rel , htup , buf ) \
95
+ ( \
96
+ heap_fetch((rel), SnapshotSelf, (htup), &(buf), false, NULL) && \
97
+ HeapTupleSatisfiesVisibility((htup), SnapshotSelf, (buf)) \
98
+ )
94
99
95
100
static inline int64
96
101
get_index_size (Oid idx )
@@ -549,8 +554,8 @@ fetch_next_pair(CrossmatchScanState *scan_state)
549
554
ItemPointerData p_tids [2 ] = { 0 };
550
555
HeapTupleData htup_outer ;
551
556
HeapTupleData htup_inner ;
552
- Buffer buf1 ;
553
- Buffer buf2 ;
557
+ Buffer buf1 = InvalidBuffer ;
558
+ Buffer buf2 = InvalidBuffer ;
554
559
555
560
crossmatch (scan_state -> ctx , p_tids );
556
561
@@ -559,51 +564,35 @@ fetch_next_pair(CrossmatchScanState *scan_state)
559
564
return FetchTidPairFinished ;
560
565
}
561
566
567
+ htup_outer .t_self = p_tids [0 ];
568
+ htup_inner .t_self = p_tids [1 ];
569
+
570
+ if (!HeapFetchVisibleTuple (scan_state -> outer , & htup_outer , buf1 ) ||
571
+ !HeapFetchVisibleTuple (scan_state -> inner , & htup_inner , buf2 ))
572
+ {
573
+ return FetchTidPairInvalid ;
574
+ }
575
+
562
576
/* We don't have to fetch tuples if scan tlist is empty */
563
577
if (scan_state -> scan_tlist != NIL )
564
578
{
565
- bool htup_outer_ready = false;
566
- bool htup_inner_ready = false;
567
579
int col_index = 0 ;
568
580
ListCell * l ;
569
581
570
- htup_outer .t_self = p_tids [0 ];
571
- htup_inner .t_self = p_tids [1 ];
572
-
573
582
foreach (l , scan_state -> scan_tlist )
574
583
{
575
584
TargetEntry * target = (TargetEntry * ) lfirst (l );
576
585
Var * var = (Var * ) target -> expr ;
577
586
578
587
if (var -> varno == scan_state -> outer_relid )
579
588
{
580
- if (!htup_outer_ready )
581
- {
582
- htup_outer_ready = true;
583
- if (!heap_fetch (scan_state -> outer , SnapshotSelf ,
584
- & htup_outer , & buf1 , false, NULL ))
585
- {
586
- return FetchTidPairInvalid ;
587
- }
588
- }
589
-
590
589
values [col_index ] = heap_getattr (& htup_outer , var -> varattno ,
591
590
scan_state -> outer -> rd_att ,
592
591
& nulls [col_index ]);
593
592
}
594
593
595
594
if (var -> varno == scan_state -> inner_relid )
596
595
{
597
- if (!htup_inner_ready )
598
- {
599
- htup_inner_ready = true;
600
- if (!heap_fetch (scan_state -> inner , SnapshotSelf ,
601
- & htup_inner , & buf2 , false, NULL ))
602
- {
603
- return FetchTidPairInvalid ;
604
- }
605
- }
606
-
607
596
values [col_index ] = heap_getattr (& htup_inner , var -> varattno ,
608
597
scan_state -> outer -> rd_att ,
609
598
& nulls [col_index ]);
@@ -612,17 +601,17 @@ fetch_next_pair(CrossmatchScanState *scan_state)
612
601
col_index ++ ;
613
602
}
614
603
615
- if (htup_outer_ready )
616
- ReleaseBuffer (buf1 );
617
- if (htup_inner_ready )
618
- ReleaseBuffer (buf2 );
619
-
620
604
htup = heap_form_tuple (tupdesc , values , nulls );
621
605
622
606
/* Fill scanSlot with a new tuple */
623
607
ExecStoreTuple (htup , slot , InvalidBuffer , false);
624
608
}
625
609
610
+ if (buf1 != InvalidBuffer )
611
+ ReleaseBuffer (buf1 );
612
+ if (buf2 != InvalidBuffer )
613
+ ReleaseBuffer (buf2 );
614
+
626
615
return FetchTidPairReady ;
627
616
}
628
617
0 commit comments