You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by re...@apache.org on 2025/02/26 13:51:08 UTC

(cloudberry) 09/10: brin ao/co: Bool to track tuples in build state

This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit efa49da09b56ea2c392c7bc591135480828c0645
Author: Soumyadeep Chakraborty <so...@gmail.com>
AuthorDate: Fri May 12 18:04:04 2023 -0700

    brin ao/co: Bool to track tuples in build state
    
    There is no reason why we need to maintain a counter. Let's use a
    boolean variable instead. Add appropriate commentary.
---
 src/backend/access/brin/brin.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index ee081df052..6aa6c566e1 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -65,8 +65,8 @@ typedef struct BrinBuildState
 	/* GPDB specific state for AO/CO tables */
 
 	bool         bs_isAO;
-	/* Number of tuples processed for current BlockSequence */
-	uint64       bs_seq_reltuples;
+	/* Have we incorporated even one data tuple into the build state? */
+	bool         bs_aoHasDataTuple;
 } BrinBuildState;
 
 /*
@@ -878,32 +878,26 @@ brinbuildCallback(Relation index,
 	if (state->bs_isAO)
 	{
 		BlockNumber seqStartBlk = AOHeapBlockGet_startHeapBlock(thisblock);
+
 		if (state->bs_currRangeStart < seqStartBlk)
 		{
 			/* We are starting a new block sequence */
+			int seqNum;
 
 			/* process the final batch in the current block sequence (if any) */
-			if (state->bs_seq_reltuples > 0)
+			if (state->bs_aoHasDataTuple)
 				form_and_insert_tuple(state);
 
 			/* adjust the current block sequence */
-			int seqNum = AOSegmentGet_blockSequenceNum(thisblock);
+			seqNum = AOSegmentGet_blockSequenceNum(thisblock);
 			brinRevmapAOPositionAtStart(state->bs_rmAccess, seqNum);
 
 			/* readjust the range lower bound */
 			state->bs_currRangeStart = seqStartBlk;
 
-			/* reset the bs_seq_reltuples counter for the new block sequence */
-			state->bs_seq_reltuples = 1;
-
 			/* re-initialize state for it */
 			brin_memtuple_initialize(state->bs_dtuple, state->bs_bdesc);
 		}
-		else
-		{
-			/* We are in the same block sequence */
-			state->bs_seq_reltuples++;
-		}
 	}
 
 	while (thisblock > state->bs_currRangeStart + state->bs_pagesPerRange - 1)
@@ -928,6 +922,8 @@ brinbuildCallback(Relation index,
 	/* Accumulate the current tuple into the running state */
 	(void) add_values_to_range(index, state->bs_bdesc, state->bs_dtuple,
 							   values, isnull);
+	/* GPDB: Additional accounting in the build state for AO/CO relations */
+	state->bs_aoHasDataTuple = true;
 }
 
 /*
@@ -1011,7 +1007,7 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
 	 * as is done for heap. If we did, we would have to do so for all 128
 	 * possible block sequences, creating unnecessary bloat.
 	 */
-	if (!isAO || state->bs_seq_reltuples != 0)
+	if (!isAO || state->bs_aoHasDataTuple)
 		form_and_insert_tuple(state);
 
 	/* release resources */
@@ -1460,8 +1456,8 @@ initialize_brin_buildstate(Relation idxRel, BrinRevmap *revmap,
 	state->bs_dtuple = brin_new_memtuple(state->bs_bdesc);
 
 	/* GPDB specific state for AO/CO tables */
-	state->bs_isAO          = isAO;
-	state->bs_seq_reltuples = 0;
+	state->bs_isAO           = isAO;
+	state->bs_aoHasDataTuple = false;
 
 	brin_memtuple_initialize(state->bs_dtuple, state->bs_bdesc);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org