From 375e5b0a687570eb41fb9e9fda9e5d6992fccffa Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 8 Feb 2011 18:12:17 -0500 Subject: 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. --- src/backend/commands/tablecmds.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/backend/commands/tablecmds.c') 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, ©Tuple->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); } /* -- cgit v1.2.3