aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-02-08 18:12:17 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-02-08 18:12:17 -0500
commit375e5b0a687570eb41fb9e9fda9e5d6992fccffa (patch)
tree285c5d6b2a3ccf74393c77c14edda857fbc82345 /src/backend/commands/tablecmds.c
parent0bc0bd07d41169d6de513967615ad9cb3d0f322e (diff)
downloadpostgresql-375e5b0a687570eb41fb9e9fda9e5d6992fccffa.tar.gz
postgresql-375e5b0a687570eb41fb9e9fda9e5d6992fccffa.zip
Suppress some compiler warnings in recent commits.
Older versions of gcc tend to throw "variable might be clobbered by `longjmp' or `vfork'" warnings whenever a variable is assigned in more than one place and then used after the end of a PG_TRY block. That's reasonably easy to work around in execute_extension_script, and the overhead of unconditionally saving/restoring the GUC variables seems unlikely to be a serious concern. Also clean up logic in ATExecValidateConstraint to make it easier to read and less likely to provoke "variable might be used uninitialized in this function" warnings.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f67e9b9b162..9c812397b1e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5612,17 +5612,16 @@ static void
ATExecValidateConstraint(Relation rel, const char *constrName)
{
Relation conrel;
- Form_pg_constraint con;
SysScanDesc scan;
ScanKeyData key;
HeapTuple tuple;
+ Form_pg_constraint con = NULL;
bool found = false;
- Oid conid;
conrel = heap_open(ConstraintRelationId, RowExclusiveLock);
/*
- * Find and the target constraint
+ * Find and check the target constraint
*/
ScanKeyInit(&key,
Anum_pg_constraint_conrelid,
@@ -5634,17 +5633,23 @@ ATExecValidateConstraint(Relation rel, const char *constrName)
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
{
con = (Form_pg_constraint) GETSTRUCT(tuple);
-
- if (strcmp(NameStr(con->conname), constrName) != 0)
- continue;
-
- conid = HeapTupleGetOid(tuple);
- found = true;
- break;
+ if (con->contype == CONSTRAINT_FOREIGN &&
+ strcmp(NameStr(con->conname), constrName) == 0)
+ {
+ found = true;
+ break;
+ }
}
- if (found && con->contype == CONSTRAINT_FOREIGN && !con->convalidated)
+ if (!found)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("foreign key constraint \"%s\" of relation \"%s\" does not exist",
+ constrName, RelationGetRelationName(rel))));
+
+ if (!con->convalidated)
{
+ Oid conid = HeapTupleGetOid(tuple);
HeapTuple copyTuple = heap_copytuple(tuple);
Form_pg_constraint copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
Relation refrel;
@@ -5671,19 +5676,13 @@ ATExecValidateConstraint(Relation rel, const char *constrName)
simple_heap_update(conrel, &copyTuple->t_self, copyTuple);
CatalogUpdateIndexes(conrel, copyTuple);
heap_freetuple(copyTuple);
+
heap_close(refrel, NoLock);
}
systable_endscan(scan);
- heap_close(conrel, RowExclusiveLock);
- if (!found)
- {
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("foreign key constraint \"%s\" of relation \"%s\" does not exist",
- constrName, RelationGetRelationName(rel))));
- }
+ heap_close(conrel, RowExclusiveLock);
}
/*