Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-06-03 Thread Robert Haas
On Thu, Jun 2, 2011 at 5:34 PM, Thom Brown t...@linux.com wrote: On 8 February 2011 03:50, Robert Haas robertmh...@gmail.com wrote: On Thu, Feb 3, 2011 at 11:00 PM, Robert Haas robertmh...@gmail.com wrote: On Fri, Jan 14, 2011 at 6:15 AM, Simon Riggs si...@2ndquadrant.com wrote: Patch to

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-06-03 Thread Alvaro Herrera
Excerpts from Robert Haas's message of vie jun 03 09:34:03 -0400 2011: Just a note that since Alvaro created a patch to provide similar functionality for constraints, I identified an issue with database dumps, which apparently affects invalid foreign keys too:

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-06-02 Thread Thom Brown
On 8 February 2011 03:50, Robert Haas robertmh...@gmail.com wrote: On Thu, Feb 3, 2011 at 11:00 PM, Robert Haas robertmh...@gmail.com wrote: On Fri, Jan 14, 2011 at 6:15 AM, Simon Riggs si...@2ndquadrant.com wrote: Patch to implement the proposed feature attached, for CFJan2011. 2 sub-command

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-02-07 Thread Robert Haas
On Thu, Feb 3, 2011 at 11:00 PM, Robert Haas robertmh...@gmail.com wrote: On Fri, Jan 14, 2011 at 6:15 AM, Simon Riggs si...@2ndquadrant.com wrote: Patch to implement the proposed feature attached, for CFJan2011. 2 sub-command changes: ALTER TABLE foo ADD FOREIGN KEY fkoo ... NOT VALID;

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-02-03 Thread Robert Haas
On Fri, Jan 14, 2011 at 6:15 AM, Simon Riggs si...@2ndquadrant.com wrote: Patch to implement the proposed feature attached, for CFJan2011. 2 sub-command changes: ALTER TABLE foo ADD FOREIGN KEY fkoo ... NOT VALID; ALTER TABLE foo VALIDATE CONSTRAINT fkoo; This patch, which seems to be the

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-24 Thread Chris Browne
si...@2ndquadrant.com (Simon Riggs) writes: I just wanted to point out that the patch submitted here does not allow what is requested here for FKs (nor indexes). That's fine; I was trying to support the thought that there was something useful about this idea. Being able to expressly deactivate

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-23 Thread Simon Riggs
On Tue, 2010-12-14 at 11:24 -0500, Chris Browne wrote: t...@sss.pgh.pa.us (Tom Lane) writes: Robert Haas robertmh...@gmail.com writes: ... On the other hand, there's clearly also a use case for this behavior. If a bulk load of prevalidated data forces an expensive revalidation of

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-23 Thread Tom Lane
Simon Riggs si...@2ndquadrant.com writes: You can add an FK without an initial check, but the FK is enforced for all further DML changes. I seem to recall pointing out upthread that the FK check triggers are designed on the assumption that the constraint does hold currently. Has any analysis

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-23 Thread Simon Riggs
On Sun, 2011-01-23 at 16:13 -0500, Tom Lane wrote: Simon Riggs si...@2ndquadrant.com writes: You can add an FK without an initial check, but the FK is enforced for all further DML changes. I seem to recall pointing out upthread that the FK check triggers are designed on the assumption

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-23 Thread Kevin Grittner
Tom Lane wrote: I seem to recall pointing out upthread that the FK check triggers are designed on the assumption that the constraint does hold currently. Has any analysis been done on exactly how badly they'll fail when it doesn't hold? I remain unconvinced that this behavior is

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-18 Thread Jim Nasby
On Jan 14, 2011, at 5:15 AM, Simon Riggs wrote: On Mon, 2010-12-13 at 17:15 +, Peter Geoghegan wrote: On 13 December 2010 16:08, Robert Haas robertmh...@gmail.com wrote: On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs si...@2ndquadrant.com wrote: 2. pg_validate_foreign_key('constraint

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-18 Thread Simon Riggs
On Tue, 2011-01-18 at 14:26 -0600, Jim Nasby wrote: 2 sub-command changes: ALTER TABLE foo ADD FOREIGN KEY fkoo ... NOT VALID; ALTER TABLE foo VALIDATE CONSTRAINT fkoo; Sorry for the late reply; I just saw this... Is there any way to be able to get the bad records out of the

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-14 Thread Simon Riggs
On Mon, 2010-12-13 at 17:15 +, Peter Geoghegan wrote: On 13 December 2010 16:08, Robert Haas robertmh...@gmail.com wrote: On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs si...@2ndquadrant.com wrote: 2. pg_validate_foreign_key('constraint name'); Returns immediately if FK is valid

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-06 Thread Simon Riggs
On Wed, 2011-01-05 at 22:05 -0500, Bruce Momjian wrote: Robert Haas wrote: On Mon, Dec 13, 2010 at 12:59 AM, Rob Wultsch wult...@gmail.com wrote: On Sun, Dec 12, 2010 at 7:24 PM, Andrew Dunstan and...@dunslane.net wrote: In fact it's possible now to disable FK enforcement, by

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2011-01-05 Thread Bruce Momjian
Robert Haas wrote: On Mon, Dec 13, 2010 at 12:59 AM, Rob Wultsch wult...@gmail.com wrote: On Sun, Dec 12, 2010 at 7:24 PM, Andrew Dunstan and...@dunslane.net wrote: In fact it's possible now to disable FK enforcement, by disabling the triggers. It's definitely a footgun though. Just the

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-14 Thread Chris Browne
t...@sss.pgh.pa.us (Tom Lane) writes: Robert Haas robertmh...@gmail.com writes: ... On the other hand, there's clearly also a use case for this behavior. If a bulk load of prevalidated data forces an expensive revalidation of constraints that are already known to hold, there's a real chance

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Dimitri Fontaine
Tom Lane t...@sss.pgh.pa.us writes: The incremental FK checks are designed on the assumption that the constraint condition held before; they aren't likely to behave very sanely if the data is bad. I'd want to see a whole lot more analysis of the resulting behavior before even considering an

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Nicolas Barbier
2010/12/13 Tom Lane t...@sss.pgh.pa.us: But allow me to harbor doubts that they really intend to allow someone to force a constraint to be considered valid without any verification. Table constraints are either enforced or not enforced. Domain constraints and assertions are always enforced.,

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Peter Geoghegan
On 13 December 2010 10:30, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Seriously, real-world use cases such as Kevin's one seems to warrant that we are able to create a table withouth enforcing the FK. That's horrid, yes, that's needed, too. Maybe some operations would have to be instructed

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Robert Haas
On Mon, Dec 13, 2010 at 12:59 AM, Rob Wultsch wult...@gmail.com wrote: On Sun, Dec 12, 2010 at 7:24 PM, Andrew Dunstan and...@dunslane.net wrote: In fact it's possible now to disable FK enforcement, by disabling the triggers. It's definitely a footgun though. Just the other day I was asked how

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Simon Riggs
On Mon, 2010-12-13 at 11:54 +, Peter Geoghegan wrote: On 13 December 2010 10:30, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Seriously, real-world use cases such as Kevin's one seems to warrant that we are able to create a table withouth enforcing the FK. That's horrid, yes, that's

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Robert Haas
On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs si...@2ndquadrant.com wrote: (a) ALTER TABLE ... ADD FOREIGN KEY ... NOT VALIDATED INITIALLY; will add a FK but NOT run the check - we mark it as check pending. Lock held: ShareRowExclusiveLock Seems about right. Not sure whether the lock strength

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Peter Geoghegan
On 13 December 2010 16:08, Robert Haas robertmh...@gmail.com wrote: On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs si...@2ndquadrant.com wrote: 2. pg_validate_foreign_key('constraint name'); Returns immediately if FK is valid Returns SETOF rows that violate the constraint, or if no rows are

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread David Fetter
On Mon, Dec 13, 2010 at 05:15:29PM +, Peter Geoghegan wrote: On 13 December 2010 16:08, Robert Haas robertmh...@gmail.com wrote: On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs si...@2ndquadrant.com wrote: 2. pg_validate_foreign_key('constraint name'); Returns immediately if FK is valid

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-13 Thread Simon Riggs
On Mon, 2010-12-13 at 17:15 +, Peter Geoghegan wrote: On 13 December 2010 16:08, Robert Haas robertmh...@gmail.com wrote: On Mon, Dec 13, 2010 at 10:49 AM, Simon Riggs si...@2ndquadrant.com wrote: 2. pg_validate_foreign_key('constraint name'); Returns immediately if FK is valid

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Tom Lane
Simon Riggs si...@2ndquadrant.com writes: The new SQL Standard (SQL:2011) contains this: Table constraints are either enforced or not enforced. Domain constraints and assertions are always enforced., 4.17.2 The SQL Standard allows you to turn the checking on and off for CHECK constraints,

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Simon Riggs
On Sun, 2010-12-12 at 17:57 -0500, Tom Lane wrote: Simon Riggs si...@2ndquadrant.com writes: The new SQL Standard (SQL:2011) contains this: Table constraints are either enforced or not enforced. Domain constraints and assertions are always enforced., 4.17.2 The SQL Standard allows you

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Tom Lane
Simon Riggs si...@2ndquadrant.com writes: On Sun, 2010-12-12 at 17:57 -0500, Tom Lane wrote: Huh? It allows you to postpone the check until commit. That's far from not enforcing it. This clearly implies that un-enforced constraints are not checked at commit. [ shrug... ] I can't argue

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Robert Haas
On Sun, Dec 12, 2010 at 6:20 PM, Tom Lane t...@sss.pgh.pa.us wrote: Simon Riggs si...@2ndquadrant.com writes: On Sun, 2010-12-12 at 17:57 -0500, Tom Lane wrote: Huh?  It allows you to postpone the check until commit.  That's far from not enforcing it. This clearly implies that un-enforced

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: ... On the other hand, there's clearly also a use case for this behavior. If a bulk load of prevalidated data forces an expensive revalidation of constraints that are already known to hold, there's a real chance the DBA will be backed into a corner

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Robert Haas
On Sun, Dec 12, 2010 at 7:07 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: ...  On the other hand, there's clearly also a use case for this behavior.  If a bulk load of prevalidated data forces an expensive revalidation of constraints that are already known

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Rob Wultsch
On Sun, Dec 12, 2010 at 4:49 PM, Robert Haas robertmh...@gmail.com wrote: On Sun, Dec 12, 2010 at 6:20 PM, Tom Lane t...@sss.pgh.pa.us wrote: Simon Riggs si...@2ndquadrant.com writes: On Sun, 2010-12-12 at 17:57 -0500, Tom Lane wrote: Huh?  It allows you to postpone the check until commit.  

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Andrew Dunstan
On 12/12/2010 08:27 PM, Rob Wultsch wrote: MySQL does in fact have this feature and it is used by mysqldump. This feature is very useful. The trouble is that FK's have more than one use. In particular, they have a documentary use that's used by tools that analyze databases, as well as by

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Peter Geoghegan
I wouldn't like to comment on whether or not Simon has correctly interpreted the words of the SQL standards committee, because standards committees sometimes word things in an intentionally ambiguous way to placate different interests, and because it seems fairly inconsequential in this case. IMHO

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Kevin Grittner
Peter Geoghegan wrote: If we followed this behaviour, we wouldn't let people just arbitrarily claim that a referential condition exists - rather, we'd let them assert that it /ought/ to exist, and that it will be maintained going forward, and give them the option of verifying that

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Rob Wultsch
On Sun, Dec 12, 2010 at 7:24 PM, Andrew Dunstan and...@dunslane.net wrote: In fact it's possible now to disable FK enforcement, by disabling the triggers. It's definitely a footgun though. Just the other day I was asked how data violating the constraint could have got into the table, and caused

Re: [HACKERS] ALTER TABLE ... ADD FOREIGN KEY ... NOT ENFORCED

2010-12-12 Thread Simon Riggs
On Sun, 2010-12-12 at 19:07 -0500, Tom Lane wrote: Robert Haas robertmh...@gmail.com writes: ... On the other hand, there's clearly also a use case for this behavior. If a bulk load of prevalidated data forces an expensive revalidation of constraints that are already known to hold,