Skip to content

Commit 135b781

Browse files
author
Commitfest Bot
committed
[PATCH]: ./v1-heapam_set_tuple_block_once.patch
1 parent 3e055f5 commit 135b781

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/backend/access/heap/heapam.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,22 +504,25 @@ page_collect_tuples(HeapScanDesc scan, Snapshot snapshot,
504504
BlockNumber block, int lines,
505505
bool all_visible, bool check_serializable)
506506
{
507+
HeapTupleData loctup;
507508
int ntup = 0;
508509
OffsetNumber lineoff;
509510

511+
/* block and tableOid is the same for all tuples, set it once outside the loop */
512+
ItemPointerSetBlockNumber(&loctup.t_self, block);
513+
loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd);
514+
510515
for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++)
511516
{
512517
ItemId lpp = PageGetItemId(page, lineoff);
513-
HeapTupleData loctup;
514518
bool valid;
515519

516520
if (!ItemIdIsNormal(lpp))
517521
continue;
518522

519523
loctup.t_data = (HeapTupleHeader) PageGetItem(page, lpp);
520524
loctup.t_len = ItemIdGetLength(lpp);
521-
loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd);
522-
ItemPointerSet(&(loctup.t_self), block, lineoff);
525+
ItemPointerSetOffsetNumber(&loctup.t_self, lineoff);
523526

524527
if (all_visible)
525528
valid = true;
@@ -927,6 +930,10 @@ heapgettup(HeapScanDesc scan,
927930

928931
LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE);
929932
page = heapgettup_start_page(scan, dir, &linesleft, &lineoff);
933+
934+
/* block is the same for all tuples, set it once outside the loop */
935+
ItemPointerSetBlockNumber(&tuple->t_self, scan->rs_cblock);
936+
930937
continue_page:
931938

932939
/*
@@ -946,7 +953,7 @@ heapgettup(HeapScanDesc scan,
946953

947954
tuple->t_data = (HeapTupleHeader) PageGetItem(page, lpp);
948955
tuple->t_len = ItemIdGetLength(lpp);
949-
ItemPointerSet(&(tuple->t_self), scan->rs_cblock, lineoff);
956+
ItemPointerSetOffsetNumber(&tuple->t_self, lineoff);
950957

951958
visible = HeapTupleSatisfiesVisibility(tuple,
952959
scan->rs_base.rs_snapshot,
@@ -1748,6 +1755,10 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
17481755
Assert(TransactionIdIsValid(RecentXmin));
17491756
Assert(BufferGetBlockNumber(buffer) == blkno);
17501757

1758+
/* block and tableOid is the same for all tuples, set it once outside the loop */
1759+
ItemPointerSetBlockNumber(&heapTuple->t_self, blkno);
1760+
heapTuple->t_tableOid = RelationGetRelid(relation);
1761+
17511762
/* Scan through possible multiple members of HOT-chain */
17521763
for (;;)
17531764
{
@@ -1782,8 +1793,7 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
17821793
*/
17831794
heapTuple->t_data = (HeapTupleHeader) PageGetItem(page, lp);
17841795
heapTuple->t_len = ItemIdGetLength(lp);
1785-
heapTuple->t_tableOid = RelationGetRelid(relation);
1786-
ItemPointerSet(&heapTuple->t_self, blkno, offnum);
1796+
ItemPointerSetOffsetNumber(&heapTuple->t_self, offnum);
17871797

17881798
/*
17891799
* Shouldn't see a HEAP_ONLY tuple at chain start.

0 commit comments

Comments
 (0)