aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-10-06 16:38:28 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-10-06 16:38:28 +0000
commitfec58f6c3f17ba6acbba65a73ca736578041677f (patch)
tree7c15e8bbc8a28aeb9e15b30e72068a7b636b945f /src/backend/commands/tablecmds.c
parenta0ab31dcc646a1bc25360999d388fd2a8408dc30 (diff)
downloadpostgresql-fec58f6c3f17ba6acbba65a73ca736578041677f.tar.gz
postgresql-fec58f6c3f17ba6acbba65a73ca736578041677f.zip
During ALTER TABLE ADD FOREIGN KEY, try to check the existing rows using
a single LEFT JOIN query instead of firing the check trigger for each row individually. Stephan Szabo, with some kibitzing from Tom Lane and Jan Wieck.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3ece4f80f95..395077081a7 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.85 2003/10/02 06:36:37 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.86 2003/10/06 16:38:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3455,6 +3455,13 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint,
int count;
/*
+ * See if we can do it with a single LEFT JOIN query. A FALSE result
+ * indicates we must proceed with the fire-the-trigger method.
+ */
+ if (RI_Initial_Check(fkconstraint, rel, pkrel))
+ return;
+
+ /*
* Scan through each tuple, calling RI_FKey_check_ins (insert trigger)
* as if that tuple had just been inserted. If any of those fail, it
* should ereport(ERROR) and that's that.