Unix Technical Forum

Re: [PATCHES] Inherited Constraints

This is a discussion on Re: [PATCHES] Inherited Constraints within the pgsql Hackers forums, part of the PostgreSQL category; --> On Wed, 2005-12-07 at 21:24 +0000, Simon Riggs wrote: > Following patch implements record of whether a constraint is ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 08:14 AM
Simon Riggs
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

On Wed, 2005-12-07 at 21:24 +0000, Simon Riggs wrote:
> Following patch implements record of whether a constraint is inherited
> or not, and prevents dropping of inherited constraints.


Patch posted to -patches list.

> What it doesn't do:
> It doesn't yet prevent dropping the parent constraint, which is wrong,
> clearly, but what to do about it?
> 1. make dropping a constraint drop all constraints dependent upon it
> (without any explicit cascade)
> 2. add a new clause to ALTER TABLE .... DROP CONSTRAINT .... CASCADE
>
> I prefer (1), since it is SQL Standard compliant, easier to remember and
> automatic de-inheritance is the natural opposite of the automatic
> inheritance process.


Comments, please -hackers?

Which implementation should I pick (or another)?

> Further patch will utilise this new knowledge to reduce the number of
> tests made during constraint_exclusion.


Best Regards, Simon Riggs


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 08:14 AM
Hannu Krosing
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

Ühel kenal päeval, N, 2005-12-08 kell 11:10, kirjutas Simon Riggs:
> On Wed, 2005-12-07 at 21:24 +0000, Simon Riggs wrote:
> > Following patch implements record of whether a constraint is inherited
> > or not, and prevents dropping of inherited constraints.

>
> Patch posted to -patches list.
>
> > What it doesn't do:
> > It doesn't yet prevent dropping the parent constraint, which is wrong,
> > clearly, but what to do about it?
> > 1. make dropping a constraint drop all constraints dependent upon it
> > (without any explicit cascade)
> > 2. add a new clause to ALTER TABLE .... DROP CONSTRAINT .... CASCADE
> >
> > I prefer (1), since it is SQL Standard compliant, easier to remember and
> > automatic de-inheritance is the natural opposite of the automatic
> > inheritance process.

>
> Comments, please -hackers?


It would be logical to do the same as DROP TABLE does, i.e (2).

hannu=# create table parent(i int);
CREATE TABLE
hannu=# create table child() inherits(parent);
CREATE TABLE
hannu=# drop table parent;
NOTICE: table child depends on table parent
ERROR: cannot drop table parent because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too.
hannu=#

Maybe there should be another option in addition to CASCADE, say
DISINHERIT, which leaves all child constraints as heads of new
ingeritance hierarchies. DROP CASCADE + ADD BACK ALL CHILD CONSTRAINTS
may be prohibitively expensive for biggish tables.

Another nice (but no doubt more complex) thing would be ability to add
multiple constraints at once, needing only one seqscan to check for
compliance with added constraints and/or making constraint checks
smarter, so that for.ex. "ADD CONSTRAINT CHECK i > 0" could make use of
index on i instead of doing a seqscan. Or if there is a constraint
"CHECK i > 0" then adding another like "CHECK i > -1" would not need to
check actual data either.

> Which implementation should I pick (or another)?
>
> > Further patch will utilise this new knowledge to reduce the number of
> > tests made during constraint_exclusion.


So will hierarchical inheritance be the thing to do to take advantage of
i then ?

year
+- month1
|+-day1
|+-day2
......
|\-day31
+- month2

etc.

btw, will your DROP patch support multiple inheritance ?

-----------
Hannu



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 08:14 AM
Rod Taylor
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

> Another nice (but no doubt more complex) thing would be ability to add
> multiple constraints at once, needing only one seqscan to check for
> compliance with added constraints and/or making constraint checks
> smarter, so that for.ex. "ADD CONSTRAINT CHECK i > 0" could make use of
> index on i instead of doing a seqscan. Or if there is a constraint
> "CHECK i > 0" then adding another like "CHECK i > -1" would not need to
> check actual data either.


Check out the comma in alter table.

ALTER TABLE tab ADD COLUMN serial NOT NULL UNIQUE,
ADD CHECK (foo > 24),
ADD CHECK (baz < 18),
ADD COLUMN integer NOT NULL DEFAULT 32;

Table tab (and each of the tables that inherits from it) is scanned and
rewritten once.

I believe this was added for 8.0.

--


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 08:15 AM
Simon Riggs
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

