Re: ENABLE/DISABLE CONSTRAINT NAME

Lists: pgsql-hackers
From: wangshuo(at)highgo(dot)com(dot)cn
To: <pgsql-hackers(at)postgresql(dot)org>
Cc: 卢健 <lujian(at)highgo(dot)com(dot)cn>
Subject: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-08-30 01:57:54
Message-ID: c6ee5854d5c182feb6b4eca7c256477a@highgo.com.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi hackers,

In order to achieve enable/disable constraint name,I made ​​a few
modifications to the code.

First, someone used to build the constraints while building
table. Then inserting data must follow a certain order.
And people usually like to insert the data but not affected by
foreign keys or check.

Second, the check or the foreign key constraint will waste much
time while inserting the data into the table.

Due to the above reasons,I realized this command.

I add a field named 'conenabled' to pg_constraint, identifying
whether a constraint is enable or not;
I enable or disable a foreign key constraint, by enable or
disable the triggers of the foreign key;
Our database will depend on the value of 'conenabled' to use the
check constrint or not;

I think the internal trigger's naming can be changed,and the
function ATExecValidateConstraint can be changed too,
but I think that together we can discuss, to decide what to do.

Now,we can do those:

Syntax:
alter table disable constraint <constraint_name> ;
alter table enable constraint <constraint_name> [ no valid ];
alter table add constraint table_constriant [ disable ];

CREATE TABLE aa
(
a1 INT CHECK(a1>4),
a2 INT
);
ALTER TABLE aa ADD CONSTRAINT aa_a2_check CHECK(a2>10) DISABLE;
INSERT INTO aa VALUES (10,1);
DELETE FROM aa;
ALTER TABLE aa DROP CONSTRAINT aa_a2_check;

ALTER TABLE aa DISABLE CONSTRAINT aa_a1_check;
INSERT INTO aa VALUES (5,2);
UPDATE aa SET a1=2 WHERE a2=2;
INSERT INTO aa VALUES (1,1);
ALTER TABLE aa ENABLE CONSTRAINT aa_a1_check NOT VALID; //don't
validate the data
DELETE FROM aa;
ALTER TABLE aa DISABLE CONSTRAINT aa_a1_check;
ALTER TABLE aa ENABLE CONSTRAINT aa_a1_check; //validate the data

CREATE TABLE bb
(
b1 INT PRIMARY KEY,
b2 INT
);
CREATE TABLE cc
(
c1 INT REFERENCES bb(b1),
c2 INT
);

ALTER TABLE cc DISABLE CONSTRAINT cc_c1_fkey;
INSERT INTO cc VALUES (1,1);
INSERT INTO bb VALUES (2,2);
INSERT INTO cc VALUES (2,2);
UPDATE cc SET c1=1 WHERE c2=2;
ALTER TABLE cc ENABLE CONSTRAINT cc_c1_fkey NOT VALID; //don't
validate the data
ALTER TABLE cc DISABLE CONSTRAINT cc_c1_fkey;
DELETE FROM cc;
ALTER TABLE cc ENABLE CONSTRAINT cc_c1_fkey; //validate the data

I packed a patch about this modification.This is my first time to send
the patch,
I hope you give me some advice.

Best Regards!

Yours,
Wang Shuo
HighGo Software Co.,Ltd.
August 26, 2013

Attachment Content-Type Size
constraint_enabledordisable.patch text/x-diff 42.7 KB

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: wangshuo(at)highgo(dot)com(dot)cn
Cc: pgsql-hackers(at)postgresql(dot)org, 卢健 <lujian(at)highgo(dot)com(dot)cn>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-02 22:42:57
Message-ID: 1378161777.21540.86.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, 2013-08-30 at 09:57 +0800, wangshuo(at)highgo(dot)com(dot)cn wrote:
> Hi hackers,
>
> In order to achieve enable/disable constraint name,I made ​​a few
> modifications to the code.
>
> First, someone used to build the constraints while building
> table. Then inserting data must follow a certain order.
> And people usually like to insert the data but not affected by
> foreign keys or check.

Is there any semantic difference between marking a constraint as
DISABLED and simply dropping it? Or does it just make it easier to
re-add it later?

