Re: BUG #15835: Errors altering data type of the column used in partial exclusion constraint
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: ladayaroslav@yandex.ru
Cc: pgsql-bugs@lists.postgresql.org
Date: 2019-06-11T23:08:33Z
Lists: pgsql-bugs
Attachments
- fix-bug-15835.patch (text/x-diff) patch
PG Bug reporting form <noreply@postgresql.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
Commits
-
Fix ALTER COLUMN TYPE failure with a partial exclusion constraint.
- f7e99de95654 9.5.18 landed
- 77d45b790e12 9.6.14 landed
- 2981e5a6126c 10.9 landed
- 0b6edb9fb3d2 11.4 landed
- e76de886157b 12.0 landed
- 9695ecf360af 9.4.23 landed
-
Fix ALTER/TYPE on columns referenced by FKs in partitioned tables
- 20bef2c3110a 12.0 cited