From: Markus Wanner <markus@bluegap.ch>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Teodor Sigaev <teodor@sigaev.ru>
Cc: Oleg Bartunov <oleg@sai.msu.su>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: BlockNumber initialized to InvalidBuffer?
Date: Fri, 13 Jul 2012 11:33:51 +0200
Message-ID: <4FFFEB7F.9090702@bluegap.ch> (raw)
In-Reply-To: <13604.1341978315@sss.pgh.pa.us>
References: <4FFC292C.20703@bluegap.ch>
<13604.1341978315@sss.pgh.pa.us>
On 07/11/2012 05:45 AM, Tom Lane wrote:
> I'm also inclined to think that the "while (stack)" coding of the rest
> of it is wrong, misleading, or both, on precisely the same grounds: if
> that loop ever did fall out at the test, the function would have failed
> to honor its contract. The only correct exit points are the "return"s
> in the middle.
I came to the same conclusion, yes. Looks like the additional asserts in
the attached patch all hold true.
As another minor improvement, it doesn't seem necessary to repeatedly
set the rootBlkno.
Regards
Markus Wanner
Attachments:pg-gin-strange-initialization2.diff (text/x-patch, 1.6K) download
#
# old_revision [d90761edf47c6543d4686a76baa0b4e2a7ed113b]
#
# patch "src/backend/access/gin/ginbtree.c"
# from [2d3e63387737b4034fc25ca3cb128d9ac57f4f01]
# to [62efe71b8e3429fc1bf2d2742f8d2fa69f2f4de6]
#
============================================================
*** src/backend/access/gin/ginbtree.c 2d3e63387737b4034fc25ca3cb128d9ac57f4f01
--- src/backend/access/gin/ginbtree.c 62efe71b8e3429fc1bf2d2742f8d2fa69f2f4de6
*************** ginInsertValue(GinBtree btree, GinBtreeS
*** 276,294 ****
ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
{
GinBtreeStack *parent = stack;
! BlockNumber rootBlkno = InvalidBuffer;
Page page,
rpage,
lpage;
/* remember root BlockNumber */
! while (parent)
{
rootBlkno = parent->blkno;
parent = parent->parent;
! }
! while (stack)
{
XLogRecData *rdata;
BlockNumber savedRightLink;
--- 276,298 ----
ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
{
GinBtreeStack *parent = stack;
! BlockNumber rootBlkno;
Page page,
rpage,
lpage;
/* remember root BlockNumber */
! Assert(stack != NULL);
! parent = stack;
! do
{
rootBlkno = parent->blkno;
parent = parent->parent;
! } while (parent);
! Assert(BlockNumberIsValid(rootBlkno));
!
! for (;;)
{
XLogRecData *rdata;
BlockNumber savedRightLink;
*************** ginInsertValue(GinBtree btree, GinBtreeS
*** 469,474 ****
--- 473,479 ----
UnlockReleaseBuffer(stack->buffer);
pfree(stack);
+ Assert(parent != NULL); /* parent == NULL case is handled above */
stack = parent;
}
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: markus@bluegap.ch, tgl@sss.pgh.pa.us, teodor@sigaev.ru, oleg@sai.msu.su
Subject: Re: BlockNumber initialized to InvalidBuffer?
In-Reply-To: <4FFFEB7F.9090702@bluegap.ch>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox