Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d27dcf

Browse files
committed
Fix bug in gistRelocateBuildBuffersOnSplit().
When we create a temporary copy of the old node buffer, in stack, we mustn'tleak that into any of the long-lived data structures. Before this patch,when we called gistPopItupFromNodeBuffer(), it got added to the array of"loaded buffers". After gistRelocateBuildBuffersOnSplit() exits, thepointer added to the loaded buffers array points to garbage. Often that goesunnotied, because when we go through the array of loaded buffers to unloadthem, buffers with a NULL pageBuffer are ignored, which can often happen byaccident even if the pointer points to garbage.This patch fixes that by marking the temporary copy in stack explicitly astemporary, and refrain from adding buffers marked as temporary to the arrayof loaded buffers.While we're at it, initialize nodeBuffer->pageBlocknum to InvalidBlockNumberand improve comments a bit. This isn't strictly necessary, but makesdebugging easier.
1 parent8402fab commit1d27dcf

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

‎src/backend/access/gist/gistbuildbuffers.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ gistGetNodeBuffer(GISTBuildBuffers *gfbb, GISTSTATE *giststate,
148148
intlevel;
149149
MemoryContextoldcxt=MemoryContextSwitchTo(gfbb->context);
150150

151-
nodeBuffer->pageBuffer=NULL;
151+
/*nodeBuffer->nodeBlocknum is the hash key and was filled in already */
152152
nodeBuffer->blocksCount=0;
153+
nodeBuffer->pageBlocknum=InvalidBlockNumber;
154+
nodeBuffer->pageBuffer=NULL;
153155
nodeBuffer->queuedForEmptying= false;
154156

155157
/*
@@ -244,11 +246,15 @@ gistAllocateNewPageBuffer(GISTBuildBuffers *gfbb)
244246
}
245247

246248
/*
247-
* Add specifiedblock number into loadedBuffers array.
249+
* Add specifiedbuffer into loadedBuffers array.
248250
*/
249251
staticvoid
250252
gistAddLoadedBuffer(GISTBuildBuffers*gfbb,GISTNodeBuffer*nodeBuffer)
251253
{
254+
/* Never add a temporary buffer to the array */
255+
if (nodeBuffer->isTemp)
256+
return;
257+
252258
/* Enlarge the array if needed */
253259
if (gfbb->loadedBuffersCount >=gfbb->loadedBuffersLen)
254260
{
@@ -591,7 +597,7 @@ gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, GISTSTATE *giststate,
591597
i;
592598
GISTENTRYentry[INDEX_MAX_KEYS];
593599
boolisnull[INDEX_MAX_KEYS];
594-
GISTNodeBuffernodebuf;
600+
GISTNodeBufferoldBuf;
595601
ListCell*lc;
596602

597603
/* If the splitted page doesn't have buffers, we have nothing to do. */
@@ -619,16 +625,14 @@ gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, GISTSTATE *giststate,
619625
* read the tuples straight from the heap instead of the root buffer.
620626
*/
621627
Assert(blocknum!=GIST_ROOT_BLKNO);
622-
memcpy(&nodebuf,nodeBuffer,sizeof(GISTNodeBuffer));
628+
memcpy(&oldBuf,nodeBuffer,sizeof(GISTNodeBuffer));
629+
oldBuf.isTemp= true;
623630

624631
/* Reset the old buffer, used for the new left page from now on */
625632
nodeBuffer->blocksCount=0;
626633
nodeBuffer->pageBuffer=NULL;
627634
nodeBuffer->pageBlocknum=InvalidBlockNumber;
628635

629-
/* Reassign pointer to the saved copy. */
630-
nodeBuffer=&nodebuf;
631-
632636
/*
633637
* Allocate memory for information about relocation buffers.
634638
*/
@@ -675,7 +679,7 @@ gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, GISTSTATE *giststate,
675679
* Loop through all index tuples on the buffer on the splitted page,
676680
* moving them to buffers on the new pages.
677681
*/
678-
while (gistPopItupFromNodeBuffer(gfbb,nodeBuffer,&itup))
682+
while (gistPopItupFromNodeBuffer(gfbb,&oldBuf,&itup))
679683
{
680684
floatsum_grow,
681685
which_grow[INDEX_MAX_KEYS];

‎src/include/access/gist_private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ typedef struct
326326
/* is this buffer queued for emptying? */
327327
boolqueuedForEmptying;
328328

329+
/* is this a temporary copy, not in the hash table? */
330+
boolisTemp;
331+
329332
structGISTBufferingInsertStack*path;
330333
}GISTNodeBuffer;
331334

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp