pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Michael Paquier <michael.paquier@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: xi@resolvent.net, PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13126: table constraint loses its comment
Date: Thu, 02 Jul 2015 15:28:53 +0300
Message-ID: <55952E85.30906@iki.fi> (raw)
In-Reply-To: <CAB7nPqRk+Y_agaYWtjyQtghGL_m8_PSER=d85E2yvhtY3sh0ug@mail.gmail.com>
References: <20150422154850.5198.26685@wrigleys.postgresql.org>
	<8519.1429995948@sss.pgh.pa.us>
	<CAB7nPqT5dzkfYBwaz-NnojU8-aQNGas1P=AQBa9n9hg8mjv+hg@mail.gmail.com>
	<CAB7nPqRk+Y_agaYWtjyQtghGL_m8_PSER=d85E2yvhtY3sh0ug@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 05/27/2015 04:10 PM, Michael Paquier wrote:
> On Wed, Apr 29, 2015 at 1:30 PM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> On Sun, Apr 26, 2015 at 6:05 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> xi@resolvent.net writes:
>>>> In some circumstances, the comment on a table constraint disappears.  Here
>>>> is an example:
>>>
>>> Hm, yeah.  The problem is that ATExecAlterColumnType() rebuilds all the
>>> affected indexes from scratch, and it isn't doing anything about copying
>>> their comments to the new objects (either comments on the constraints, or
>>> comments directly on the indexes).
>>>
>>> The least painful way to fix it might be to charter ATPostAlterTypeCleanup
>>> to create COMMENT commands and add those to the appropriate work queue,
>>> rather than complicating the data structure initially emitted by
>>> ATExecAlterColumnType.  But it'd still be a fair amount of new code I'm
>>> afraid.
>>>
>>> Not planning to fix this personally, but maybe someone else would like to
>>> take it up.
>>
>> In order to fix this, an idea would be to add a new routine in
>> ruleutils.c that generates the COMMENT query string, and then call it
>> directly from tablecmds.c. On master, I imagine that we could even add
>> some SQL interface if there is some need.
>> Thoughts?
>
> After looking at this problem, I noticed that the test case given
> above does not cover everything: primary key indexes, constraints
> (CHECK for example) and indexes alone have also their comments removed
> after ALTER TABLE when those objects are re-created. I finished with
> the patch attached to fix everything, patch that includes a set of
> regression tests covering all the code paths added.

The problem isn't limited to the cases where the old index is not 
reused. This still fails with your patch:

postgres=# create table t(id text primary key);CREATE TABLE
postgres=# comment on constraint t_pkey on t is 'the primary key of 
table "t"';COMMENT
postgres=# select d.description from pg_description d, pg_constraint c 
where d.classoid = 'pg_constraint'::regclass and c.conname = 't_pkey' 
and d.objoid = c.oid;
          description
------------------------------
  the primary key of table "t"
(1 row)

-- perform an ALTER TABLE that doesn't really do anything
postgres=# ALTER TABLE t ALTER COLUMN id SET DATA TYPE text;
ALTER TABLE

-- The comment is gone:
postgres=# select d.description from pg_description d, pg_constraint c 
where d.classoid = 'pg_constraint'::regclass and c.conname = 't_pkey' 
and d.objoid = c.oid;
  description
-------------
(0 rows)

- Heikki


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



view thread (15+ messages)  latest in thread

Message-ID: <55952E85.30906@iki.fi>
Permalink:  ../55952E85.30906@iki.fi/
Also on:    postgresql.org/message-id/55952E85.30906@iki.fi

 · 

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: hlinnaka@iki.fi, michael.paquier@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #13126: table constraint loses its comment
  In-Reply-To: <55952E85.30906@iki.fi>
  References: <20150422154850.5198.26685@wrigleys.postgresql.org> <8519.1429995948@sss.pgh.pa.us> <CAB7nPqT5dzkfYBwaz-NnojU8-aQNGas1P=AQBa9n9hg8mjv+hg@mail.gmail.com> <CAB7nPqRk+Y_agaYWtjyQtghGL_m8_PSER=d85E2yvhtY3sh0ug@mail.gmail.com> <55952E85.30906@iki.fi>

* 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