Re: BUG #15835: Errors altering data type of the column used in partial exclusion constraint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ladayaroslav(at)yandex(dot)ru
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15835: Errors altering data type of the column used in partial exclusion constraint
Date: 2019-06-11 23:08:33
Message-ID: 20307.1560294513@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Executing the below code:

> CREATE TABLE t(some_id int);
> ALTER TABLE t ADD EXCLUDE USING btree(some_id WITH =) WHERE (some_id IS NOT
> NULL);
> ALTER TABLE t ALTER COLUMN some_id TYPE bigint;

> Produces the following errors (per PostgreSQL version):
> 9.4.19, 9.5.15, 9.6.13: ERROR: could not open relation with OID 195837
> 10.8: ERROR: cache lookup failed for relation 630589
> 11.3, 12beta1: ERROR: relation "t_some_id_excl" already exists

Thanks for the report! The problem seems to be that ATExecAlterColumnType
doesn't consider the possibility that an index that needs to be rebuilt
might be a child of a constraint that needs to be rebuilt. We haven't
noticed this before because usually a constraint index doesn't have a
direct dependency on the table. But if there's a WHERE clause, then
dependency analysis of the WHERE clause results in direct dependencies
on the column(s) mentioned in WHERE.

In HEAD, we successfully drop both the index and the constraint, and
then try to rebuild both, and of course the second rebuild hits a
duplicate-index-name problem. Before v11, it fails even earlier than
that, because we first drop all the constraints and then drop all the
indexes. (Commit 20bef2c31 explains the change in behavior.)

The attached patch seems to fix it in HEAD. I'm pretty sure it will
fix the older branches too, but haven't tried to back-patch yet.

In passing, I cleaned up some obsolete comments in pg_depend.c,
and changed a "paranoia" test so that it won't break things so
badly if it fires.

regards, tom lane

Attachment Content-Type Size
fix-bug-15835.patch text/x-diff 7.4 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2019-06-12 02:36:56 Re: BUG #15833: defining a comment on a domain constraint fails with wrong OID
Previous Message PG Bug reporting form 2019-06-11 19:22:22 BUG #15846: problem with the pgdg repository for fedora-29