Re: BUG #6712: PostgreSQL 9.2 beta2: alter table drop constraint does not work on inherited master table

From: Noah Misch <noah(at)leadboat(dot)com>
To: Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
Cc: miroslav(dot)sulc(at)fordfrog(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6712: PostgreSQL 9.2 beta2: alter table drop constraint does not work on inherited master table
Date: 2012-07-15 21:23:44
Message-ID: 20120715212344.GA7475@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Jul 02, 2012 at 04:16:31PM +0530, Amit Kapila wrote:
> > From: pgsql-bugs-owner(at)postgresql(dot)org [mailto:pgsql-bugs-owner(at)postgresql(dot)org] On Behalf Of miroslav(dot)sulc(at)fordfrog(dot)com
> > Sent: Saturday, June 30, 2012 4:28 PM

> > test=# create table test_constraints (id int, val1 varchar, val2 int, unique
> > (val1, val2));
> > NOTICE: CREATE TABLE / UNIQUE will create implicit index
> > "test_constraints_val1_val2_key" for table "test_constraints"
> > CREATE TABLE
> > test=# create table test_constraints_inh () inherits (test_constraints);
> > CREATE TABLE
> > test=# alter table only test_constraints drop constraint
> > test_constraints_val1_val2_key;
> > ERROR: constraint "test_constraints_val1_val2_key" of relation
> > "test_constraints_inh" does not exist

> > postgresql tries to drop the constraint even from descendant table though
> > "only" is specified.

ONLY shouldn't be necessary, either.

> In function ATExecDropConstraint(), for the constarint "test_constraints_val1_val2_key" con->connoinherit is false,
> due to which it tries to drop the constrint from child table as well.
> I have checked that from function index_constraint_create() when it calls function CreateConstraintEntry(), the flag for noinherit passed is false.
> I think this is the reason of failure for the same.

Agreed. The other non-CHECK callers also get this wrong:

[local] regression=# select contype,connoinherit,count(*) from pg_constraint group by 1,2;
contype | connoinherit | count
---------+--------------+-------
p | f | 7
x | f | 2
c | f | 17
f | f | 5

One can construct similar bugs around dropping foreign key and exclusion
constraints. Though it may be irrelevant for command semantics, additionally
using connoinherit = 't' for contype = 't' (CONSTRAINT_TRIGGER) would
more-accurately represent the nature of those constraints.

Care to prepare a patch with a test case addition?

Thanks,
nm

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2012-07-15 21:45:28 Re: BUG #6733: All Tables Empty After pg_upgrade (PG 9.2.0 beta 2)
Previous Message Mike Wilson 2012-07-15 21:15:35 Re: BUG #6733: All Tables Empty After pg_upgrade (PG 9.2.0 beta 2)