Re: Review of patch renaming constraints

Lists: pgsql-hackers
From: Joshua Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Review of patch renaming constraints
Date: 2012-01-13 04:43:38
Message-ID: 1216229788.2620.1326429818474.JavaMail.root@mail-1.01.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Compiling on Ubuntu 10.04 LTS AMD64 on a GoGrid virtual machine from 2012-01-12 git checkout.

Patch applied fine.

Docs are present, build, look good and are clear.

Changes to gram.y required Bison 2.5 to compile. Are we requiring Bison 2.5 now? There's no configure check for it, so it took me quite a while to figure out what was wrong.

Make check passed. Patch has tests for rename constraint.

Most normal uses of alter table ... rename constraint ... worked normally. However, the patch does not deal correctly with constraints which are not inherited, such as primary key constraints:

create table master ( category text not null, status int not null, value text );

alter table master add constraint master_key primary key ( category, status );

alter table master rename constraint master_key to master_primary_key;

create table partition_1 () inherits ( master );

create table partition_2 () inherits ( master );

alter table master rename constraint master_primary_key to master_key;

postgres=# alter table master rename constraint master_primary_key to master_key;
ERROR: constraint "master_primary_key" for table "partition_1" does not exist
STATEMENT: alter table master rename constraint master_primary_key to master_key;
ERROR: constraint "master_primary_key" for table "partition_1" does not exist

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com
San Francisco


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Joshua Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-01-19 19:04:46
Message-ID: 1326999886.19500.3.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2012-01-12 at 22:43 -0600, Joshua Berkus wrote:
> Compiling on Ubuntu 10.04 LTS AMD64 on a GoGrid virtual machine from 2012-01-12 git checkout.
>
> Patch applied fine.
>
> Docs are present, build, look good and are clear.
>
> Changes to gram.y required Bison 2.5 to compile. Are we requiring Bison 2.5 now? There's no configure check for it, so it took me quite a while to figure out what was wrong.

I can't reproduce that. I think there might be something wrong with
your installation. The same issue was reported for my COLLATION FOR
patch from the same environment.

> Make check passed. Patch has tests for rename constraint.
>
> Most normal uses of alter table ... rename constraint ... worked normally. However, the patch does not deal correctly with constraints which are not inherited, such as primary key constraints:

That appears to be because creating a primary key constraint does not
set pg_constraint.conisonly correctly. This was introduced recently
with noninherited check constraints.


From: Nikhil Sontakke <nikkhils(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Joshua Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-01-20 03:38:33
Message-ID: CANgU5ZcCv-v=LCivv6qL2aa2nZnVCEt7Afy2zLkET6k3RP++xQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> > Make check passed. Patch has tests for rename constraint.
> >
> > Most normal uses of alter table ... rename constraint ... worked
> normally. However, the patch does not deal correctly with constraints
> which are not inherited, such as primary key constraints:
>
> That appears to be because creating a primary key constraint does not
> set pg_constraint.conisonly correctly. This was introduced recently
> with noninherited check constraints.
>
>
> Umm, conisonly is set as false from primary key entries in pg_constraint.
And primary keys are anyways not inherited. So why is the conisonly field
interfering in rename? Seems quite orthogonal to me.

Regards,
Nikhils


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Nikhil Sontakke <nikkhils(at)gmail(dot)com>
Cc: Joshua Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-01-20 05:09:24
Message-ID: 1327036164.5983.3.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On fre, 2012-01-20 at 09:08 +0530, Nikhil Sontakke wrote:
> > Umm, conisonly is set as false from primary key entries in
> pg_constraint.
> And primary keys are anyways not inherited. So why is the conisonly
> field interfering in rename? Seems quite orthogonal to me.

In the past, each kind of constraint was either always inherited or
always not, implicitly. Now, for check constraints we can choose what
we want, and in the future, perhaps we will want to choose for primary
keys as well. So having conisonly is really a good step into that
future, and we should use it uniformly.


From: Nikhil Sontakke <nikkhils(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Joshua Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-01-20 06:02:25
Message-ID: CANgU5ZdyG-3wS13Xcea8m23E-v+mKxeJsrYFVAQVNxVdsr+KSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> > And primary keys are anyways not inherited. So why is the conisonly
> > field interfering in rename? Seems quite orthogonal to me.
>
> In the past, each kind of constraint was either always inherited or
> always not, implicitly. Now, for check constraints we can choose what
> we want, and in the future, perhaps we will want to choose for primary
> keys as well. So having conisonly is really a good step into that
> future, and we should use it uniformly.
>
>
Agreed. And right now primary key constraints are not marked as only making
them available for inheritance in the future. Or you prefer it otherwise?

Anyways, fail to see the direct connection between this and renaming. Might
have to look at this patch for that.

Regards,
Nikhils


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Nikhil Sontakke <nikkhils(at)gmail(dot)com>
Cc: Joshua Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-01-21 22:13:55
Message-ID: 1327184035.4482.15.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On fre, 2012-01-20 at 11:32 +0530, Nikhil Sontakke wrote:
> Agreed. And right now primary key constraints are not marked as only
> making them available for inheritance in the future. Or you prefer it
> otherwise?
>
> Anyways, fail to see the direct connection between this and renaming.
> Might have to look at this patch for that.

It checks conisonly to determine whether it needs to rename the
constraint in child tables as well. Since a primary has conisonly =
false, it goes to the child tables, but the constraint it not there.

In the past, we have treated this merely as an implementation artifact:
check constraints are inherited, primary key constraints are not. Now
we can choose for check constraints, with inherited being the default.
Having inheritable primary key constraints is a possible future feature.
So we need to think a littler harder now how to work that into the
existing logic. This also ties in with the other thread about having
this in CREATE TABLE syntax.


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Joshua Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-02-01 20:32:29
Message-ID: 1328128349.28270.18.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2012-01-12 at 22:43 -0600, Joshua Berkus wrote:
> Most normal uses of alter table ... rename constraint ... worked
> normally. However, the patch does not deal correctly with constraints
> which are not inherited, such as primary key constraints:

New patch which works around that issue.

Attachment Content-Type Size
rename-constraint.patch text/x-patch 15.7 KB

From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Joshua Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review of patch renaming constraints
Date: 2012-03-09 10:43:59
Message-ID: 87vcmeoxzk.fsf@hi-media-techno.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> On tor, 2012-01-12 at 22:43 -0600, Joshua Berkus wrote:
>> Most normal uses of alter table ... rename constraint ... worked
>> normally. However, the patch does not deal correctly with constraints
>> which are not inherited, such as primary key constraints:
>
> New patch which works around that issue.

I've been reviewing this new patch and it seems ready for commiter for
me: the code indeed looks like it's always been there, the corner cases
are covered in the added regression tests, including the one Josh ran
into problem with in the previous round of testing.

The regression test covering made me lazy enough not to retry the patch
here, I trust Peter on testing his own work here :)

I'll update my command trigger patch as soon as this one makes it in.

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support