pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org, Noah Misch <noah@leadboat.com>
Cc: Jason Petersen <jason@citusdata.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: [HACKERS] Concurrent ALTER SEQUENCE RESTART Regression
Date: Thu, 11 May 2017 17:21:18 -0400
Message-ID: <8863.1494537678@sss.pgh.pa.us> (raw)
In-Reply-To: <90255529-1de1-0aad-c545-f75d08479a9a@2ndquadrant.com>
References: <20170427062304.gxh3rczhh6vblrwh@alap3.anarazel.de>
	<CAB7nPqTYQ+GZ9jP7FNHbTa+J5Z1k3ZmBrxvAhtOvpkH3k9j42g@mail.gmail.com>
	<E77D2275-DA45-4F43-B00D-A9B113DFA9FB@anarazel.de>
	<CAB7nPqQ=yHXxiWU2FuaC13L_5y7UG7R_OkJhWQbXYMJPXCDtNg@mail.gmail.com>
	<20170430080517.GA811193@rfd.leadboat.com>
	<59aeb834-b113-6769-bfe4-65f2f8c875e3@2ndquadrant.com>
	<20170507234334.yimkp6aq2o43wtt2@alap3.anarazel.de>
	<4521f870-bb1f-1b29-3b3f-42419696efe7@2ndquadrant.com>
	<20d59e42-4a08-fa34-29df-9f54b3ef5ba7@2ndquadrant.com>
	<2913.1494426542@sss.pgh.pa.us>
	<20170510162450.bzfktkeexezepf6c@alap3.anarazel.de>
	<90255529-1de1-0aad-c545-f75d08479a9a@2ndquadrant.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> I ran this script

> CREATE SEQUENCE seq1;

> DO LANGUAGE plpythonu $$
> plan = plpy.prepare("SELECT nextval('seq1')")
> for i in range(0, 10000000):
>     plpy.execute(plan)
> $$;

> and timed the "DO".

It occurred to me that plpy.execute is going to run a subtransaction for
each call, which makes this kind of a dubious test case, both because of
the extra subtransaction overhead and because subtransaction lock
ownership effects will possibly skew the results.  So I tried to
reproduce the test using plain plpgsql,

CREATE SEQUENCE IF NOT EXISTS seq1;

\timing on

do $$
declare x int;
begin
  for i in 0 .. 10000000 loop
    x := nextval('seq1');
  end loop;
end
$$;

On HEAD, building without cassert, I got a fairly reproducible result
of about 10.6 seconds.  I doubt my machine is 6X faster than yours,
so this indicates that the subtransaction overhead is pretty real.

> I compared the stock releases with a patched version that replaces the
> body of open_share_lock() with just
>     return relation_open(seq->relid, AccessShareLock);

Hm.  I don't think that's a sufficient code change, because if you do it
like that then the lock remains held after nextval() returns.  This means
that (a) subsequent calls aren't hitting the shared lock manager at all,
they're just incrementing a local lock counter, and whether it would be
fastpath or not is irrelevant; and (b) this means that the semantic issues
Andres is worried about remain in place, because we will hold the lock
till transaction end.

I experimented with something similar, just replacing open_share_lock
as above, and I got runtimes of just about 12 seconds, which surprised
me a bit.  I'd have thought the locallock-already-exists code path
would be faster than that.

I then further changed the code so that nextval_internal ends with
"relation_close(seqrel, AccessShareLock);" rather than NoLock,
so that the lock is actually released between calls.  This boosted
the runtime up to 15.5 seconds, or a 50% penalty over HEAD.

My conclusion is that in low-overhead cases, such as using a sequence
to assign default values during COPY IN, the percentage overhead from
acquiring and releasing the lock could be pretty dire.  Still, we might
not have much choice if we want nice semantics.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (84+ messages)  latest in thread

Message-ID: <8863.1494537678@sss.pgh.pa.us>
Permalink:  ../8863.1494537678@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/8863.1494537678@sss.pgh.pa.us

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, peter.eisentraut@2ndquadrant.com, andres@anarazel.de, petr.jelinek@2ndquadrant.com, noah@leadboat.com, jason@citusdata.com, michael.paquier@gmail.com
  Subject: Re: [HACKERS] Concurrent ALTER SEQUENCE RESTART Regression
  In-Reply-To: <8863.1494537678@sss.pgh.pa.us>
  References: <20170427062304.gxh3rczhh6vblrwh@alap3.anarazel.de> <CAB7nPqTYQ+GZ9jP7FNHbTa+J5Z1k3ZmBrxvAhtOvpkH3k9j42g@mail.gmail.com> <E77D2275-DA45-4F43-B00D-A9B113DFA9FB@anarazel.de> <CAB7nPqQ=yHXxiWU2FuaC13L_5y7UG7R_OkJhWQbXYMJPXCDtNg@mail.gmail.com> <20170430080517.GA811193@rfd.leadboat.com> <59aeb834-b113-6769-bfe4-65f2f8c875e3@2ndquadrant.com> <20170507234334.yimkp6aq2o43wtt2@alap3.anarazel.de> <4521f870-bb1f-1b29-3b3f-42419696efe7@2ndquadrant.com> <20d59e42-4a08-fa34-29df-9f54b3ef5ba7@2ndquadrant.com> <2913.1494426542@sss.pgh.pa.us> <20170510162450.bzfktkeexezepf6c@alap3.anarazel.de> <90255529-1de1-0aad-c545-f75d08479a9a@2ndquadrant.com> <8863.1494537678@sss.pgh.pa.us>

* 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