v22-0012-Update-variable-names-in-bitmap-scan-descriptors.patch

text/x-patch

Filename: v22-0012-Update-variable-names-in-bitmap-scan-descriptors.patch
Type: text/x-patch
Part: 10
Message: Re: BitmapHeapScan streaming read user and prelim refactoring

Patch

Format: format-patch
Series: patch v22-0012
Subject: Update variable names in bitmap scan descriptors
File+
src/backend/access/heap/heapam.c 32 32
src/backend/access/heap/heapam_handler.c 35 35
src/backend/executor/nodeBitmapHeapscan.c 7 7
src/include/access/heapam.h 11 11
src/include/access/relscan.h 4 4
src/include/access/tableam.h 7 7
From 8fe0e440f6109532de42fb3e11a4f234cae0066f Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Tue, 11 Jun 2024 09:59:23 -0400
Subject: [PATCH v22 12/19] Update variable names in bitmap scan descriptors

The previous commit which added BitmapTableScanDesc and
BitmapHeapScanDesc used the existing member names from TableScanDescData
and HeapScanDescData for diff clarity. This commit renames the members
-- in many cases by removing the rs_ prefix which is not relevant or
needed here.
---
 src/backend/access/heap/heapam.c          | 64 ++++++++++-----------
 src/backend/access/heap/heapam_handler.c  | 70 +++++++++++------------
 src/backend/executor/nodeBitmapHeapscan.c | 14 ++---
 src/include/access/heapam.h               | 22 +++----
 src/include/access/relscan.h              |  8 +--
 src/include/access/tableam.h              | 14 ++---
 6 files changed, 96 insertions(+), 96 deletions(-)

diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 0d8239d2f15..88da737d149 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -1244,27 +1244,27 @@ heap_beginscan_bm(Relation relation, Snapshot snapshot, uint32 flags)
 	RelationIncrementReferenceCount(relation);
 	scan = (BitmapHeapScanDesc *) palloc(sizeof(BitmapHeapScanDesc));
 
-	scan->rs_base.rs_rd = relation;
-	scan->rs_base.rs_snapshot = snapshot;
-	scan->rs_base.rs_flags = flags;
+	scan->base.rel = relation;
+	scan->base.snapshot = snapshot;
+	scan->base.flags = flags;
 
 	Assert(snapshot && IsMVCCSnapshot(snapshot));
 
 	/* we only need to set this up once */
-	scan->rs_ctup.t_tableOid = RelationGetRelid(relation);
+	scan->ctup.t_tableOid = RelationGetRelid(relation);
 
-	scan->rs_nblocks = RelationGetNumberOfBlocks(scan->rs_base.rs_rd);
+	scan->nblocks = RelationGetNumberOfBlocks(scan->base.rel);
 
-	scan->rs_ctup.t_data = NULL;
-	ItemPointerSetInvalid(&scan->rs_ctup.t_self);
-	scan->rs_cbuf = InvalidBuffer;
-	scan->rs_cblock = InvalidBlockNumber;
+	scan->ctup.t_data = NULL;
+	ItemPointerSetInvalid(&scan->ctup.t_self);
+	scan->cbuf = InvalidBuffer;
+	scan->cblock = InvalidBlockNumber;
 
-	scan->rs_cindex = 0;
-	scan->rs_ntuples = 0;
+	scan->vis_idx = 0;
+	scan->vis_ntuples = 0;
 
-	scan->rs_vmbuffer = InvalidBuffer;
-	scan->rs_empty_tuples_pending = 0;
+	scan->vmbuffer = InvalidBuffer;
+	scan->empty_tuples_pending = 0;
 
 	return (BitmapTableScanDesc *) scan;
 }
