Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9089a98

Browse files
author
Commitfest Bot
committed
[PATCH]: ./v1-heapam_handler_set_tuple_block_once.patch
1 parent 2c0ed86 commit 9089a98

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/backend/access/heap/heapam_handler.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,21 +1031,26 @@ heapam_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin,
10311031
TupleTableSlot *slot)
10321032
{
10331033
HeapScanDesc hscan = (HeapScanDesc) scan;
1034+
HeapTuple targtuple;
10341035
Page targpage;
10351036
OffsetNumber maxoffset;
10361037
BufferHeapTupleTableSlot *hslot;
10371038

10381039
Assert(TTS_IS_BUFFERTUPLE(slot));
10391040

10401041
hslot = (BufferHeapTupleTableSlot *) slot;
1042+
targtuple = &hslot->base.tupdata;
10411043
targpage = BufferGetPage(hscan->rs_cbuf);
10421044
maxoffset = PageGetMaxOffsetNumber(targpage);
10431045

1046+
/* block and tableOid is the same for all tuples, set it once outside the loop */
1047+
ItemPointerSetBlockNumber(&targtuple->t_self, hscan->rs_cblock);
1048+
targtuple->t_tableOid = RelationGetRelid(scan->rs_rd);
1049+
10441050
/* Inner loop over all tuples on the selected page */
10451051
for (; hscan->rs_cindex <= maxoffset; hscan->rs_cindex++)
10461052
{
10471053
ItemId itemid;
1048-
HeapTuple targtuple = &hslot->base.tupdata;
10491054
bool sample_it = false;
10501055

10511056
itemid = PageGetItemId(targpage, hscan->rs_cindex);
@@ -1063,11 +1068,9 @@ heapam_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin,
10631068
continue;
10641069
}
10651070

1066-
ItemPointerSet(&targtuple->t_self, hscan->rs_cblock, hscan->rs_cindex);
1067-
1068-
targtuple->t_tableOid = RelationGetRelid(scan->rs_rd);
10691071
targtuple->t_data = (HeapTupleHeader) PageGetItem(targpage, itemid);
10701072
targtuple->t_len = ItemIdGetLength(itemid);
1073+
ItemPointerSetOffsetNumber(&targtuple->t_self, hscan->rs_cindex);
10711074

10721075
switch (HeapTupleSatisfiesVacuum(targtuple, OldestXmin,
10731076
hscan->rs_cbuf))
@@ -2265,6 +2268,7 @@ heapam_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate,
22652268
TupleTableSlot *slot)
22662269
{
22672270
HeapScanDesc hscan = (HeapScanDesc) scan;
2271+
HeapTuple tuple = &(hscan->rs_ctup);
22682272
TsmRoutine *tsm = scanstate->tsmroutine;
22692273
BlockNumber blockno = hscan->rs_cblock;
22702274
bool pagemode = (scan->rs_flags & SO_ALLOW_PAGEMODE) != 0;
@@ -2285,6 +2289,9 @@ heapam_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate,
22852289
!scan->rs_snapshot->takenDuringRecovery;
22862290
maxoffset = PageGetMaxOffsetNumber(page);
22872291

2292+
/* block is the same for all tuples, set it once outside the loop */
2293+
ItemPointerSetBlockNumber(&tuple->t_self, blockno);
2294+
22882295
for (;;)
22892296
{
22902297
OffsetNumber tupoffset;
@@ -2300,7 +2307,6 @@ heapam_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate,
23002307
{
23012308
ItemId itemid;
23022309
bool visible;
2303-
HeapTuple tuple = &(hscan->rs_ctup);
23042310

23052311
/* Skip invalid tuple pointers. */
23062312
itemid = PageGetItemId(page, tupoffset);
@@ -2309,8 +2315,7 @@ heapam_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate,
23092315

23102316
tuple->t_data = (HeapTupleHeader) PageGetItem(page, itemid);
23112317
tuple->t_len = ItemIdGetLength(itemid);
2312-
ItemPointerSet(&(tuple->t_self), blockno, tupoffset);
2313-
2318+
ItemPointerSetOffsetNumber(&tuple->t_self, blockno);
23142319

23152320
if (all_visible)
23162321
visible = true;
@@ -2536,18 +2541,21 @@ BitmapHeapScanNextBlock(TableScanDesc scan,
25362541
* tbmres; but we have to follow any HOT chain starting at each such
25372542
* offset.
25382543
*/
2544+
ItemPointerData tid;
25392545
int curslot;
25402546

25412547
/* We must have extracted the tuple offsets by now */
25422548
Assert(noffsets > -1);
25432549

2550+
/* block is the same for all tuples, set it once outside the loop */
2551+
ItemPointerSetBlockNumber(&tid, block);
2552+
25442553
for (curslot = 0; curslot < noffsets; curslot++)
25452554
{
25462555
OffsetNumber offnum = offsets[curslot];
2547-
ItemPointerData tid;
25482556
HeapTupleData heapTuple;
25492557

2550-
ItemPointerSet(&tid, block, offnum);
2558+
ItemPointerSetOffsetNumber(&tid, offnum);
25512559
if (heap_hot_search_buffer(&tid, scan->rs_rd, buffer, snapshot,
25522560
&heapTuple, NULL, true))
25532561
hscan->rs_vistuples[ntup++] = ItemPointerGetOffsetNumber(&tid);
@@ -2562,20 +2570,24 @@ BitmapHeapScanNextBlock(TableScanDesc scan,
25622570
Page page = BufferGetPage(buffer);
25632571
OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
25642572
OffsetNumber offnum;
2573+
HeapTupleData loctup;
2574+
2575+
/* block and tableOid is the same for all tuples, set it once outside the loop */
2576+
ItemPointerSetBlockNumber(&loctup.t_self, block);
2577+
loctup.t_tableOid = scan->rs_rd->rd_id;
25652578

25662579
for (offnum = FirstOffsetNumber; offnum <= maxoff; offnum = OffsetNumberNext(offnum))
25672580
{
25682581
ItemId lp;
2569-
HeapTupleData loctup;
25702582
bool valid;
25712583

25722584
lp = PageGetItemId(page, offnum);
25732585
if (!ItemIdIsNormal(lp))
25742586
continue;
25752587
loctup.t_data = (HeapTupleHeader) PageGetItem(page, lp);
25762588
loctup.t_len = ItemIdGetLength(lp);
2577-
loctup.t_tableOid = scan->rs_rd->rd_id;
2578-
ItemPointerSet(&loctup.t_self, block, offnum);
2589+
ItemPointerSetOffsetNumber(&loctup.t_self, offnum);
2590+
25792591
valid = HeapTupleSatisfiesVisibility(&loctup, snapshot, buffer);
25802592
if (valid)
25812593
{

0 commit comments

Comments
 (0)