Skip to content

Commit efa49da

Browse files
soumyadeep2007reshke
authored andcommitted
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.
1 parent 184585f commit efa49da

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/backend/access/brin/brin.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ typedef struct BrinBuildState
6565
/* GPDB specific state for AO/CO tables */
6666

6767
bool bs_isAO;
68-
/* Number of tuples processed for current BlockSequence */
69-
uint64 bs_seq_reltuples;
68+
/* Have we incorporated even one data tuple into the build state? */
69+
bool bs_aoHasDataTuple;
7070
} BrinBuildState;
7171

7272
/*
@@ -878,32 +878,26 @@ brinbuildCallback(Relation index,
878878
if (state->bs_isAO)
879879
{
880880
BlockNumber seqStartBlk = AOHeapBlockGet_startHeapBlock(thisblock);
881+
881882
if (state->bs_currRangeStart < seqStartBlk)
882883
{
883884
/* We are starting a new block sequence */
885+
int seqNum;
884886

885887
/* process the final batch in the current block sequence (if any) */
886-
if (state->bs_seq_reltuples > 0)
888+
if (state->bs_aoHasDataTuple)
887889
form_and_insert_tuple(state);
888890

889891
/* adjust the current block sequence */
890-
int seqNum = AOSegmentGet_blockSequenceNum(thisblock);
892+
seqNum = AOSegmentGet_blockSequenceNum(thisblock);
891893
brinRevmapAOPositionAtStart(state->bs_rmAccess, seqNum);
892894

893895
/* readjust the range lower bound */
894896
state->bs_currRangeStart = seqStartBlk;
895897

896-
/* reset the bs_seq_reltuples counter for the new block sequence */
897-
state->bs_seq_reltuples = 1;
898-
899898
/* re-initialize state for it */
900899
brin_memtuple_initialize(state->bs_dtuple, state->bs_bdesc);
901900
}
902-
else
903-
{
904-
/* We are in the same block sequence */
905-
state->bs_seq_reltuples++;
906-
}
907901
}
908902

909903
while (thisblock > state->bs_currRangeStart + state->bs_pagesPerRange - 1)
@@ -928,6 +922,8 @@ brinbuildCallback(Relation index,
928922
/* Accumulate the current tuple into the running state */
929923
(void) add_values_to_range(index, state->bs_bdesc, state->bs_dtuple,
930924
values, isnull);
925+
/* GPDB: Additional accounting in the build state for AO/CO relations */
926+
state->bs_aoHasDataTuple = true;
931927
}
932928

933929
/*
@@ -1011,7 +1007,7 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
10111007
* as is done for heap. If we did, we would have to do so for all 128
10121008
* possible block sequences, creating unnecessary bloat.
10131009
*/
1014-
if (!isAO || state->bs_seq_reltuples != 0)
1010+
if (!isAO || state->bs_aoHasDataTuple)
10151011
form_and_insert_tuple(state);
10161012

10171013
/* release resources */
@@ -1460,8 +1456,8 @@ initialize_brin_buildstate(Relation idxRel, BrinRevmap *revmap,
14601456
state->bs_dtuple = brin_new_memtuple(state->bs_bdesc);
14611457

14621458
/* GPDB specific state for AO/CO tables */
1463-
state->bs_isAO = isAO;
1464-
state->bs_seq_reltuples = 0;
1459+
state->bs_isAO = isAO;
1460+
state->bs_aoHasDataTuple = false;
14651461

14661462
brin_memtuple_initialize(state->bs_dtuple, state->bs_bdesc);
14671463

0 commit comments

Comments
 (0)