Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f61jV-0004dr-4u for pgsql-committers@arkaria.postgresql.org; Tue, 10 Apr 2018 22:27:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f61jT-0005UF-Eb for pgsql-committers@arkaria.postgresql.org; Tue, 10 Apr 2018 22:27:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f61jT-0005U6-9N for pgsql-committers@lists.postgresql.org; Tue, 10 Apr 2018 22:27:19 +0000 Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f61jP-0003Ox-Ts for pgsql-committers@lists.postgresql.org; Tue, 10 Apr 2018 22:27:18 +0000 X-Originating-IP: 98.122.175.38 Received: from [192.168.10.146] (unknown [98.122.175.38]) (Authenticated sender: adsend@dunslane.net) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 03C6F4000B; Wed, 11 Apr 2018 00:27:11 +0200 (CEST) Subject: Re: pgsql: Optimize btree insertions for common case of increasing values To: Peter Geoghegan , Pavan Deolasee Cc: pgsql-committers References: From: Andrew Dunstan Message-ID: Date: Tue, 10 Apr 2018 18:27:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/10/2018 03:30 PM, Peter Geoghegan wrote: > On Tue, Apr 10, 2018 at 12:07 PM, Pavan Deolasee > wrote: >> Hmm. I am a bit confused why we want to mention anything about something >> we're not even considering seriously, let alone any patch or work in that >> direction. If we at all change everything to use extent based storage, there >> would be many other things that will break and require changes, no? > I guess you're right. It's implied by what you already say in the > nbtree README. No need to do more. > >> Apart from that, other changes requested are included in the patch. This >> also takes care of Heikki's observation regarding UNLOGGED tables on the >> other thread. > Cool. > > Feedback on this version: > >> +without a backend's cached page also being detected as invalidated, but >> +only when we happen to recycle a page that once again becomes the >> +rightmost leaf page. > I suggest wording this as "...but only when we happen to recycle a > block that once again gets recycled as the rightmost leaf page". (I'm > correcting my own wording here, I think.) > > * No need to start a sentence with "So" here, IMV: > >> + * Note the fact that whenever we fail to take the fastpath, we clear >> + * the cached block. So checking for a valid cached block at this point >> + * is enough to decide whether we're in a fastpath or not. > * This should test "if (P_RIGHTMOST(lpageop) && P_ISLEAF(lpageop) && > !P_ISROOT(lpageop))", because you don't want to use the optimization > for internal pages that happen to not be the root -- there is no leaf > check here: > >> + /* >> + * Cache the block information if we just inserted into the rightmost >> + * leaf page of the index and it's not the root page. For very small >> + * index where root is also the leaf, there is no point trying for any >> + * optimisation. >> + */ >> + if (P_RIGHTMOST(lpageop) && !P_ISROOT(lpageop)) >> + cachedBlock = BufferGetBlockNumber(buf); > * I don't think that you should have a #define inline with code like this: > >> +#define BTREE_FASTPATH_MIN_LEVEL 2 >> + if (BlockNumberIsValid(cachedBlock) && >> + _bt_getrootheight(rel) >= BTREE_FASTPATH_MIN_LEVEL) >> + RelationSetTargetBlock(rel, cachedBlock); > I suggest putting this in nbtree.h instead. You can put it just after > BTREE_NONLEAF_FILLFACTOR, with a comment, in a separate block/section. > > Other than that, looks good to me. > Committed with light editing. I didn't put the #define in the .h file - it's only used here and that seemed like unnecessary clutter. I moved it to the top of the file. I also standardized the spelling of "optimization". cheers andrew