Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAdbz-0006ni-2n for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Jul 2015 12:29:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZAdby-0003JJ-F7 for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Jul 2015 12:29:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZAdbw-0003Ii-OK for pgsql-bugs@postgresql.org; Thu, 02 Jul 2015 12:29:00 +0000 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZAdbt-000591-L0 for pgsql-bugs@postgresql.org; Thu, 02 Jul 2015 12:28:59 +0000 Received: by wgqq4 with SMTP id q4so61861324wgq.1 for ; Thu, 02 Jul 2015 05:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:reply-to:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=T2mQohwMxbgvZZaNO8IkuApsWEQGpJVOTrl5qHPRMYc=; b=rQOg/zOq3QyYEt4BfdFFKjc9ewssqcwg6rbTNiz8li+8znSGJsOEHtP3PTWG2ddZHF TfX8bO7xxN6BOdj6uoMMaCwrlUcPp6JEgjx9pCz4viegwxSPgTmkQ+h7fsM+TZp1j3bX vEUfc1hduP5ni7OMiyW72xuukyckh3FnenTAaw9h06R1Bmh5TCC8d9bm/T0fKl0XnWEJ /fcicOKtAthOl2f1ikUEAHklQvnhAEv8oQN4tSXoflbitd/sCuJPovRHkrbK/WTeWKLq noLgRGlGSAvZwX2rC2QJIvksQ/TDQQ8gNaxiW8dBM21hAAnIYvDPd7kGEyY+PpCLWZOY R27A== X-Received: by 10.194.82.167 with SMTP id j7mr58605552wjy.123.1435840135919; Thu, 02 Jul 2015 05:28:55 -0700 (PDT) Received: from [192.168.1.110] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by mx.google.com with ESMTPSA id e2sm7943631wjw.12.2015.07.02.05.28.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 05:28:55 -0700 (PDT) Message-ID: <55952E85.30906@iki.fi> Date: Thu, 02 Jul 2015 15:28:53 +0300 From: Heikki Linnakangas Reply-To: hlinnaka@iki.fi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: Michael Paquier , Tom Lane CC: xi@resolvent.net, PostgreSQL mailing lists Subject: Re: BUG #13126: table constraint loses its comment References: <20150422154850.5198.26685@wrigleys.postgresql.org> <8519.1429995948@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 05/27/2015 04:10 PM, Michael Paquier wrote: > On Wed, Apr 29, 2015 at 1:30 PM, Michael Paquier > wrote: >> On Sun, Apr 26, 2015 at 6:05 AM, Tom Lane 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