Refactor ColumnarReadNextRow for better readability (#4823)

pull/4862/head^2
Onur Tirtir 2021-04-13 10:44:00 +03:00 committed by GitHub
parent 3efdfdd791
commit 716cc629f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 11 deletions

View File

@ -83,11 +83,14 @@ struct ColumnarReadState
};
/* static function declarations */
static bool StripeReadInProgress(ColumnarReadState *readState);
static bool HasUnreadStripe(ColumnarReadState *readState);
static StripeReadState * BeginStripeRead(StripeMetadata *stripeMetadata, Relation rel,
TupleDesc tupleDesc, List *projectedColumnList,
List *whereClauseList, List *whereClauseVars,
MemoryContext stripeReadContext);
static void EndStripeRead(StripeReadState *stripeReadState);
static void AdvanceStripeRead(ColumnarReadState *readState);
static bool ReadStripeNextRow(StripeReadState *stripeReadState, Datum *columnValues,
bool *columnNulls);
static ChunkGroupReadState * BeginChunkGroupRead(StripeBuffers *stripeBuffers, int
@ -188,18 +191,15 @@ ColumnarReadNextRow(ColumnarReadState *readState, Datum *columnValues, bool *col
{
while (true)
{
if (readState->stripeReadState == NULL)
if (!StripeReadInProgress(readState))
{
uint32 stripeCount = list_length(readState->stripeList);
if (readState->currentStripe >= stripeCount)
if (!HasUnreadStripe(readState))
{
return false;
}
StripeMetadata *stripeMetadata = list_nth(readState->stripeList,
readState->currentStripe);
readState->stripeReadState = BeginStripeRead(stripeMetadata,
readState->relation,
readState->tupleDescriptor,
@ -211,13 +211,8 @@ ColumnarReadNextRow(ColumnarReadState *readState, Datum *columnValues, bool *col
if (!ReadStripeNextRow(readState->stripeReadState, columnValues, columnNulls))
{
readState->chunkGroupsFiltered +=
readState->stripeReadState->chunkGroupsFiltered;
readState->currentStripe++;
EndStripeRead(readState->stripeReadState);
readState->stripeReadState = NULL;
MemoryContextReset(readState->stripeReadContext);
AdvanceStripeRead(readState);
continue;
}
@ -228,6 +223,28 @@ ColumnarReadNextRow(ColumnarReadState *readState, Datum *columnValues, bool *col
}
/*
* StripeReadInProgress returns true if we already started reading a stripe.
*/
static bool
StripeReadInProgress(ColumnarReadState *readState)
{
return readState->stripeReadState != NULL;
}
/*
* HasUnreadStripe returns true if we still have stripes to read during current
* read operation.
*/
static bool
HasUnreadStripe(ColumnarReadState *readState)
{
uint32 stripeCount = list_length(readState->stripeList);
return readState->currentStripe < stripeCount;
}
/*
* ColumnarRescan clears the position where we were scanning so that the next read starts at
* the beginning again
@ -300,6 +317,21 @@ EndStripeRead(StripeReadState *stripeReadState)
}
/*
* AdvanceStripeRead updates chunkGroupsFiltered and increments currentStripe
* for next stripe read.
*/
static void
AdvanceStripeRead(ColumnarReadState *readState)
{
readState->chunkGroupsFiltered +=
readState->stripeReadState->chunkGroupsFiltered;
readState->currentStripe++;
readState->stripeReadState = NULL;
MemoryContextReset(readState->stripeReadContext);
}
/*
* ReadStripeNextRow: If more rows can be read from the current stripe, fill
* in non-NULL columnValues and return true. Otherwise, return false.