Commit fcbf4558 authored by Alvaro Herrera's avatar Alvaro Herrera

Fix unitialized variables

As complained by clang, reported by Andres Freund.  Brown paper bag bug
in ccc4c074.

Add some comments, too.

Backpatch to 9.5, like that one.
parent cfe30a72
...@@ -86,6 +86,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, ...@@ -86,6 +86,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
{ {
LockBuffer(oldbuf, BUFFER_LOCK_EXCLUSIVE); LockBuffer(oldbuf, BUFFER_LOCK_EXCLUSIVE);
newbuf = InvalidBuffer; newbuf = InvalidBuffer;
extended = false;
} }
oldpage = BufferGetPage(oldbuf); oldpage = BufferGetPage(oldbuf);
oldlp = PageGetItemId(oldpage, oldoff); oldlp = PageGetItemId(oldpage, oldoff);
...@@ -335,9 +336,8 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, ...@@ -335,9 +336,8 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
brinRevmapExtend(revmap, heapBlk); brinRevmapExtend(revmap, heapBlk);
/* /*
* Obtain a locked buffer to insert the new tuple. Note * Acquire lock on buffer supplied by caller, if any. If it doesn't have
* brin_getinsertbuffer ensures there's enough space in the returned * enough space, unpin it to obtain a new one below.
* buffer.
*/ */
if (BufferIsValid(*buffer)) if (BufferIsValid(*buffer))
{ {
...@@ -354,12 +354,18 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, ...@@ -354,12 +354,18 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
} }
} }
/*
* If we still don't have a usable buffer, have brin_getinsertbuffer
* obtain one for us.
*/
if (!BufferIsValid(*buffer)) if (!BufferIsValid(*buffer))
{ {
*buffer = brin_getinsertbuffer(idxrel, InvalidBuffer, itemsz, &extended); *buffer = brin_getinsertbuffer(idxrel, InvalidBuffer, itemsz, &extended);
Assert(BufferIsValid(*buffer)); Assert(BufferIsValid(*buffer));
Assert(extended || br_page_get_freespace(BufferGetPage(*buffer)) >= itemsz); Assert(extended || br_page_get_freespace(BufferGetPage(*buffer)) >= itemsz);
} }
else
extended = false;
/* Now obtain lock on revmap buffer */ /* Now obtain lock on revmap buffer */
revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk); revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
...@@ -367,6 +373,7 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, ...@@ -367,6 +373,7 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
page = BufferGetPage(*buffer); page = BufferGetPage(*buffer);
blk = BufferGetBlockNumber(*buffer); blk = BufferGetBlockNumber(*buffer);
/* Execute the actual insertion */
START_CRIT_SECTION(); START_CRIT_SECTION();
if (extended) if (extended)
brin_page_init(BufferGetPage(*buffer), BRIN_PAGETYPE_REGULAR); brin_page_init(BufferGetPage(*buffer), BRIN_PAGETYPE_REGULAR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment