8000 check tuple visibility · postgrespro/pgsphere@16e45b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16e45b5

Browse files
committed
check tuple visibility
1 parent 03713a3 commit 16e45b5

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

init.c

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ static CustomExecMethods crossmatch_exec_methods;
9191
IsA(lsecond(((FuncExpr *) (arg))->args), Var) \
9292
)
9393

94+
#define HeapFetchVisibleTuple(rel, htup, buf) \
95+
( \
96+
heap_fetch((rel), SnapshotSelf, (htup), &(buf), false, NULL) && \
97+
HeapTupleSatisfiesVisibility((htup), SnapshotSelf, (buf)) \
98+
)
9499

95100
static inline int64
96101
get_index_size(Oid idx)
@@ -549,8 +554,8 @@ fetch_next_pair(CrossmatchScanState *scan_state)
549554
ItemPointerData p_tids[2] = { 0 };
550555
HeapTupleData htup_outer;
551556
HeapTupleData htup_inner;
552-
Buffer buf1;
553-
Buffer buf2;
557+
Buffer buf1 = InvalidBuffer;
558+
Buffer buf2 = InvalidBuffer;
554559

555560
crossmatch(scan_state->ctx, p_tids);
556561

@@ -559,51 +564,35 @@ fetch_next_pair(CrossmatchScanState *scan_state)
559564
return FetchTidPairFinished;
560565
}
561566

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+
562576
/* We don't have to fetch tuples if scan tlist is empty */
563577
if (scan_state->scan_tlist != NIL)
564578
{
565-
bool htup_outer_ready = false;
566-
bool htup_inner_ready = false;
567579
int col_index = 0;
568580
ListCell *l;
569581

570-
htup_outer.t_self = p_tids[0];
571-
htup_inner.t_self = p_tids[1];
572-
573582
foreach(l, scan_state->scan_tlist)
574583
{
575584
TargetEntry *target = (TargetEntry *) lfirst(l);
576585
Var *var = (Var *) target->expr;
577586

578587
if (var->varno == scan_state->outer_relid)
579588
{
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-
590589
values[col_index] = heap_getattr(&htup_outer, var->varattno,
591590
scan_state->outer->rd_att,
592591
&nulls[col_index]);
593592
}
594593

595594
if (var->varno == scan_state->inner_relid)
596595
{
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-
607596
values[col_index] = heap_getattr(&htup_inner, var->varattno,
608597
scan_state->outer->rd_att,
609598
&nulls[col_index]);
@@ -612,17 +601,17 @@ fetch_next_pair(CrossmatchScanState *scan_state)
612601
col_index++;
613602
}
614603

615-
if (htup_outer_ready)
616-
ReleaseBuffer(buf1);
617-
if (htup_inner_ready)
618-
ReleaseBuffer(buf2);
619-
620604
htup = heap_form_tuple(tupdesc, values, nulls);
621605

622606
/* Fill scanSlot with a new tuple */
623607
ExecStoreTuple(htup, slot, InvalidBuffer, false);
624608
}
625609

610+
if (buf1 != InvalidBuffer)
611+
ReleaseBuffer(buf1);
612+
if (buf2 != InvalidBuffer)
613+
ReleaseBuffer(buf2);
614+
626615
return FetchTidPairReady;
627616
}
628617

0 commit comments

Comments
 (0)
0