On Thu, 2005-12-08 at 11:10 +0000, Simon Riggs wrote:
> On Wed, 2005-12-07 at 21:24 +0000, Simon Riggs wrote:
> > Following patch implements record of whether a constraint is inherited
> > or not, and prevents dropping of inherited constraints.

>
> Patch posted to -patches list.
>
> > What it doesn't do:
> > It doesn't yet prevent dropping the parent constraint, which is wrong,
> > clearly, but what to do about it?
> > 1. make dropping a constraint drop all constraints dependent upon it
> > (without any explicit cascade)
> > 2. add a new clause to ALTER TABLE .... DROP CONSTRAINT .... CASCADE
> >
> > I prefer (1), since it is SQL Standard compliant, easier to remember and
> > automatic de-inheritance is the natural opposite of the automatic
> > inheritance process.

>
> Comments, please -hackers?


Late night hacking again....

ALTER TABLE .... DROP CONSTRAINT .... CASCADE

does of course already exist, so the following should cause dependency
violation ERRORs:
- omitting the CASCADE when attempting to delete parent constraint
- attempting to drop the child constraint

Best Regards, Simon Riggs


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 08:15 AM
Trent Shipley
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

On Thursday 2005-12-08 15:47, Simon Riggs wrote:

> does of course already exist, so the following should cause dependency
> violation ERRORs:
> - omitting the CASCADE when attempting to delete parent constraint
> - attempting to drop the child constraint


Why should dropping the child constraint fail?

Child tables are supposed to be able to over-ride parent constraints.
Dropping a parent's constraint sounds like just a way to over-ride a
constraint with no constraint at all. (Making the column unconstrained.)

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 08:15 AM
Tom Lane
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

Trent Shipley <tshipley@deru.com> writes:
> Child tables are supposed to be able to over-ride parent constraints.


Says who?

If we allow that, then reading the parent table will produce rows that
violate the parent's constraint. This does not seem very wise.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-12-2008, 02:25 AM
Bruce Momjian
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints


Where are we on this patch? My testing shows it is still shows we have
a problem:

test=> CREATE TABLE x(y INT CHECK(y > 0));
CREATE TABLE
test=> CREATE TABLE z(a INT) inherits (x);
CREATE TABLE
test=> ALTER TABLE z DROP CONSTRAINT "x_y_check";
ALTER TABLE
test=> ALTER TABLE x DROP CONSTRAINT "x_y_check";
ALTER TABLE

Deleting the parent constraint first does not require CASCADE, as it
should, I think:

test=> CREATE TABLE x(y INT CHECK(y > 0));
CREATE TABLE
test=> CREATE TABLE z(a INT) inherits (x);
CREATE TABLE
test=> ALTER TABLE x DROP CONSTRAINT "x_y_check";
ALTER TABLE
test=> ALTER TABLE z DROP CONSTRAINT "x_y_check";
ERROR: CONSTRAINT "x_y_check" does NOT exist

---------------------------------------------------------------------------

Simon Riggs wrote:
> On Thu, 2005-12-08 at 11:10 +0000, Simon Riggs wrote:
> > On Wed, 2005-12-07 at 21:24 +0000, Simon Riggs wrote:
> > > Following patch implements record of whether a constraint is inherited
> > > or not, and prevents dropping of inherited constraints.

> >
> > Patch posted to -patches list.
> >
> > > What it doesn't do:
> > > It doesn't yet prevent dropping the parent constraint, which is wrong,
> > > clearly, but what to do about it?
> > > 1. make dropping a constraint drop all constraints dependent upon it
> > > (without any explicit cascade)
> > > 2. add a new clause to ALTER TABLE .... DROP CONSTRAINT .... CASCADE
> > >
> > > I prefer (1), since it is SQL Standard compliant, easier to remember and
> > > automatic de-inheritance is the natural opposite of the automatic
> > > inheritance process.

> >
> > Comments, please -hackers?

>
> Late night hacking again....
>
> ALTER TABLE .... DROP CONSTRAINT .... CASCADE
>
> does of course already exist, so the following should cause dependency
> violation ERRORs:
> - omitting the CASCADE when attempting to delete parent constraint
> - attempting to drop the child constraint
>
> Best Regards, Simon Riggs
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>


--
Bruce Momjian http://candle.pha.pa.us
SRA OSS, Inc. http://www.sraoss.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-12-2008, 02:29 AM
Bruce Momjian
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints


Added to TODO:

o Prevent parent tables from altering or dropping constraints
like CHECK that are inherited by child tables

Dropping constraints should only be possible with CASCADE.

and we already have this in TODO:

o %Prevent child tables from altering or dropping constraints
like CHECK that were inherited from the parent table

so I think we now have all the failure cases documented.

---------------------------------------------------------------------------

Bruce Momjian wrote:
>
> Where are we on this patch? My testing shows it is still shows we have
> a problem:
>
> test=> CREATE TABLE x(y INT CHECK(y > 0));
> CREATE TABLE
> test=> CREATE TABLE z(a INT) inherits (x);
> CREATE TABLE
> test=> ALTER TABLE z DROP CONSTRAINT "x_y_check";
> ALTER TABLE
> test=> ALTER TABLE x DROP CONSTRAINT "x_y_check";
> ALTER TABLE
>
> Deleting the parent constraint first does not require CASCADE, as it
> should, I think:
>
> test=> CREATE TABLE x(y INT CHECK(y > 0));
> CREATE TABLE
> test=> CREATE TABLE z(a INT) inherits (x);
> CREATE TABLE
> test=> ALTER TABLE x DROP CONSTRAINT "x_y_check";
> ALTER TABLE
> test=> ALTER TABLE z DROP CONSTRAINT "x_y_check";
> ERROR: CONSTRAINT "x_y_check" does NOT exist
>
> ---------------------------------------------------------------------------
>
> Simon Riggs wrote:
> > On Thu, 2005-12-08 at 11:10 +0000, Simon Riggs wrote:
> > > On Wed, 2005-12-07 at 21:24 +0000, Simon Riggs wrote:
> > > > Following patch implements record of whether a constraint is inherited
> > > > or not, and prevents dropping of inherited constraints.
> > >
> > > Patch posted to -patches list.
> > >
> > > > What it doesn't do:
> > > > It doesn't yet prevent dropping the parent constraint, which is wrong,
> > > > clearly, but what to do about it?
> > > > 1. make dropping a constraint drop all constraints dependent upon it
> > > > (without any explicit cascade)
> > > > 2. add a new clause to ALTER TABLE .... DROP CONSTRAINT .... CASCADE
> > > >
> > > > I prefer (1), since it is SQL Standard compliant, easier to remember and
> > > > automatic de-inheritance is the natural opposite of the automatic
> > > > inheritance process.
> > >
> > > Comments, please -hackers?

> >
> > Late night hacking again....
> >
> > ALTER TABLE .... DROP CONSTRAINT .... CASCADE
> >
> > does of course already exist, so the following should cause dependency
> > violation ERRORs:
> > - omitting the CASCADE when attempting to delete parent constraint
> > - attempting to drop the child constraint
> >
> > Best Regards, Simon Riggs
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> >

>
> --
> Bruce Momjian http://candle.pha.pa.us
> SRA OSS, Inc. http://www.sraoss.com
>
> + If your life is a hard drive, Christ can be your backup. +
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>


--
Bruce Momjian http://candle.pha.pa.us
SRA OSS, Inc. http://www.sraoss.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-12-2008, 02:29 AM
Hannu Krosing
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

Ühel kenal päeval, E, 2006-03-06 kell 12:12, kirjutas Bruce Momjian:
> Added to TODO:
>
> o Prevent parent tables from altering or dropping constraints
> like CHECK that are inherited by child tables
>
> Dropping constraints should only be possible with CASCADE.
>
> and we already have this in TODO:
>
> o %Prevent child tables from altering or dropping constraints
> like CHECK that were inherited from the parent table
>
> so I think we now have all the failure cases documented.


If you want to be consistent, then ALTER TABLE ONLY ADD CONSTRAINT ..
should also be forbidden, so you can't create non-inherited constraints

---------------
Hannu



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-12-2008, 02:29 AM
Bruce Momjian
 
Posts: n/a
Default Re: [PATCHES] Inherited Constraints

Hannu Krosing wrote:
> ?hel kenal p?eval, E, 2006-03-06 kell 12:12, kirjutas Bruce Momjian:
> > Added to TODO:
> >
> > o Prevent parent tables from altering or dropping constraints
> > like CHECK that are inherited by child tables
> >
> > Dropping constraints should only be possible with CASCADE.
> >
> > and we already have this in TODO:
> >
> > o %Prevent child tables from altering or dropping constraints
> > like CHECK that were inherited from the parent table
> >
> > so I think we now have all the failure cases documented.

>
> If you want to be consistent, then ALTER TABLE ONLY ADD CONSTRAINT ..
> should also be forbidden, so you can't create non-inherited constraints


I don't have a problem with creating ONLY constraints on parents and
children. We just don't want them to be removed/modified if they are
shared.

--
Bruce Momjian http://candle.pha.pa.us
SRA OSS, Inc. http://www.sraoss.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:44 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com