Regards,
Jeff Davis


From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-03 00:15:24
Message-ID: 1378167324857-5769337.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jeff Davis-8 wrote
> Is there any semantic difference between marking a constraint as
> DISABLED and simply dropping it? Or does it just make it easier to
> re-add it later?

I cannot answer the question but if there is none then the main concern I'd
have is capturing "meta-information" about WHY such a constraint has been
disabled instead of dropped.

I guess this whole feature extends from the trigger disable feature that
already exists. Given we have the one adding this seems symmetrical...

I cannot really see using either feature on a production system (if
following best practices) but I can imagine where they could both be helpful
during development. Note with this usage pattern the meta-information about
"why" becomes considerably less important.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/ENABLE-DISABLE-CONSTRAINT-NAME-tp5769136p5769337.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


From: wangshuo(at)highgo(dot)com(dot)cn
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-03 07:13:18
Message-ID: 69d69a640cea999cda555acc120b508d@highgo.com.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

于 2013-09-03 08:15, David Johnston 回复:
> Jeff Davis-8 wrote
>> Is there any semantic difference between marking a constraint as
>> DISABLED and simply dropping it? Or does it just make it easier to
>> re-add it later?
>
David Johnston wrote:
> I cannot answer the question but if there is none then the main
> concern I'd
> have is capturing "meta-information" about WHY such a constraint has
> been
> disabled instead of dropped.

Drop/build and disable/enable constraint has no fundamental difference,
and could achieve the same purpose.What I do also more convenient for
the user.
Recording the disabled constraints is easier than recoding all the
constrains.
What's more, a lot of people ever asked about turing off constraint and
The sql2008 support this.So I think it's necessary in some ways.

> I guess this whole feature extends from the trigger disable feature
> that
> already exists. Given we have the one adding this seems
> symmetrical...
>
> I cannot really see using either feature on a production system (if
> following best practices) but I can imagine where they could both be
> helpful
> during development. Note with this usage pattern the
> meta-information about
> "why" becomes considerably less important.
>
> David J.

Wang Shuo
HighGo Software Co.,Ltd.
September 3, 2013


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: wangshuo(at)highgo(dot)com(dot)cn
Cc: David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-04 17:56:04
Message-ID: CA+TgmobXBqLS4qCDKL3OpWopuPyKNuc7g7j1Bck9hS3xZus26A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 3, 2013 at 3:13 AM, <wangshuo(at)highgo(dot)com(dot)cn> wrote:
> 于 2013-09-03 08:15, David Johnston 回复:
>
>> Jeff Davis-8 wrote
>>>
>>> Is there any semantic difference between marking a constraint as
>>> DISABLED and simply dropping it? Or does it just make it easier to
>>> re-add it later?
>>
>>
> David Johnston wrote:
>>
>> I cannot answer the question but if there is none then the main concern
>> I'd
>> have is capturing "meta-information" about WHY such a constraint has been
>> disabled instead of dropped.
>
>
> Drop/build and disable/enable constraint has no fundamental difference,
> and could achieve the same purpose.What I do also more convenient for the
> user.
> Recording the disabled constraints is easier than recoding all the
> constrains.
> What's more, a lot of people ever asked about turing off constraint and
> The sql2008 support this.So I think it's necessary in some ways.

Please add your patch to the upcoming CommitFest so we don't forget about it.

https://commitfest.postgresql.org/action/commitfest_view/open

Please see also https://wiki.postgresql.org/wiki/Submitting_a_Patch

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: wangshuo(at)highgo(dot)com(dot)cn
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-05 03:27:08
Message-ID: 4212a401b6014356540ac842546edd68@highgo.com.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

于 2013-09-05 01:56, Robert Haas 回复:
> On Tue, Sep 3, 2013 at 3:13 AM, <wangshuo(at)highgo(dot)com(dot)cn> wrote:
>> 于 2013-09-03 08:15, David Johnston 回复:
>>
>>> Jeff Davis-8 wrote
>>>>
>>>> Is there any semantic difference between marking a constraint as
>>>> DISABLED and simply dropping it? Or does it just make it easier to
>>>> re-add it later?
>>>
>>>
>> David Johnston wrote:
>>>
>>> I cannot answer the question but if there is none then the main
>>> concern
>>> I'd
>>> have is capturing "meta-information" about WHY such a constraint
>>> has been
>>> disabled instead of dropped.
>>
>>
>> Drop/build and disable/enable constraint has no fundamental
>> difference,
>> and could achieve the same purpose.What I do also more convenient
>> for the
>> user.
>> Recording the disabled constraints is easier than recoding all the
>> constrains.
>> What's more, a lot of people ever asked about turing off constraint
>> and
>> The sql2008 support this.So I think it's necessary in some ways.
>
> Please add your patch to the upcoming CommitFest so we don't forget
> about it.
>
> https://commitfest.postgresql.org/action/commitfest_view/open
>
> Please see also https://wiki.postgresql.org/wiki/Submitting_a_Patch
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company