@@ -1274,31 +1274,31 @@ heap_rescan_bm(BitmapTableScanDesc *sscan)
 {
 	BitmapHeapScanDesc *scan = (BitmapHeapScanDesc *) sscan;
 
-	if (BufferIsValid(scan->rs_cbuf))
+	if (BufferIsValid(scan->cbuf))
 	{
-		ReleaseBuffer(scan->rs_cbuf);
-		scan->rs_cbuf = InvalidBuffer;
+		ReleaseBuffer(scan->cbuf);
+		scan->cbuf = InvalidBuffer;
 	}
 
-	if (BufferIsValid(scan->rs_vmbuffer))
+	if (BufferIsValid(scan->vmbuffer))
 	{
-		ReleaseBuffer(scan->rs_vmbuffer);
-		scan->rs_vmbuffer = InvalidBuffer;
+		ReleaseBuffer(scan->vmbuffer);
+		scan->vmbuffer = InvalidBuffer;
 	}
 
-	scan->rs_cblock = InvalidBlockNumber;
+	scan->cblock = InvalidBlockNumber;
 
 	/*
-	 * Reset rs_empty_tuples_pending, a field only used by bitmap heap scan,
-	 * to avoid incorrectly emitting NULL-filled tuples from a previous scan
-	 * on rescan.
+	 * Reset empty_tuples_pending, a field only used by bitmap heap scan, to
+	 * avoid incorrectly emitting NULL-filled tuples from a previous scan on
+	 * rescan.
 	 */
-	scan->rs_empty_tuples_pending = 0;
+	scan->empty_tuples_pending = 0;
 
-	scan->rs_nblocks = RelationGetNumberOfBlocks(scan->rs_base.rs_rd);
+	scan->nblocks = RelationGetNumberOfBlocks(scan->base.rel);
 
-	scan->rs_ctup.t_data = NULL;
-	ItemPointerSetInvalid(&scan->rs_ctup.t_self);
+	scan->ctup.t_data = NULL;
+	ItemPointerSetInvalid(&scan->ctup.t_self);
 }
 
 void
@@ -1306,16 +1306,16 @@ heap_endscan_bm(BitmapTableScanDesc *sscan)
 {
 	BitmapHeapScanDesc *scan = (BitmapHeapScanDesc *) sscan;
 
-	if (BufferIsValid(scan->rs_cbuf))
-		ReleaseBuffer(scan->rs_cbuf);
+	if (BufferIsValid(scan->cbuf))
+		ReleaseBuffer(scan->cbuf);
 
-	if (BufferIsValid(scan->rs_vmbuffer))
-		ReleaseBuffer(scan->rs_vmbuffer);
+	if (BufferIsValid(scan->vmbuffer))
+		ReleaseBuffer(scan->vmbuffer);
 
 	/*
 	 * decrement relation reference count and free scan descriptor storage
 	 */
-	RelationDecrementReferenceCount(scan->rs_base.rs_rd);
+	RelationDecrementReferenceCount(scan->base.rel);
 
 	pfree(scan);
 }
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 82f216952b1..4057d0cf22b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2130,8 +2130,8 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 	int			ntup;
 	TBMIterateResult *tbmres;
 
-	hscan->rs_cindex = 0;
-	hscan->rs_ntuples = 0;
+	hscan->vis_idx = 0;
+	hscan->vis_ntuples = 0;
 
 	*blockno = InvalidBlockNumber;
 	*recheck = true;
@@ -2140,7 +2140,7 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 	{
 		CHECK_FOR_INTERRUPTS();
 
-		tbmres = tbm_iterate(&scan->tbmiterator);
+		tbmres = tbm_iterate(&scan->iterator);
 
 		if (tbmres == NULL)
 			return false;
@@ -2153,7 +2153,7 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 		 * isolation though, as we need to examine all invisible tuples
 		 * reachable by the index.
 		 */
-	} while (!IsolationIsSerializable() && tbmres->blockno >= hscan->rs_nblocks);
+	} while (!IsolationIsSerializable() && tbmres->blockno >= hscan->nblocks);
 
 	/* Got a valid block */
 	*blockno = tbmres->blockno;
@@ -2164,15 +2164,15 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 	 * heap, the bitmap entries don't need rechecking, and all tuples on the
 	 * page are visible to our transaction.
 	 */
-	if (!(scan->rs_flags & SO_NEED_TUPLES) &&
+	if (!(scan->flags & SO_NEED_TUPLES) &&
 		!tbmres->recheck &&
-		VM_ALL_VISIBLE(scan->rs_rd, tbmres->blockno, &hscan->rs_vmbuffer))
+		VM_ALL_VISIBLE(scan->rel, tbmres->blockno, &hscan->vmbuffer))
 	{
 		/* can't be lossy in the skip_fetch case */
 		Assert(tbmres->ntuples >= 0);
-		Assert(hscan->rs_empty_tuples_pending >= 0);
+		Assert(hscan->empty_tuples_pending >= 0);
 
-		hscan->rs_empty_tuples_pending += tbmres->ntuples;
+		hscan->empty_tuples_pending += tbmres->ntuples;
 
 		return true;
 	}
@@ -2182,19 +2182,19 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 	/*
 	 * Acquire pin on the target heap page, trading in any pin we held before.
 	 */
-	hscan->rs_cbuf = ReleaseAndReadBuffer(hscan->rs_cbuf,
-										  scan->rs_rd,
-										  block);
-	hscan->rs_cblock = block;
-	buffer = hscan->rs_cbuf;
-	snapshot = scan->rs_snapshot;
+	hscan->cbuf = ReleaseAndReadBuffer(hscan->cbuf,
+									   scan->rel,
+									   block);
+	hscan->cblock = block;
+	buffer = hscan->cbuf;
+	snapshot = scan->snapshot;
 
 	ntup = 0;
 
 	/*
 	 * Prune and repair fragmentation for the whole page, if possible.
 	 */
-	heap_page_prune_opt(scan->rs_rd, buffer);
+	heap_page_prune_opt(scan->rel, buffer);
 
 	/*
 	 * We must hold share lock on the buffer content while examining tuple
@@ -2222,9 +2222,9 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 			HeapTupleData heapTuple;
 
 			ItemPointerSet(&tid, block, offnum);
-			if (heap_hot_search_buffer(&tid, scan->rs_rd, buffer, snapshot,
+			if (heap_hot_search_buffer(&tid, scan->rel, buffer, snapshot,
 									   &heapTuple, NULL, true))
-				hscan->rs_vistuples[ntup++] = ItemPointerGetOffsetNumber(&tid);
+				hscan->vis_tuples[ntup++] = ItemPointerGetOffsetNumber(&tid);
 		}
 	}
 	else
@@ -2248,16 +2248,16 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 				continue;
 			loctup.t_data = (HeapTupleHeader) PageGetItem(page, lp);
 			loctup.t_len = ItemIdGetLength(lp);
-			loctup.t_tableOid = scan->rs_rd->rd_id;
+			loctup.t_tableOid = scan->rel->rd_id;
 			ItemPointerSet(&loctup.t_self, block, offnum);
 			valid = HeapTupleSatisfiesVisibility(&loctup, snapshot, buffer);
 			if (valid)
 			{
-				hscan->rs_vistuples[ntup++] = offnum;
-				PredicateLockTID(scan->rs_rd, &loctup.t_self, snapshot,
+				hscan->vis_tuples[ntup++] = offnum;
+				PredicateLockTID(scan->rel, &loctup.t_self, snapshot,
 								 HeapTupleHeaderGetXmin(loctup.t_data));
 			}
-			HeapCheckForSerializableConflictOut(valid, scan->rs_rd, &loctup,
+			HeapCheckForSerializableConflictOut(valid, scan->rel, &loctup,
 												buffer, snapshot);
 		}
 	}
@@ -2265,7 +2265,7 @@ heapam_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 	LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
 
 	Assert(ntup <= MaxHeapTuplesPerPage);
-	hscan->rs_ntuples = ntup;
+	hscan->vis_ntuples = ntup;
 
 	if (tbmres->ntuples < 0)
 		(*lossy_pages)++;
@@ -2291,43 +2291,43 @@ heapam_scan_bitmap_next_tuple(BitmapTableScanDesc *scan,
 	Page		page;
 	ItemId		lp;
 
-	if (hscan->rs_empty_tuples_pending > 0)
+	if (hscan->empty_tuples_pending > 0)
 	{
 		/*
 		 * If we don't have to fetch the tuple, just return nulls.
 		 */
 		ExecStoreAllNullTuple(slot);
-		hscan->rs_empty_tuples_pending--;
+		hscan->empty_tuples_pending--;
 		return true;
 	}
 
 	/*
 	 * Out of range?  If so, nothing more to look at on this page
 	 */
-	if (hscan->rs_cindex < 0 || hscan->rs_cindex >= hscan->rs_ntuples)
+	if (hscan->vis_idx < 0 || hscan->vis_idx >= hscan->vis_ntuples)
 		return false;
 
-	targoffset = hscan->rs_vistuples[hscan->rs_cindex];
-	page = BufferGetPage(hscan->rs_cbuf);
+	targoffset = hscan->vis_tuples[hscan->vis_idx];
+	page = BufferGetPage(hscan->cbuf);
 	lp = PageGetItemId(page, targoffset);
 	Assert(ItemIdIsNormal(lp));
 
-	hscan->rs_ctup.t_data = (HeapTupleHeader) PageGetItem(page, lp);
-	hscan->rs_ctup.t_len = ItemIdGetLength(lp);
-	hscan->rs_ctup.t_tableOid = scan->rs_rd->rd_id;
-	ItemPointerSet(&hscan->rs_ctup.t_self, hscan->rs_cblock, targoffset);
+	hscan->ctup.t_data = (HeapTupleHeader) PageGetItem(page, lp);
+	hscan->ctup.t_len = ItemIdGetLength(lp);
+	hscan->ctup.t_tableOid = scan->rel->rd_id;
+	ItemPointerSet(&hscan->ctup.t_self, hscan->cblock, targoffset);
 
-	pgstat_count_heap_fetch(scan->rs_rd);
+	pgstat_count_heap_fetch(scan->rel);
 
 	/*
 	 * Set up the result slot to point to this tuple.  Note that the slot
 	 * acquires a pin on the buffer.
 	 */
-	ExecStoreBufferHeapTuple(&hscan->rs_ctup,
+	ExecStoreBufferHeapTuple(&hscan->ctup,
 							 slot,
-							 hscan->rs_cbuf);
+							 hscan->cbuf);
 
-	hscan->rs_cindex++;
+	hscan->vis_idx++;
 
 	return true;
 }
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index fe5e19ac6dc..4dfc031c125 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -166,11 +166,11 @@ BitmapHeapNext(BitmapHeapScanState *node)
 		{
 			Assert(scan);
 			/* rescan to release any page pin */
-			tbm_end_iterate(&scan->tbmiterator);
+			tbm_end_iterate(&scan->iterator);
 			table_rescan_bm(scan);
 		}
 
-		tbm_begin_iterate(&scan->tbmiterator, node->tbm, dsa,
+		tbm_begin_iterate(&scan->iterator, node->tbm, dsa,
 						  pstate ?
 						  pstate->tbmiterator :
 						  InvalidDsaPointer);
@@ -436,14 +436,14 @@ BitmapPrefetch(BitmapHeapScanState *node, BitmapTableScanDesc *scan)
 				 * logic normally.  (Would it be better not to increment
 				 * prefetch_pages?)
 				 */
-				skip_fetch = (!(scan->rs_flags & SO_NEED_TUPLES) &&
+				skip_fetch = (!(scan->flags & SO_NEED_TUPLES) &&
 							  !tbmpre->recheck &&
 							  VM_ALL_VISIBLE(node->ss.ss_currentRelation,
 											 tbmpre->blockno,
 											 &node->pvmbuffer));
 
 				if (!skip_fetch)
-					PrefetchBuffer(scan->rs_rd, MAIN_FORKNUM, tbmpre->blockno);
+					PrefetchBuffer(scan->rel, MAIN_FORKNUM, tbmpre->blockno);
 			}
 		}
 
@@ -488,14 +488,14 @@ BitmapPrefetch(BitmapHeapScanState *node, BitmapTableScanDesc *scan)
 				node->pfblockno = tbmpre->blockno;
 
 				/* As above, skip prefetch if we expect not to need page */
-				skip_fetch = (!(scan->rs_flags & SO_NEED_TUPLES) &&
+				skip_fetch = (!(scan->flags & SO_NEED_TUPLES) &&
 							  !tbmpre->recheck &&
 							  VM_ALL_VISIBLE(node->ss.ss_currentRelation,
 											 tbmpre->blockno,
 											 &node->pvmbuffer));
 
 				if (!skip_fetch)
-					PrefetchBuffer(scan->rs_rd, MAIN_FORKNUM, tbmpre->blockno);
+					PrefetchBuffer(scan->rel, MAIN_FORKNUM, tbmpre->blockno);
 			}
 		}
 	}
