Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 56187be

Browse files
committed
minor refactoring for fetch_next_pair()
1 parent de99e0c commit 56187be

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

init.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ extern void _PG_init(void);
2828

2929
static set_join_pathlist_hook_type set_join_pathlist_next;
3030

31+
typedef enum
32+
{
33+
FetchTidPairFinished = 0,
34+
FetchTidPairInvalid,
35+
FetchTidPairReady
36+
} FetchTidPairState;
37+
3138
typedef struct
3239
{
3340
CustomPath cpath;
@@ -528,7 +535,7 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags)
528535
}
529536
}
530537

531-
static bool
538+
static FetchTidPairState
532539
fetch_next_pair(CrossmatchScanState *scan_state)
533540
{
534541
ScanState *ss = &scan_state->css.ss;
@@ -549,7 +556,7 @@ fetch_next_pair(CrossmatchScanState *scan_state)
549556

550557
if (!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)
573580
if (!htup_outer_ready)
574581
{
575582
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+
}
579588
}
580589

581590
values[col_index] = heap_getattr(&htup_outer, var->varattno,
@@ -588,8 +597,11 @@ fetch_next_pair(CrossmatchScanState *scan_state)
588597
if (!htup_inner_ready)
589598
{
590599
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+
}
593605
}
594606

595607
values[col_index] = heap_getattr(&htup_inner, var->varattno,
@@ -611,7 +623,7 @@ fetch_next_pair(CrossmatchScanState *scan_state)
611623
ExecStoreTuple(htup, slot, InvalidBuffer, false);
612624
}
613625

614-
return true;
626+
return FetchTidPairReady;
615627
}
616628

617629
static TupleTableSlot *
@@ -620,12 +632,19 @@ crossmatch_exec(CustomScanState *node)
620632
CrossmatchScanState *scan_state = (CrossmatchScanState *) node;
621633
TupleTableSlot *scanSlot = node->ss.ss_ScanTupleSlot;
622634

623-
for(;;)
635+
for (;;)
624636
{
625637
if (!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)
629648
return NULL;
630649
}
631650

0 commit comments

Comments
 (0)