I had committed the patch to the Server Features
(https://commitfest.postgresql.org/action/commitfest_view/open).
Is this right ? If not, please give me more advice,thanks !

Wang Shuo
HighGo Software Co.,Ltd.
September 5, 2013


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: wangshuo(at)highgo(dot)com(dot)cn
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-07 11:45:58
Message-ID: CAB7nPqTZSc0Ay0CPSbMd9jL7PukBk-_-0vAr1AARBXQwEQ2ZWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 5, 2013 at 12:27 PM, <wangshuo(at)highgo(dot)com(dot)cn> wrote:
> I had committed the patch to the Server Features
> (https://commitfest.postgresql.org/action/commitfest_view/open).
> Is this right ? If not, please give me more advice,thanks !
Yes this category is fine don't worry.
--
Michael


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: wangshuo(at)highgo(dot)com(dot)cn
Cc: David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-09 12:54:32
Message-ID: 522DC508.1000509@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 9/3/13 3:13 AM, wangshuo(at)highgo(dot)com(dot)cn wrote:
> Drop/build and disable/enable constraint has no fundamental difference,
> and could achieve the same purpose.What I do also more convenient for
> the user.
> Recording the disabled constraints is easier than recoding all the
> constrains.

Note that other schema objects can depend on the existence of
constraints. For example, the validity of a view might depend on the
existence of a primary key constraint. What would you do with the view
if the primary key constraint is temporarily disabled?

> What's more, a lot of people ever asked about turing off constraint and
> The sql2008 support this.So I think it's necessary in some ways.

I don't see this in the SQL standard. There is [NOT] ENFORCED, but
that's something different. Implementing that instead might actually
address the above concern.


From: wangshuo(at)highgo(dot)com(dot)cn
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-11 05:09:12
Message-ID: 6959ea807ca0c9b5f774c4573e231352@highgo.com.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

于 2013-09-09 20:54, Peter Eisentraut 回复:
> On 9/3/13 3:13 AM, wangshuo(at)highgo(dot)com(dot)cn wrote:
>> Drop/build and disable/enable constraint has no fundamental
>> difference,
>> and could achieve the same purpose.What I do also more convenient
>> for
>> the user.
>> Recording the disabled constraints is easier than recoding all the
>> constrains.
>

Peter Eisentraut wrote:
> Note that other schema objects can depend on the existence of
> constraints. For example, the validity of a view might depend on the
> existence of a primary key constraint. What would you do with the
> view
> if the primary key constraint is temporarily disabled?
>

Thanks for your reply.
I could't clearly understand your opinion, could you give me more
information or example?

>> What's more, a lot of people ever asked about turing off constraint
>> and
>> The sql2008 support this.So I think it's necessary in some ways.
>
> I don't see this in the SQL standard. There is [NOT] ENFORCED, but
> that's something different. Implementing that instead might actually
> address the above concern.

You are right. I had checked the SQL standard. There is not
ENABLE/DISABLE.
Sorry.
I misunderstood the former discussion about the constraint and the SQL
standard.
Thanks ,again.

Wang Shuo
HighGo Software Co.,Ltd.
September 11, 2013


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: wangshuo(at)highgo(dot)com(dot)cn
Cc: David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-12 21:23:49
Message-ID: 523230E5.9050708@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 9/11/13 1:09 AM, wangshuo(at)highgo(dot)com(dot)cn wrote:
> Peter Eisentraut wrote:
>> Note that other schema objects can depend on the existence of
>> constraints. For example, the validity of a view might depend on the
>> existence of a primary key constraint. What would you do with the view
>> if the primary key constraint is temporarily disabled?
>>
>
> Thanks for your reply.
> I could't clearly understand your opinion, could you give me more
> information or example?

=> create table test1 (a int constraint pk primary key, b text);
=> create view test2 as select a, b from test1 group by a;
=> alter table test1 drop constraint pk;
ERROR: 2BP01: cannot drop constraint pk on table test1 because other
objects depend on it
DETAIL: view test2 depends on constraint pk on table test1
HINT: Use DROP ... CASCADE to drop the dependent objects too.

(This has to do with whether ungrouped columns are allowed in the select
list when the presence of constraints ensures well-defined results.)

When trying to drop the constraint, the choice is to abort the drop or
to drop dependent objects. When you are talking about
enabling/disabling the constraint, it's not clear what to do.


From: wangshuo(at)highgo(dot)com(dot)cn
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-13 02:03:44
Message-ID: 641404c1a796c784742201c72e1273e2@highgo.com.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 09/13/2013 05:23, Peter Eisentraut wrote:
> => create table test1 (a int constraint pk primary key, b text);
> => create view test2 as select a, b from test1 group by a;
> => alter table test1 drop constraint pk;
> ERROR: 2BP01: cannot drop constraint pk on table test1 because other
> objects depend on it
> DETAIL: view test2 depends on constraint pk on table test1
> HINT: Use DROP ... CASCADE to drop the dependent objects too.
>
> (This has to do with whether ungrouped columns are allowed in the
> select
> list when the presence of constraints ensures well-defined results.)
>
> When trying to drop the constraint, the choice is to abort the drop
> or
> to drop dependent objects. When you are talking about
> enabling/disabling the constraint, it's not clear what to do.

Thanks for your reply.
First, I had said that I I only made ​​a few modifications to the check
and the
foreign key constraint, and did nothing with primary key constraint.

On 08/30/2013 02:03 PM, I wrote:
>Due to the above reasons,I realized this command.
>
>I add a field named 'conenabled' to pg_constraint, identifying whether
> a constraint is enable or not;
>I enable or disable a foreign key constraint, by enable or disable the
> triggers of the foreign key;
>Our database will depend on the value of 'conenabled' to use the check
> constrint or not;

In the alter_table.sgml, I wrote:
>This form enables or disables a foreign key or check constraint.

Second, I tested the check and the foreign key constraint as your test
above.
And no error found, as fellow:

postgres=# create table a1 (a1 int check(a1>4));
CREATE TABLE
postgres=# create view a11 as select * from a1;
CREATE VIEW
postgres=# alter table a1 disable constraint a1_a1_check;
ALTER TABLE
postgres=# insert into a1 values (3);
INSERT 0 1
postgres=# select * from a11;
a1
----
3
(1 row)

postgres=# alter table a1 drop constraint a1_a1_check;
ALTER TABLE

postgres=# create table bb(b1 int primary key);
CREATE TABLE
postgres=# create table cc(c1 int references bb(b1));
CREATE TABLE
postgres=# create view c11 as select * from cc;
CREATE VIEW
postgres=# alter table cc disable constraint cc_c1_fkey;
ALTER TABLE
postgres=# insert into cc values (1);
INSERT 0 1
postgres=# select * from c11;
c1
----
1
(1 row)

postgres=# alter table cc drop constraint cc_c1_fkey;
ALTER TABLE

Wang Shuo
HighGo Software Co.,Ltd.
September 13, 2013


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: wangshuo(at)highgo(dot)com(dot)cn
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-14 00:17:19
Message-ID: CA+TgmoabJW1D3+xxXkeqH43DKyqPzqk9V4bB0im8wRO09zroLg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 12, 2013 at 10:03 PM, <wangshuo(at)highgo(dot)com(dot)cn> wrote:
> Second, I tested the check and the foreign key constraint as your test
> above.
> And no error found, as fellow:

You're missing the point. Peter wasn't worried that your patch throws
an error; he's concerned about the fact that it doesn't.

In PostgreSQL, you can only create the following view because test1
has a primary key over column a:

=> create table test1 (a int constraint pk primary key, b text);
=> create view test2 as select a, b from test1 group by a;
=> alter table test1 drop constraint pk;

The reason that, if the primary key weren't there, it would be
ambiguous which row should be returned as among multiple values where
a is equal and b is not. If you can disable the constraint, then you
can create precisely that problem.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bernd Helmle <mailings(at)oopsware(dot)de>
To: Robert Haas <robertmhaas(at)gmail(dot)com>, wangshuo(at)highgo(dot)com(dot)cn
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-24 09:58:25
Message-ID: BB11006AFB4CF43C55C89345@apophis.credativ.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

--On 13. September 2013 20:17:19 -0400 Robert Haas <robertmhaas(at)gmail(dot)com>
wrote:

> You're missing the point. Peter wasn't worried that your patch throws
> an error; he's concerned about the fact that it doesn't.
>
> In PostgreSQL, you can only create the following view because test1
> has a primary key over column a:
>
> => create table test1 (a int constraint pk primary key, b text);
> => create view test2 as select a, b from test1 group by a;
> => alter table test1 drop constraint pk;
>
> The reason that, if the primary key weren't there, it would be
> ambiguous which row should be returned as among multiple values where
> a is equal and b is not. If you can disable the constraint, then you
> can create precisely that problem.

Hmm not sure i understand this argument either: this patch doesn't allow
disabling a primary key. It only supports FKs and CHECK constraints
explicitly.

--
Thanks

Bernd


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: wangshuo(at)highgo(dot)com(dot)cn, Peter Eisentraut <peter_e(at)gmx(dot)net>, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-24 14:38:55
Message-ID: CA+TgmoY0EV6SG3kKHdcBbG7qm7m7ebYA8UeJZiLRhamuSufFsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 24, 2013 at 5:58 AM, Bernd Helmle <mailings(at)oopsware(dot)de> wrote:
> --On 13. September 2013 20:17:19 -0400 Robert Haas <robertmhaas(at)gmail(dot)com>
> wrote:
>> You're missing the point. Peter wasn't worried that your patch throws
>> an error; he's concerned about the fact that it doesn't.
>>
>> In PostgreSQL, you can only create the following view because test1
>> has a primary key over column a:
>>
>> => create table test1 (a int constraint pk primary key, b text);
>> => create view test2 as select a, b from test1 group by a;
>> => alter table test1 drop constraint pk;
>>
>> The reason that, if the primary key weren't there, it would be
>> ambiguous which row should be returned as among multiple values where
>> a is equal and b is not. If you can disable the constraint, then you
>> can create precisely that problem.
>
> Hmm not sure i understand this argument either: this patch doesn't allow
> disabling a primary key. It only supports FKs and CHECK constraints
> explicitly.

Well, that is certainly one way of skating around the specific concern
Peter raised.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, wangshuo(at)highgo(dot)com(dot)cn, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-09-25 02:40:58
Message-ID: 1380076858.1440.23.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, 2013-09-24 at 11:58 +0200, Bernd Helmle wrote:
> Hmm not sure i understand this argument either: this patch doesn't
> allow disabling a primary key. It only supports FKs and CHECK
> constraints explicitly.

Well, as soon as the patch for cataloging not-null constraints as check
constraints is available, it will be possible to create views that
depend functionally on check constraints. Then you'll have the same
problem there.

It's also not clear why this patch only supports foreign keys and check
constraints. Maybe that's what was convenient to implement, but it's
not a principled solution to the general issue that constraints can be
involved in dependencies.


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Bernd Helmle <mailings(at)oopsware(dot)de>, wangshuo(at)highgo(dot)com(dot)cn, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-10-09 18:10:42
Message-ID: CA+TgmobOJSLHxN9fCzwK-eF0XneXPAoNGMKPEWmDmY2qL53TwQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 24, 2013 at 10:40 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> On Tue, 2013-09-24 at 11:58 +0200, Bernd Helmle wrote:
>> Hmm not sure i understand this argument either: this patch doesn't
>> allow disabling a primary key. It only supports FKs and CHECK
>> constraints explicitly.
>
> Well, as soon as the patch for cataloging not-null constraints as check
> constraints is available, it will be possible to create views that
> depend functionally on check constraints. Then you'll have the same
> problem there.
>
> It's also not clear why this patch only supports foreign keys and check
> constraints. Maybe that's what was convenient to implement, but it's
> not a principled solution to the general issue that constraints can be
> involved in dependencies.

I agree with these concerns, as well as those raised by Tom Lane and
Fabien COELHO, and I think they indicate that we shouldn't accept this
patch. So I'm marking this as Rejected.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Jim Nasby <jim(at)nasby(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Bernd Helmle <mailings(at)oopsware(dot)de>, wangshuo(at)highgo(dot)com(dot)cn, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-10-10 22:48:47
Message-ID: 52572ECF.8030709@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 10/9/13 1:10 PM, Robert Haas wrote:
> On Tue, Sep 24, 2013 at 10:40 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>> On Tue, 2013-09-24 at 11:58 +0200, Bernd Helmle wrote:
>>> Hmm not sure i understand this argument either: this patch doesn't
>>> allow disabling a primary key. It only supports FKs and CHECK
>>> constraints explicitly.
>>
>> Well, as soon as the patch for cataloging not-null constraints as check
>> constraints is available, it will be possible to create views that
>> depend functionally on check constraints. Then you'll have the same
>> problem there.
>>
>> It's also not clear why this patch only supports foreign keys and check
>> constraints. Maybe that's what was convenient to implement, but it's
>> not a principled solution to the general issue that constraints can be
>> involved in dependencies.
>
> I agree with these concerns, as well as those raised by Tom Lane and
> Fabien COELHO, and I think they indicate that we shouldn't accept this
> patch. So I'm marking this as Rejected.

I see a use case for disabling FKs and CHECKS but not PKs or UNIQUE constraints: FKs and CHECKS don't depend on additional state information (namely an index), so it's easy to just disable them temporarily and then re-enable them. The same isn't true about a PK or UNIQUE constraint.

Of course we could decide to do something more complex to handle disabling PK/UNIQUE... though at that point it'd be better to just allow temporarily disabling any index. But I think there's an argument to be made for that being beyond the scope of disabling "simple" constraints... it's a pretty high bar to set that we won't accept a patch that disables simple constraints but not those involving indexes.
--
Jim C. Nasby, Data Architect jim(at)nasby(dot)net
512.569.9461 (cell) http://jim.nasby.net


From: wangshuo(at)highgo(dot)com(dot)cn
To: Robert Haas <robertmhaas(at)gmail(dot)com>, Jim Nasby <jim(at)nasby(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Bernd Helmle <mailings(at)oopsware(dot)de>, David Johnston <polobo(at)yahoo(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: ENABLE/DISABLE CONSTRAINT NAME
Date: 2013-10-11 01:44:20
Message-ID: 3f7951c11d3fa4685a32b0ed89c5025d@highgo.com.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2013-10-10 02:10, Robert Haas wrote:

> I agree with these concerns, as well as those raised by Tom Lane and
> Fabien COELHO, and I think they indicate that we shouldn't accept
> this
> patch. So I'm marking this as Rejected.

On 2013-10-11 06:48, Jim Nasby wrote:

>I see a use case for disabling FKs and CHECKS but not PKs or UNIQUE
> constraints: FKs and CHECKS don't depend on additional state
> information (namely an index), so >it's easy to just disable them
> temporarily and then re-enable them. The same isn't true about a PK or
> UNIQUE constraint.
>
>Of course we could decide to do something more complex to handle
> disabling PK/UNIQUE... though at that point it'd be better to just
> allow temporarily disabling >any index. But I think there's an argument
> to be made for that being beyond the scope of disabling "simple"
> constraints... it's a pretty high bar to set that we ?>won't accept a
> patch that disables simple constraints but not those involving indexes.

Thanks for your reply.
I found my patch's weakness.I think the DISABLE/ENABLE patch is
necessary.
I will pack a new patch for all the constraints to commit.
Thanks again.

Yours,
Wang Shuo
HighGo Software Co.,Ltd.
October 11, 2013