Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac355d5

Browse files
committed
Move most of the error checking for foreign-key constraints out of
parse analysis and into the execution code (in tablecmds.c). Thiseliminates a lot of unreasonably complex code that needed to have twoor more execution paths in case it was dealing with a not-yet-createdtable column vs. an already-existing one. The execution code is alwaysdealing with already-created tables and so needs only one case. Thisalso eliminates some potential race conditions (the table wasn't lockedbetween parse analysis and execution), makes it easy to fix the gripeabout wrong referenced-column names generating a misleading error message,and lets us easily add a dependency from the foreign-key constraint tothe unique index that it requires the referenced table to have. (Cf.complaint from Kris Jurka 12-Sep-2002 on pgsql-bugs.)Also, third try at building a deletion mechanism that is not sensitiveto the order in which pg_depend entries are visited. Adding the above-mentioned dependency exposed the folly of what dependency.c had beendoing: it failed for cases where B depends on C while both auto-dependon A. Dropping A should succeed in this case, but was failing if Chappened to be visited before B. It appears the only solution is twoseparate walks over the dependency tree.
1 parente303a2d commitac355d5

File tree

10 files changed

+761
-804
lines changed

10 files changed

+761
-804
lines changed

‎src/backend/catalog/dependency.c

Lines changed: 180 additions & 128 deletions
Large diffs are not rendered by default.

‎src/backend/catalog/heap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.229 2002/09/19 23:40:56 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.230 2002/09/22 00:37:09 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1342,6 +1342,7 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin)
13421342
' ',
13431343
' ',
13441344
' ',
1345+
InvalidOid,/* no associated index */
13451346
expr,/* Tree form check constraint */
13461347
ccbin,/* Binary form check constraint */
13471348
ccsrc);/* Source form check constraint */

‎src/backend/catalog/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.196 2002/09/04 20:31:14 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.197 2002/09/22 00:37:09 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -693,6 +693,7 @@ index_create(Oid heapRelationId,
693693
' ',
694694
' ',
695695
' ',
696+
InvalidOid,/* no associated index */
696697
NULL,/* no check constraint */
697698
NULL,
698699
NULL);

‎src/backend/catalog/pg_constraint.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.6 2002/09/04 20:31:14 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.7 2002/09/22 00:37:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -53,6 +53,7 @@ CreateConstraintEntry(const char *constraintName,
5353
charforeignUpdateType,
5454
charforeignDeleteType,
5555
charforeignMatchType,
56+
OidindexRelId,
5657
Node*conExpr,
5758
constchar*conBin,
5859
constchar*conSrc)
@@ -216,6 +217,21 @@ CreateConstraintEntry(const char *constraintName,
216217
}
217218
}
218219

220+
if (OidIsValid(indexRelId))
221+
{
222+
/*
223+
* Register normal dependency on the unique index that supports
224+
* a foreign-key constraint.
225+
*/
226+
ObjectAddressrelobject;
227+
228+
relobject.classId=RelOid_pg_class;
229+
relobject.objectId=indexRelId;
230+
relobject.objectSubId=0;
231+
232+
recordDependencyOn(&conobject,&relobject,DEPENDENCY_NORMAL);
233+
}
234+
219235
if (conExpr!=NULL)
220236
{
221237
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp