pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Disallow non-default collation in ADD PRIMARY KEY/UNIQUE USING I
Date: Fri, 06 Dec 2019 16:25:16 +0000
Message-ID: <E1idGPs-0000Rs-OA@gemulon.postgresql.org> (raw)

Disallow non-default collation in ADD PRIMARY KEY/UNIQUE USING INDEX.

When creating a uniqueness constraint using a pre-existing index,
we have always required that the index have the same properties you'd
get if you just let a new index get built.  However, when collations
were added, we forgot to add the index's collation to that check.

It's hard to trip over this without intentionally trying to break it:
you'd have to explicitly specify a different collation in CREATE
INDEX, then convert it to a pkey or unique constraint.  Still, if you
did that, pg_dump would emit a script that fails to reproduce the
index's collation.  The main practical problem is that after a
pg_upgrade the index would be corrupt, because its actual physical
order wouldn't match what pg_index says.  A more theoretical issue,
which is new as of v12, is that if you create the index with a
nondeterministic collation then it wouldn't be enforcing the normal
notion of uniqueness, causing the constraint to mean something
different from a normally-created constraint.

To fix, just add collation to the conditions checked for index
acceptability in ADD PRIMARY KEY/UNIQUE USING INDEX.  We won't try
to clean up after anybody who's already created such a situation;
it seems improbable enough to not be worth the effort involved.
(If you do get into trouble, a REINDEX should be enough to fix it.)

In principle this is a long-standing bug, but I chose not to
back-patch --- the odds of causing trouble seem about as great
as the odds of preventing it, and both risks are very low anyway.

Per report from Alexey Bashtanov, though this is not his preferred
fix.

Discussion: https://postgr.es/m/b05ce36a-cefb-ca5e-b386-a400535b1c0b@imap.cc

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fbbf68094c5ff3d513969d072126c92932e484da

Modified Files
--------------
src/backend/parser/parse_utilcmd.c         | 12 +++++++-----
src/test/regress/expected/create_index.out | 13 +++++++++++++
src/test/regress/sql/create_index.sql      |  6 ++++++
3 files changed, 26 insertions(+), 5 deletions(-)



Message-ID: <E1idGPs-0000Rs-OA@gemulon.postgresql.org>
Permalink:  ../E1idGPs-0000Rs-OA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1idGPs-0000Rs-OA@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: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Disallow non-default collation in ADD PRIMARY KEY/UNIQUE USING I
  In-Reply-To: <E1idGPs-0000Rs-OA@gemulon.postgresql.org>
  References: <E1idGPs-0000Rs-OA@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