@@ -594,7 +594,7 @@ ExecEndBitmapHeapScan(BitmapHeapScanState *node)
 	 */
 	if (scanDesc)
 	{
-		tbm_end_iterate(&scanDesc->tbmiterator);
+		tbm_end_iterate(&scanDesc->iterator);
 		table_endscan_bm(scanDesc);
 	}
 
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 3cac199dd36..1d5583cac22 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -100,19 +100,19 @@ typedef struct HeapScanDescData *HeapScanDesc;
 
 typedef struct BitmapHeapScanDesc
 {
-	BitmapTableScanDesc rs_base;
+	BitmapTableScanDesc base;
 
-	BlockNumber rs_nblocks;		/* total number of blocks in rel */
+	BlockNumber nblocks;		/* total number of blocks in rel */
 
-	int			rs_cindex;		/* current tuple's index in vistuples */
-	int			rs_ntuples;		/* number of visible tuples on page */
-	OffsetNumber rs_vistuples[MaxHeapTuplesPerPage];	/* their offsets */
+	int			vis_idx;		/* current tuple's index in vistuples */
+	int			vis_ntuples;	/* number of visible tuples on page */
+	OffsetNumber vis_tuples[MaxHeapTuplesPerPage];	/* their offsets */
 
-	Buffer		rs_cbuf;		/* current buffer in scan, if any */
-	/* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
-	HeapTupleData rs_ctup;		/* current tuple in scan, if any */
+	Buffer		cbuf;			/* current buffer in scan, if any */
+	/* NB: if cbuf is not InvalidBuffer, we hold a pin on that buffer */
+	HeapTupleData ctup;			/* current tuple in scan, if any */
 
-	BlockNumber rs_cblock;		/* current block # in scan, if any */
+	BlockNumber cblock;			/* current block # in scan, if any */
 
 	/*
 	 * These fields are only used for bitmap scans for the "skip fetch"
@@ -121,8 +121,8 @@ typedef struct BitmapHeapScanDesc
 	 * block reported by the bitmap to determine how many NULL-filled tuples
 	 * to return. They are common to parallel and serial BitmapHeapScans
 	 */
-	Buffer		rs_vmbuffer;
-	int			rs_empty_tuples_pending;
+	Buffer		vmbuffer;
+	int			empty_tuples_pending;
 } BitmapHeapScanDesc;
 
 /*
diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h
index 036ef29e7d5..086fce35a8b 100644
--- a/src/include/access/relscan.h
+++ b/src/include/access/relscan.h
@@ -54,19 +54,19 @@ typedef struct TableScanDescData *TableScanDesc;
 
 typedef struct BitmapTableScanDesc
 {
-	Relation	rs_rd;			/* heap relation descriptor */
-	struct SnapshotData *rs_snapshot;	/* snapshot to see */
+	Relation	rel;			/* heap relation descriptor */
+	struct SnapshotData *snapshot;	/* snapshot to see */
 
 	/*
 	 * Members common to Parallel and Serial BitmapTableScans
 	 */
-	TBMIterator tbmiterator;
+	TBMIterator iterator;
 
 	/*
 	 * Information about type and behaviour of the scan, a bitmask of members
 	 * of the ScanOptions enum (see tableam.h).
 	 */
-	uint32		rs_flags;
+	uint32		flags;
 } BitmapTableScanDesc;
 
 /*
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 57bc06f77e0..f7f099b6449 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -984,7 +984,7 @@ table_beginscan_bm(Relation rel, Snapshot snapshot,
 static inline void
 table_rescan_bm(BitmapTableScanDesc *scan)
 {
-	scan->rs_rd->rd_tableam->scan_rescan_bm(scan);
+	scan->rel->rd_tableam->scan_rescan_bm(scan);
 }
 
 /*
@@ -993,7 +993,7 @@ table_rescan_bm(BitmapTableScanDesc *scan)
 static inline void
 table_endscan_bm(BitmapTableScanDesc *scan)
 {
-	scan->rs_rd->rd_tableam->scan_end_bm(scan);
+	scan->rel->rd_tableam->scan_end_bm(scan);
 }
 
 
@@ -2016,9 +2016,9 @@ table_scan_bitmap_next_block(BitmapTableScanDesc *scan,
 	if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
-	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan,
-														   blockno, recheck,
-														   lossy_pages, exact_pages);
+	return scan->rel->rd_tableam->scan_bitmap_next_block(scan,
+														 blockno, recheck,
+														 lossy_pages, exact_pages);
 }
 
 /*
@@ -2041,8 +2041,8 @@ table_scan_bitmap_next_tuple(BitmapTableScanDesc *scan,
 	if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
 		elog(ERROR, "unexpected table_scan_bitmap_next_tuple call during logical decoding");
 
-	return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
-														   slot);
+	return scan->rel->rd_tableam->scan_bitmap_next_tuple(scan,
+														 slot);
 }
 
 /*
-- 
2.34.1