Re: Faster inserts with mostly-monotonically increasing values

2018-04-10 Thread Pavan Deolasee
On Tue, Apr 10, 2018 at 7:49 PM, Claudio Freire wrote: > On Tue, Apr 10, 2018 at 11:10 AM, Heikki Linnakangas > wrote: > > > > > Why is this RelationSetTargetBlock() call inside the "XLOG stuff" block? > > ISTM that we're failing to take advantage of this optimization for > unlogged > > tables,

Re: Faster inserts with mostly-monotonically increasing values

2018-04-10 Thread Claudio Freire
On Tue, Apr 10, 2018 at 11:10 AM, Heikki Linnakangas wrote: >> /* XLOG stuff */ >> if (RelationNeedsWAL(rel)) >> { >> ... >> >> if (P_ISLEAF(lpageop)) >> { >>

Re: Faster inserts with mostly-monotonically increasing values

2018-04-10 Thread Heikki Linnakangas
/* XLOG stuff */ if (RelationNeedsWAL(rel)) { ... if (P_ISLEAF(lpageop)) { xlinfo = XLOG_BTREE_INSERT_LEAF; /*

Re: Faster inserts with mostly-monotonically increasing values

2018-03-26 Thread Andrew Dunstan
On Mon, Mar 26, 2018 at 6:06 PM, Pavan Deolasee wrote: > > > On Sun, Mar 25, 2018 at 6:00 AM, Andrew Dunstan > wrote: >> >> On Fri, Mar 23, 2018 at 8:27 PM, Pavan Deolasee >> wrote: >> >> >> >> >> >> I would probably just have a few regression lines that should be sure >> >> to exercise the code

Re: Faster inserts with mostly-monotonically increasing values

2018-03-26 Thread Pavan Deolasee
On Sun, Mar 25, 2018 at 6:00 AM, Andrew Dunstan < andrew.duns...@2ndquadrant.com> wrote: > On Fri, Mar 23, 2018 at 8:27 PM, Pavan Deolasee > wrote: > >> > >> > >> I would probably just have a few regression lines that should be sure > >> to exercise the code path and leave it at that. > >> > > >

Re: Faster inserts with mostly-monotonically increasing values

2018-03-24 Thread Andrew Dunstan
On Fri, Mar 23, 2018 at 8:27 PM, Pavan Deolasee wrote: >> >> >> I would probably just have a few regression lines that should be sure >> to exercise the code path and leave it at that. >> > > I changed the regression tests to include a few more scenarios, basically > using multi-column indexes in

Re: Faster inserts with mostly-monotonically increasing values

2018-03-23 Thread Pavan Deolasee
Hi Andrew and Claudio, Thanks for the review! On Fri, Mar 23, 2018 at 10:19 AM, Andrew Dunstan < andrew.duns...@2ndquadrant.com> wrote: > On Fri, Mar 23, 2018 at 10:20 AM, Claudio Freire > wrote: > > > This patch looks in pretty good shape. I have been trying hard to > think of some failure mod

Re: Faster inserts with mostly-monotonically increasing values

2018-03-22 Thread Andrew Dunstan
On Fri, Mar 23, 2018 at 10:20 AM, Claudio Freire wrote: > On Thu, Mar 22, 2018 at 3:29 AM, Pavan Deolasee > wrote: >> >> On Thu, Mar 22, 2018 at 7:22 AM, Claudio Freire >> wrote: >>> >>> >>> If you're not planning on making any further changes, would you mind >>> posting a coalesced patch? >>> >

Re: Faster inserts with mostly-monotonically increasing values

2018-03-22 Thread Claudio Freire
On Thu, Mar 22, 2018 at 3:29 AM, Pavan Deolasee wrote: > > On Thu, Mar 22, 2018 at 7:22 AM, Claudio Freire > wrote: >> >> >> If you're not planning on making any further changes, would you mind >> posting a coalesced patch? >> >> Notice that I removed the last offset thing only halfway, so it wou

Re: Faster inserts with mostly-monotonically increasing values

2018-03-21 Thread Pavan Deolasee
On Thu, Mar 22, 2018 at 7:22 AM, Claudio Freire wrote: > > If you're not planning on making any further changes, would you mind > posting a coalesced patch? > > Notice that I removed the last offset thing only halfway, so it would > need some cleanup. > Here is an updated patch. I removed the la

Re: Faster inserts with mostly-monotonically increasing values

2018-03-21 Thread Claudio Freire
On Mon, Mar 19, 2018 at 12:06 PM, Claudio Freire wrote: > On Mon, Mar 19, 2018 at 11:57 AM, Pavan Deolasee > wrote: >> >> >> On Thu, Mar 15, 2018 at 7:51 AM, Claudio Freire >> wrote: >>> >>> >>> >>> I applied the attached patches on top of your patch, so it would be >>> nice to see if you can gi

Re: Faster inserts with mostly-monotonically increasing values

2018-03-19 Thread Claudio Freire
On Mon, Mar 19, 2018 at 11:57 AM, Pavan Deolasee wrote: > > > On Thu, Mar 15, 2018 at 7:51 AM, Claudio Freire > wrote: >> >> >> >> I applied the attached patches on top of your patch, so it would be >> nice to see if you can give it a try in your test hardware to see >> whether it helps. > > > I

Re: Faster inserts with mostly-monotonically increasing values

2018-03-19 Thread Pavan Deolasee
On Thu, Mar 15, 2018 at 7:51 AM, Claudio Freire wrote: > > > I applied the attached patches on top of your patch, so it would be > nice to see if you can give it a try in your test hardware to see > whether it helps. > I can confirm that I no longer see any regression at 8 or even 16 clients. In

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Claudio Freire
On Wed, Mar 14, 2018 at 12:05 PM, Claudio Freire wrote: > On Wed, Mar 14, 2018 at 1:36 AM, Pavan Deolasee > wrote: >> >> >> On Sun, Mar 11, 2018 at 9:18 PM, Claudio Freire >> wrote: >>> >>> On Sun, Mar 11, 2018 at 2:27 AM, Pavan Deolasee >>> >>> > >>> > Yes, I will try that next - it seems like

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Claudio Freire
On Wed, Mar 14, 2018 at 1:36 AM, Pavan Deolasee wrote: > > > On Sun, Mar 11, 2018 at 9:18 PM, Claudio Freire > wrote: >> >> On Sun, Mar 11, 2018 at 2:27 AM, Pavan Deolasee >> >> > >> > Yes, I will try that next - it seems like a good idea. So the idea would >> > be: >> > check if the block is sti

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Pavan Deolasee
On Wed, Mar 14, 2018 at 7:21 PM, Simon Riggs wrote: > On 14 March 2018 at 13:33, Pavan Deolasee > wrote: > > > > > > On Wed, Mar 14, 2018 at 4:53 PM, Simon Riggs < > simon.ri...@2ndquadrant.com> > > wrote: > >> > >> On 14 March 2018 at 04:36, Pavan Deolasee > >> wrote: > >> > I wonder if the sh

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Claudio Freire
On Wed, Mar 14, 2018 at 10:51 AM, Simon Riggs wrote: > If there is enough delay in step 1 then any benefit is lost anyway, so > there is no point taking the cached path even when successful, so its > better to ignore in that case. I find myself agreeing with that.

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Simon Riggs
On 14 March 2018 at 13:33, Pavan Deolasee wrote: > > > On Wed, Mar 14, 2018 at 4:53 PM, Simon Riggs > wrote: >> >> On 14 March 2018 at 04:36, Pavan Deolasee >> wrote: >> > I wonder if the shortened code path actually leads to >> > heavier contention for EXCLUSIVE lock on the rightmost page, whic

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Pavan Deolasee
On Wed, Mar 14, 2018 at 4:53 PM, Simon Riggs wrote: > On 14 March 2018 at 04:36, Pavan Deolasee > wrote: > > I wonder if the shortened code path actually leads to > > heavier contention for EXCLUSIVE lock on the rightmost page, which in > turn > > causes the slowdown. But that's just a theory. A

Re: Faster inserts with mostly-monotonically increasing values

2018-03-14 Thread Simon Riggs
On 14 March 2018 at 04:36, Pavan Deolasee wrote: > I wonder if the shortened code path actually leads to > heavier contention for EXCLUSIVE lock on the rightmost page, which in turn > causes the slowdown. But that's just a theory. Any ideas how to prove or > disprove that theory or any other point

Re: Faster inserts with mostly-monotonically increasing values

2018-03-13 Thread Pavan Deolasee
On Wed, Mar 14, 2018 at 10:58 AM, Claudio Freire wrote: > > > I'm thinking there could be contention on some lock somewhere. > > Can you attach the benchmark script you're using so I can try to reproduce > it? > I am using a very ad-hoc script.. But here it is.. It assumes a presence of a branc

Re: Faster inserts with mostly-monotonically increasing values

2018-03-13 Thread Claudio Freire
On Wed, Mar 14, 2018 at 1:36 AM, Pavan Deolasee wrote: > > > On Sun, Mar 11, 2018 at 9:18 PM, Claudio Freire > wrote: >> >> On Sun, Mar 11, 2018 at 2:27 AM, Pavan Deolasee >> >> > >> > Yes, I will try that next - it seems like a good idea. So the idea would >> > be: >> > check if the block is sti

Re: Faster inserts with mostly-monotonically increasing values

2018-03-13 Thread Pavan Deolasee
On Sun, Mar 11, 2018 at 9:18 PM, Claudio Freire wrote: > On Sun, Mar 11, 2018 at 2:27 AM, Pavan Deolasee > > > > > Yes, I will try that next - it seems like a good idea. So the idea would > be: > > check if the block is still the rightmost block and the insertion-key is > > greater than the first

Re: Faster inserts with mostly-monotonically increasing values

2018-03-11 Thread Claudio Freire
On Sun, Mar 11, 2018 at 2:27 AM, Pavan Deolasee wrote: > > > On Sat, Mar 10, 2018 at 12:11 AM, Claudio Freire > wrote: >> >> On Fri, Mar 9, 2018 at 2:54 PM, Pavan Deolasee >> wrote: >> > >> > >> >> > >> > So yes, the benefits of the patch go down with higher number of clients, >> > but >> > it d

Re: Faster inserts with mostly-monotonically increasing values

2018-03-10 Thread Pavan Deolasee
On Sat, Mar 10, 2018 at 12:11 AM, Claudio Freire wrote: > On Fri, Mar 9, 2018 at 2:54 PM, Pavan Deolasee > wrote: > > > > > > > > > So yes, the benefits of the patch go down with higher number of clients, > but > > it does not entirely vanish. > > What if you implement my suggestion? > > That sh

Re: Faster inserts with mostly-monotonically increasing values

2018-03-09 Thread Claudio Freire
On Fri, Mar 9, 2018 at 2:54 PM, Pavan Deolasee wrote: > > > On Tue, Mar 6, 2018 at 10:10 AM, Pavan Deolasee > wrote: >> >> >> >> On Tue, Mar 6, 2018 at 7:29 AM, Peter Geoghegan wrote: >>> >>> On Mon, Mar 5, 2018 at 5:48 PM, Claudio Freire >>> wrote: >>> >>> > I believe PKs are a prime candidate

Re: Faster inserts with mostly-monotonically increasing values

2018-03-09 Thread Pavan Deolasee
On Tue, Mar 6, 2018 at 10:10 AM, Pavan Deolasee wrote: > > > On Tue, Mar 6, 2018 at 7:29 AM, Peter Geoghegan wrote: > >> On Mon, Mar 5, 2018 at 5:48 PM, Claudio Freire >> wrote: >> >> > I believe PKs are a prime candidate for this optimization, and >> > expecting it to apply only when no concur

Re: Faster inserts with mostly-monotonically increasing values

2018-03-06 Thread Claudio Freire
On Tue, Mar 6, 2018 at 9:06 AM, Simon Riggs wrote: >> Simon had raised concerns about DESC indexes and whether we need to do the >> checks for leftmost page in that case. I haven't yet figured out if DESC >> indexes are actually stored in the reverse order. I am gonna look at that >> too. > > No,

Re: Faster inserts with mostly-monotonically increasing values

2018-03-06 Thread Simon Riggs
On 6 March 2018 at 04:40, Pavan Deolasee wrote: > > > On Tue, Mar 6, 2018 at 7:29 AM, Peter Geoghegan wrote: >> >> On Mon, Mar 5, 2018 at 5:48 PM, Claudio Freire >> wrote: >> >> > I believe PKs are a prime candidate for this optimization, and >> > expecting it to apply only when no concurrency i

Re: Faster inserts with mostly-monotonically increasing values

2018-03-06 Thread Claudio Freire
On Tue, Mar 6, 2018 at 1:45 AM, Peter Geoghegan wrote: > On Mon, Mar 5, 2018 at 7:10 PM, Claudio Freire wrote: >>> Introducing any case that allows us to land on a recycled page, and >>> reason that it must at least not be the page we were looking for based >>> on *any* criteria about the page it

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Peter Geoghegan
On Mon, Mar 5, 2018 at 7:10 PM, Claudio Freire wrote: >> Introducing any case that allows us to land on a recycled page, and >> reason that it must at least not be the page we were looking for based >> on *any* criteria about the page itself seems very brittle. Yeah, it >> probably won't break in

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Pavan Deolasee
On Tue, Mar 6, 2018 at 7:29 AM, Peter Geoghegan wrote: > On Mon, Mar 5, 2018 at 5:48 PM, Claudio Freire > wrote: > > > I believe PKs are a prime candidate for this optimization, and > > expecting it to apply only when no concurrency is involved is severely > > dumbing down the optimization. > >

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Claudio Freire
On Mon, Mar 5, 2018 at 10:59 PM, Peter Geoghegan wrote: > On Mon, Mar 5, 2018 at 5:48 PM, Claudio Freire wrote: >> But in thise case there's no right link to follow, so it's a non-issue. >> >> BTree doesn't truncate AFAIK, so the cached block number can't be >> nonexisting (beyond the end of the

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Peter Geoghegan
On Mon, Mar 5, 2018 at 5:48 PM, Claudio Freire wrote: > From what I read, both phase 1 & 2 are served by the !P_IGNORE check. True. > For the third phase: > >> A deleted page can only be reclaimed once there is no scan or search that >> has a reference to it; until then, it must stay in place wi

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Claudio Freire
On Mon, Mar 5, 2018 at 9:52 PM, Peter Geoghegan wrote: > On Mon, Mar 5, 2018 at 4:37 PM, Claudio Freire wrote: >> Correct me if I'm wrong, but there's lots of code in nbtree already >> that risks reading recycled pages for various reasons. Presumably, >> checking P_ISDELETED and P_ISHALFDEAD shou

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Peter Geoghegan
On Mon, Mar 5, 2018 at 4:37 PM, Claudio Freire wrote: > Correct me if I'm wrong, but there's lots of code in nbtree already > that risks reading recycled pages for various reasons. Presumably, > checking P_ISDELETED and P_ISHALFDEAD should be enough, which is what > !P_IGNORE implies. You're mist

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Claudio Freire
On Mon, Mar 5, 2018 at 9:37 PM, Claudio Freire wrote: > Assuming the rightmost page is the first page the value could be on, > it already does get an exclusive buffer lock. That made me check, and: +/* + * Acquire exclusive lock on the buffer before doing any checks. This +

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Claudio Freire
On Mon, Mar 5, 2018 at 9:12 PM, Peter Geoghegan wrote: > On Thu, Mar 1, 2018 at 3:18 PM, Claudio Freire wrote: >> The key there is strictly greater than the rightmost key. As such, it >> must precede the first page with an equal key, and since it's the >> rightmost page... there's no such key. Bu

Re: Faster inserts with mostly-monotonically increasing values

2018-03-05 Thread Peter Geoghegan
On Thu, Mar 1, 2018 at 3:18 PM, Claudio Freire wrote: > given... > > +if (P_ISLEAF(lpageop) && P_RIGHTMOST(lpageop) && > +!P_INCOMPLETE_SPLIT(lpageop) && > +!P_IGNORE(lpageop) && > +(PageGetFreeSpace(page) > itemsz) && > +_bt_compare(rel, nat

Re: Faster inserts with mostly-monotonically increasing values

2018-03-01 Thread Claudio Freire
On Sun, Dec 31, 2017 at 8:06 AM, Peter Geoghegan wrote: > I also have my > doubts about unique index enforcement remaining correct with the patch > when there are many physical duplicates, to the extent that more than > a single leaf page is needed for a single value. given... +if (P_ISL

Re: Faster inserts with mostly-monotonically increasing values

2018-01-18 Thread Simon Riggs
On 31 December 2017 at 11:06, Peter Geoghegan wrote: > On Sun, Dec 31, 2017 at 6:44 AM, Pavan Deolasee > wrote: >> Here is a patch that implements the idea. If the last insert happens to be >> in the rightmost block of an index, then we cache the block and check that >> first for the next insert.

Re: Faster inserts with mostly-monotonically increasing values

2018-01-04 Thread Pavan Deolasee
On Thu, Jan 4, 2018 at 6:05 PM, Alvaro Herrera wrote: > Pavan Deolasee wrote: > > On Tue, Jan 2, 2018 at 7:15 PM, Tels > wrote: > > > > > Just a question trying to understand how btree indexes work: > > > > > > If one inserts ever-increasing value, is the tree a balanced tree with > a > > > mini

Re: Faster inserts with mostly-monotonically increasing values

2018-01-04 Thread Tels
Hello Alvaro, On Thu, January 4, 2018 7:35 am, Alvaro Herrera wrote: > Pavan Deolasee wrote: >> On Tue, Jan 2, 2018 at 7:15 PM, Tels >> wrote: >> >> > Just a question trying to understand how btree indexes work: >> > >> > If one inserts ever-increasing value, is the tree a balanced tree with >> a

Re: Faster inserts with mostly-monotonically increasing values

2018-01-04 Thread Alvaro Herrera
Pavan Deolasee wrote: > On Tue, Jan 2, 2018 at 7:15 PM, Tels wrote: > > > Just a question trying to understand how btree indexes work: > > > > If one inserts ever-increasing value, is the tree a balanced tree with a > > minimum (or at least not-as-high) number of levels, or does it increase in >

Re: Faster inserts with mostly-monotonically increasing values

2018-01-04 Thread Pavan Deolasee
On Tue, Jan 2, 2018 at 7:15 PM, Tels wrote: > Moin, > > > >> > >> > > Hmm Ok. I am not entirely sure whether it's the depth or just purely > > binary > > searching through 3-4 index pages and/or pinning/unpinning buffers result > > in much overhead. I will run some more tests and collect evidence

Re: Faster inserts with mostly-monotonically increasing values

2018-01-02 Thread Tels
Moin, On Tue, January 2, 2018 7:51 am, Pavan Deolasee wrote: > On Sun, Dec 31, 2017 at 4:36 PM, Peter Geoghegan wrote: > >> On Sun, Dec 31, 2017 at 6:44 AM, Pavan Deolasee >> wrote: >> > Here is a patch that implements the idea. If the last insert happens >> to >> be >> > in the rightmost block

Re: Faster inserts with mostly-monotonically increasing values

2018-01-02 Thread Pavan Deolasee
On Sun, Dec 31, 2017 at 4:36 PM, Peter Geoghegan wrote: > On Sun, Dec 31, 2017 at 6:44 AM, Pavan Deolasee > wrote: > > Here is a patch that implements the idea. If the last insert happens to > be > > in the rightmost block of an index, then we cache the block and check > that > > first for the n

Re: Faster inserts with mostly-monotonically increasing values

2017-12-31 Thread Andrey Borodin
Hi! > 31 дек. 2017 г., в 11:44, Pavan Deolasee > написал(а): > On a per-session basis, we cache the last heap block used for inserts and try > to use the same block for subsequent inserts. +1, from my POV this is good idea and it's cool that it already has implementation. I'd suggest to do not

Re: Faster inserts with mostly-monotonically increasing values

2017-12-31 Thread Peter Geoghegan
On Sun, Dec 31, 2017 at 6:44 AM, Pavan Deolasee wrote: > Here is a patch that implements the idea. If the last insert happens to be > in the rightmost block of an index, then we cache the block and check that > first for the next insert. For the cached block to be usable for the insert, > it shoul

Faster inserts with mostly-monotonically increasing values

2017-12-30 Thread Pavan Deolasee
Hello All, On a per-session basis, we cache the last heap block used for inserts and try to use the same block for subsequent inserts. We don't do that for indexes because the target block in the index is determined by the overall structure of the index and the index key being inserted and hence c