Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1a9405d

Browse files
committed
Cosmetic cleanup of ginInsertValue().
Make it clearer that the passed stack mustn't be empty, and that we are not supposed to fall off the end of the stack in the main loop. Tighten the loop that extracts the root block number, too. Markus Wanner and Tom Lane
1 parent a84bf49 commit 1a9405d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/backend/access/gin/ginbtree.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,22 @@ ginFindParents(GinBtree btree, GinBtreeStack *stack,
275275
void
276276
ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
277277
{
278-
GinBtreeStack *parent = stack;
279-
BlockNumber rootBlkno = InvalidBuffer;
278+
GinBtreeStack *parent;
279+
BlockNumber rootBlkno;
280280
Page page,
281281
rpage,
282282
lpage;
283283

284-
/* remember root BlockNumber */
285-
while (parent)
286-
{
287-
rootBlkno = parent->blkno;
284+
/* extract root BlockNumber from stack */
285+
Assert(stack != NULL);
286+
parent = stack;
287+
while (parent->parent)
288288
parent = parent->parent;
289-
}
289+
rootBlkno = parent->blkno;
290+
Assert(BlockNumberIsValid(rootBlkno));
290291

291-
while (stack)
292+
/* this loop crawls up the stack until the insertion is complete */
293+
for (;;)
292294
{
293295
XLogRecData *rdata;
294296
BlockNumber savedRightLink;
@@ -457,7 +459,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
457459
*/
458460
ginFindParents(btree, stack, rootBlkno);
459461
parent = stack->parent;
460-
page = BufferGetPage(parent->buffer);
462+
Assert(parent != NULL);
461463
break;
462464
}
463465

0 commit comments

Comments
 (0)