@@ -28,6 +28,13 @@ extern void _PG_init(void);
2828
2929static set_join_pathlist_hook_type set_join_pathlist_next ;
3030
31+ typedef enum
32+ {
33+ FetchTidPairFinished = 0 ,
34+ FetchTidPairInvalid ,
35+ FetchTidPairReady
36+ }FetchTidPairState ;
37+
3138typedef struct
3239{
3340CustomPath cpath ;
@@ -528,7 +535,7 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags)
528535}
529536}
530537
531- static bool
538+ static FetchTidPairState
532539fetch_next_pair (CrossmatchScanState * scan_state )
533540{
534541ScanState * ss = & scan_state -> css .ss ;
@@ -549,7 +556,7 @@ fetch_next_pair(CrossmatchScanState *scan_state)
549556
550557if (!ItemPointerIsValid (& p_tids [0 ])|| !ItemPointerIsValid (& p_tids [1 ]))
551558{
552- return false ;
559+ return FetchTidPairFinished ;
553560}
554561
555562/* We don't have to fetch tuples if scan tlist is empty */
@@ -573,9 +580,11 @@ fetch_next_pair(CrossmatchScanState *scan_state)
573580if (!htup_outer_ready )
574581{
575582htup_outer_ready = true;
576- /* TODO: check result */
577- heap_fetch (scan_state -> outer ,SnapshotSelf ,
578- & htup_outer ,& buf1 , false,NULL );
583+ if (!heap_fetch (scan_state -> outer ,SnapshotSelf ,
584+ & htup_outer ,& buf1 , false,NULL ))
585+ {
586+ return FetchTidPairInvalid ;
587+ }
579588}
580589
581590values [col_index ]= heap_getattr (& htup_outer ,var -> varattno ,
@@ -588,8 +597,11 @@ fetch_next_pair(CrossmatchScanState *scan_state)
588597if (!htup_inner_ready )
589598{
590599htup_inner_ready = true;
591- heap_fetch (scan_state -> inner ,SnapshotSelf ,
592- & htup_inner ,& buf2 , false,NULL );
600+ if (!heap_fetch (scan_state -> inner ,SnapshotSelf ,
601+ & htup_inner ,& buf2 , false,NULL ))
602+ {
603+ return FetchTidPairInvalid ;
604+ }
593605}
594606
595607values [col_index ]= heap_getattr (& htup_inner ,var -> varattno ,
@@ -611,7 +623,7 @@ fetch_next_pair(CrossmatchScanState *scan_state)
611623ExecStoreTuple (htup ,slot ,InvalidBuffer , false);
612624}
613625
614- return true ;
626+ return FetchTidPairReady ;
615627}
616628
617629static TupleTableSlot *
@@ -620,12 +632,19 @@ crossmatch_exec(CustomScanState *node)
620632CrossmatchScanState * scan_state = (CrossmatchScanState * )node ;
621633TupleTableSlot * scanSlot = node -> ss .ss_ScanTupleSlot ;
622634
623- for (;;)
635+ for (;;)
624636{
625637if (!node -> ss .ps .ps_TupFromTlist )
626638{
627- /* Fetch next tid pair if we're done with the SRF function */
628- if (!fetch_next_pair (scan_state ))
639+ FetchTidPairState fetch_state ;
640+
641+ do
642+ {
643+ fetch_state = fetch_next_pair (scan_state );
644+ }
645+ while (fetch_state == FetchTidPairInvalid );
646+
647+ if (fetch_state == FetchTidPairFinished )
629648return NULL ;
630649}
631650