@@ -28,6 +28,13 @@ extern void _PG_init(void);
28
28
29
29
static set_join_pathlist_hook_type set_join_pathlist_next ;
30
30
31
+ typedef enum
32
+ {
33
+ FetchTidPairFinished = 0 ,
34
+ FetchTidPairInvalid ,
35
+ FetchTidPairReady
36
+ }FetchTidPairState ;
37
+
31
38
typedef struct
32
39
{
33
40
CustomPath cpath ;
@@ -528,7 +535,7 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags)
528
535
}
529
536
}
530
537
531
- static bool
538
+ static FetchTidPairState
532
539
fetch_next_pair (CrossmatchScanState * scan_state )
533
540
{
534
541
ScanState * ss = & scan_state -> css .ss ;
@@ -549,7 +556,7 @@ fetch_next_pair(CrossmatchScanState *scan_state)
549
556
550
557
if (!ItemPointerIsValid (& p_tids [0 ])|| !ItemPointerIsValid (& p_tids [1 ]))
551
558
{
552
- return false ;
559
+ return FetchTidPairFinished ;
553
560
}
554
561
555
562
/* We don't have to fetch tuples if scan tlist is empty */
@@ -573,9 +580,11 @@ fetch_next_pair(CrossmatchScanState *scan_state)
573
580
if (!htup_outer_ready )
574
581
{
575
582
htup_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
+ }
579
588
}
580
589
581
590
values [col_index ]= heap_getattr (& htup_outer ,var -> varattno ,
@@ -588,8 +597,11 @@ fetch_next_pair(CrossmatchScanState *scan_state)
588
597
if (!htup_inner_ready )
589
598
{
590
599
htup_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
+ }
593
605
}
594
606
595
607
values [col_index ]= heap_getattr (& htup_inner ,var -> varattno ,
@@ -611,7 +623,7 @@ fetch_next_pair(CrossmatchScanState *scan_state)
611
623
ExecStoreTuple (htup ,slot ,InvalidBuffer , false);
612
624
}
613
625
614
- return true ;
626
+ return FetchTidPairReady ;
615
627
}
616
628
617
629
static TupleTableSlot *
@@ -620,12 +632,19 @@ crossmatch_exec(CustomScanState *node)
620
632
CrossmatchScanState * scan_state = (CrossmatchScanState * )node ;
621
633
TupleTableSlot * scanSlot = node -> ss .ss_ScanTupleSlot ;
622
634
623
- for (;;)
635
+ for (;;)
624
636
{
625
637
if (!node -> ss .ps .ps_TupFromTlist )
626
638
{
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 )
629
648
return NULL ;
630
649
}
631
650