pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Make identity sequence management more robust
Date: Mon, 22 Jul 2019 10:16:23 +0000
Message-ID: <E1hpVMl-0003P8-8p@gemulon.postgresql.org> (raw)

Make identity sequence management more robust

Some code could get confused when certain catalog state involving both
identity and serial sequences was present, perhaps during an attempt
to upgrade the latter to the former.  Specifically, dropping the
default of a serial column maintains the ownership of the sequence by
the column, and so it would then be possible to afterwards make the
column an identity column that would now own two sequences.  This
causes the code that looks up the identity sequence to error out,
making the new identity column inoperable until the ownership of the
previous sequence is released.

To fix this, make the identity sequence lookup only consider sequences
with the appropriate dependency type for an identity sequence, so it
only ever finds one (unless something else is broken).  In the above
example, the old serial sequence would then be ignored.  Reorganize
the various owned-sequence-lookup functions a bit to make this
clearer.

Reported-by: Laurenz Albe <laurenz.albe@cybertec.at>
Discussion: https://www.postgresql.org/message-id/flat/470c54fc8590be4de0f41b0d295fd6390d5e8a6c.camel@cybertec.a...

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/19781729f789f3c6b2540e02b96f8aa500460322

Modified Files
--------------
src/backend/catalog/pg_depend.c        | 33 +++++++++++++++++++++++++--------
src/backend/commands/tablecmds.c       |  4 ++--
src/backend/parser/parse_utilcmd.c     | 12 +++++-------
src/backend/rewrite/rewriteHandler.c   |  2 +-
src/include/catalog/dependency.h       |  4 ++--
src/test/regress/expected/identity.out |  5 +++++
src/test/regress/sql/identity.sql      |  8 ++++++++
7 files changed, 48 insertions(+), 20 deletions(-)



Message-ID: <E1hpVMl-0003P8-8p@gemulon.postgresql.org>
Permalink:  ../E1hpVMl-0003P8-8p@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hpVMl-0003P8-8p@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: peter@eisentraut.org
  Subject: Re: pgsql: Make identity sequence management more robust
  In-Reply-To: <E1hpVMl-0003P8-8p@gemulon.postgresql.org>
  References: <E1hpVMl-0003P8-8p@gemulon.postgresql.org>

* 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