pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgreSQL.org
Cc: jan.dirk.zijlstra@redwood.com
Cc: pgsql-bugs@postgreSQL.org
Subject: Re: [BUGS] BUG #13779: Inherited check constraint becomes non-inherited when related column is changed
Date: Fri, 20 Nov 2015 12:01:28 -0500
Message-ID: <31841.1448038888@sss.pgh.pa.us> (raw)
In-Reply-To: <20151119094126.2574.12966@wrigleys.postgresql.org>
References: <20151119094126.2574.12966@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

jan.dirk.zijlstra@redwood.com writes:
> [ ALTER COLUMN TYPE leaves inherited constraints in the wrong state ]

Yeah.  After perusing this I've become convinced that ALTER TABLE's
approach to rebuilding check constraints is fundamentally misguided.
Rather than using ALTER TABLE ONLY to reconstruct a check constraint
separately for each child table, we should apply a regular ALTER TABLE
ADD CONSTRAINT once at the parent table.

Annoyingly, we already tried to fix this area once in 5ed6546c, but
that was just doubling down on the wrong basic design.  The problem
is actually visible in the test case added by that commit, if it had
occurred to us to check the inheritance status columns:

regression=# select t.relname, c.conname, c.coninhcount, c.conislocal, c.connoinherit
from pg_constraint c, pg_class t where c.conname like 'test_inh_check%'
and c.conrelid = t.oid;
       relname        |        conname         | coninhcount | conislocal | connoinherit 
----------------------+------------------------+-------------+------------+--------------
 test_inh_check       | test_inh_check_a_check |           0 | t          | f
 test_inh_check_child | test_inh_check_a_check |           1 | f          | f
(2 rows)

regression=# ALTER TABLE test_inh_check ALTER COLUMN a TYPE numeric;
ALTER TABLE
regression=# select t.relname, c.conname, c.coninhcount, c.conislocal, c.connoinherit
from pg_constraint c, pg_class t where c.conname like 'test_inh_check%'
and c.conrelid = t.oid;
       relname        |        conname         | coninhcount | conislocal | connoinherit 
----------------------+------------------------+-------------+------------+--------------
 test_inh_check       | test_inh_check_a_check |           0 | t          | f
 test_inh_check_child | test_inh_check_a_check |           0 | t          | f
(2 rows)

Barring objections I'll go try to fix it by removing the "ONLY"
and then suppressing generation of new work queue entries
for inherited child constraints.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (2+ messages)

Message-ID: <31841.1448038888@sss.pgh.pa.us>
Permalink:  ../31841.1448038888@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/31841.1448038888@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-hackers@postgreSQL.org, jan.dirk.zijlstra@redwood.com
  Subject: Re: [BUGS] BUG #13779: Inherited check constraint becomes non-inherited when related column is changed
  In-Reply-To: <31841.1448038888@sss.pgh.pa.us>
  References: <20151119094126.2574.12966@wrigleys.postgresql.org> <31841.1448038888@sss.pgh.pa.us>

* 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