aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/pg_constraint.c190
-rw-r--r--src/backend/catalog/pg_depend.c101
-rw-r--r--src/backend/commands/alter.c81
-rw-r--r--src/backend/parser/gram.y11
-rw-r--r--src/backend/tcop/utility.c3
5 files changed, 7 insertions, 379 deletions
diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c
index 6e89d6832c2..2a11674683b 100644
--- a/src/backend/catalog/pg_constraint.c
+++ b/src/backend/catalog/pg_constraint.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.29 2006/02/11 22:17:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.30 2006/02/12 19:11:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -664,191 +664,3 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
heap_close(conRel, RowExclusiveLock);
}
-
-
-/*
- * RenameConstraint
- * Rename a single constraint record
- * conId: The OID of the constraint to rename
- * newName: The new name of the constraint
- * implicitRename: is this an implicit rename? If so, we will issue
- * a notice about the implicit rename
- * cmdName: the command that triggered the rename for the "implicitly
- * renames" notice message
- */
-void
-RenameConstraint(Oid conId, const char* newName,
- bool implicitRename, const char* cmdName)
-{
- Relation conRel;
- ScanKeyData key[1];
- SysScanDesc scan;
- HeapTuple tup;
- NameData newNameData;
- Relation rel;
- Oid relId;
- Oid nspOid;
- Form_pg_constraint conform;
-
- /* before reading the tuple, lock the table it constraints in
- * AccessExclusiveLock mode. Otherwise, if we read it before locking this
- * table, the tuple might be changed by another transaction and our copy
- * would be out of date
- */
- relId = GetConstraintRelationId(conId);
- if (!OidIsValid(relId))
- {
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("constraint with OID %d does not exist", conId)));
- }
-
- rel = relation_open(relId, AccessExclusiveLock);
- nspOid = get_rel_namespace(relId);
-
- conRel = heap_open(ConstraintRelationId, RowExclusiveLock);
-
- ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(conId));
-
- scan = systable_beginscan(conRel, ConstraintOidIndexId, true,
- SnapshotNow, 1, key);
- if (!HeapTupleIsValid((tup = systable_getnext(scan))))
- {
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("constraint with OID %d does not exist", conId)));
- }
-
- conform = (Form_pg_constraint) GETSTRUCT(tup);
-
- if (ConstraintNameIsUsed(CONSTRAINT_RELATION,
- conform->conrelid,
- get_rel_namespace(conform->conrelid),
- newName))
- {
- ereport(ERROR,
- (errcode(ERRCODE_DUPLICATE_OBJECT),
- errmsg("constraint \"%s\" for relation \"%s\" already exists",
- newName,
- RelationGetRelationName(rel))));
- }
- tup = heap_copytuple(tup);
- conform = (Form_pg_constraint) GETSTRUCT(tup);
-
- if (implicitRename && cmdName)
- {
- ereport(NOTICE,
- (errmsg("%s will implicitly rename constraint "
- "\"%s\" to \"%s\" on table \"%s.%s\"",
- cmdName,
- NameStr(conform->conname),
- newName,
- get_namespace_name(nspOid),
- RelationGetRelationName(rel))));
- }
-
- namestrcpy(&newNameData, newName);
- conform->conname = newNameData;
-
- simple_heap_update(conRel, &tup->t_self, tup);
- CatalogUpdateIndexes(conRel, tup);
- heap_freetuple(tup);
-
- systable_endscan(scan);
- heap_close(conRel, RowExclusiveLock);
-
- /* close relation but hold lock until end of transaction */
- relation_close(rel, NoLock);
-}
-
-
-/* GetRelationConstraintOid
- *
- * Get the contraint OID by the relation Id of the relation it constraints and
- * this relations' name. We need this function in order to rename a constraint.
- * This is done via "ALTER TABLE ... ALTER CONSTRAINT name" and the parser
- * gives us the relation this constraint is defined on as well as the
- * constraint's name.
- *
- * The function returns:
- *
- * - the unique OID of the constraint if the constraint could be found
- * - the invalid OID if the constraint was not found
- *
- */
-Oid GetRelationConstraintOid(Oid relId, const char* name)
-{
- Relation conRel;
- ScanKeyData key[1];
- SysScanDesc scan;
- HeapTuple tup;
- Oid conId = InvalidOid;
-
- /* we don't change data, so an AccessShareLock is enough */
- conRel = heap_open(ConstraintRelationId, AccessShareLock);
-
- ScanKeyInit(&key[0],
- Anum_pg_constraint_conrelid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(relId));
-
- scan = systable_beginscan(conRel, ConstraintRelidIndexId, true,
- SnapshotNow, 1, key);
-
- while (HeapTupleIsValid((tup = systable_getnext(scan))))
- {
- Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup);
- if (pg_strcasecmp(name, NameStr(con->conname)) == 0)
- {
- conId = HeapTupleGetOid(tup);
- Assert(OidIsValid(conId));
- }
- }
-
- systable_endscan(scan);
- heap_close(conRel, AccessShareLock);
-
- return conId;
-}
-
-
-/* GetConstraintRelationId
- *
- * Gets the OID of the relation where the constraint is defined on or the
- * invalid OID if the constraint cannot be found.
- */
-Oid GetConstraintRelationId(Oid conId)
-{
- Relation conRel;
- ScanKeyData key[1];
- SysScanDesc scan;
- HeapTuple tup;
- Oid relId = InvalidOid;
-
- /* we don't change data, so an AccessShareLock is enough */
- conRel = heap_open(ConstraintRelationId, AccessShareLock);
-
- ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(conId));
-
- scan = systable_beginscan(conRel, ConstraintOidIndexId, true,
- SnapshotNow, 1, key);
-
- if (HeapTupleIsValid((tup = systable_getnext(scan))))
- {
- Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup);
- relId = con->conrelid;
- Assert(OidIsValid(relId));
- }
-
- systable_endscan(scan);
- heap_close(conRel, AccessShareLock);
-
- return relId;
-}
-
diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c
index 0915ef5c827..95b258f93fd 100644
--- a/src/backend/catalog/pg_depend.c
+++ b/src/backend/catalog/pg_depend.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_depend.c,v 1.18 2006/02/11 22:17:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_depend.c,v 1.19 2006/02/12 19:11:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -361,102 +361,3 @@ isObjectPinned(const ObjectAddress *object, Relation rel)
return ret;
}
-
-List* getReferencingOids(Oid refClassId, Oid refObjId, Oid refObjSubId,
- Oid classId, DependencyType deptype)
-{
- ScanKeyData key[3];
- SysScanDesc scan;
- HeapTuple tup;
- Relation depRel;
- List *list = NIL;
-
- depRel = heap_open(DependRelationId, AccessShareLock);
-
- ScanKeyInit(&key[0],
- Anum_pg_depend_refclassid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(refClassId));
-
- ScanKeyInit(&key[1],
- Anum_pg_depend_refobjid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(refObjId));
-
- ScanKeyInit(&key[2],
- Anum_pg_depend_refobjsubid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(refObjSubId));
-
- scan = systable_beginscan(depRel, DependReferenceIndexId, true,
- SnapshotNow, 3, key);
-
- while (HeapTupleIsValid(tup = systable_getnext(scan)))
- {
- Form_pg_depend depForm = (Form_pg_depend) GETSTRUCT(tup);
-
- /* check if the class id is what we want */
- if (depForm->classid != classId)
- continue;
-
- /* check if the DependencyType is what we want */
- if (depForm->deptype != deptype)
- continue;
-
- /* if we are still here, we have found a match */
- list = lcons_oid(depForm->objid, list);
- break;
- }
- systable_endscan(scan);
-
- heap_close(depRel, AccessShareLock);
- return list;
-}
-
-
-List* getDependentOids(Oid classId, Oid objId,
- Oid refClassId, DependencyType deptype)
-{
- ScanKeyData key[2];
- SysScanDesc scan;
- HeapTuple tup;
- Relation depRel;
- List *list = NIL;
-
- depRel = heap_open(DependRelationId, AccessShareLock);
-
- ScanKeyInit(&key[0],
- Anum_pg_depend_classid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(classId));
-
- ScanKeyInit(&key[1],
- Anum_pg_depend_objid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(objId));
-
- scan = systable_beginscan(depRel, DependDependerIndexId, true,
- SnapshotNow, 2, key);
-
- while (HeapTupleIsValid(tup = systable_getnext(scan)))
- {
- Form_pg_depend depForm = (Form_pg_depend) GETSTRUCT(tup);
-
- /* check if the DependencyType is what we want */
- if (depForm->deptype != deptype)
- continue;
-
- /* check if the referenced class id is what we want */
- if (depForm->refclassid != refClassId)
- continue;
-
- /* if we are still here, we have found a match */
- list = lcons_oid(depForm->refobjid, list);
- break;
- }
- systable_endscan(scan);
-
- heap_close(depRel, AccessShareLock);
- return list;
-}
-
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index 1a120a93882..20360fd60a4 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.16 2006/02/11 22:17:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.17 2006/02/12 19:11:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -16,10 +16,8 @@
#include "access/htup.h"
#include "catalog/catalog.h"
-#include "catalog/dependency.h"
#include "catalog/namespace.h"
#include "catalog/pg_class.h"
-#include "catalog/pg_constraint.h"
#include "commands/alter.h"
#include "commands/conversioncmds.h"
#include "commands/dbcommands.h"
@@ -90,7 +88,6 @@ ExecRenameStmt(RenameStmt *stmt)
case OBJECT_INDEX:
case OBJECT_COLUMN:
case OBJECT_TRIGGER:
- case OBJECT_CONSTRAINT:
{
Oid relid;
@@ -112,38 +109,12 @@ ExecRenameStmt(RenameStmt *stmt)
AclResult aclresult;
aclresult = pg_namespace_aclcheck(namespaceId,
- GetUserId(), ACL_CREATE);
+ GetUserId(),
+ ACL_CREATE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceId));
- /*
- * Do NOT refer to stmt->renameType here because
- * you can also rename an index with ALTER TABLE
- */
- if (get_rel_relkind(relid) == RELKIND_INDEX)
- {
- /* see if we depend on a constraint */
- List* depOids = getDependentOids(
- RelationRelationId, relid,
- ConstraintRelationId,
- DEPENDENCY_INTERNAL);
-
- /* there should only be one constraint */
- Assert(list_length(depOids) <= 1);
- if (list_length(depOids) == 1)
- {
- Oid conRelId = linitial_oid(depOids);
- /*
- * Apply the same name to the
- * constraint and tell it that this
- * is an implicit rename triggered
- * by an "ALTER INDEX" command.
- */
- RenameConstraint(conRelId,
- stmt->newname, true, "ALTER INDEX");
- }
- }
renamerel(relid, stmt->newname);
break;
}
@@ -159,52 +130,6 @@ ExecRenameStmt(RenameStmt *stmt)
stmt->subname, /* old att name */
stmt->newname); /* new att name */
break;
- case OBJECT_CONSTRAINT:
- /* XXX could do extra function renameconstr() - but I
- * don't know where it should go */
- /* renameconstr(relid,
- stmt->subname,
- stmt->newname); */
- {
- List *depRelOids;
- ListCell *l;
- Oid conId =
- GetRelationConstraintOid(relid,
- stmt->subname);
- if (!OidIsValid(conId)) {
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("constraint with name \"%s\" "
- "does not exist",
- stmt->subname)));
- }
- RenameConstraint(conId, stmt->newname,
- false, NULL);
- depRelOids = getReferencingOids(
- ConstraintRelationId, conId, 0,
- RelationRelationId,
- DEPENDENCY_INTERNAL);
- foreach(l, depRelOids)
- {
- Oid depRelOid;
- Oid nspOid;
- depRelOid = lfirst_oid(l);
- nspOid = get_rel_namespace(depRelOid);
- if (get_rel_relkind(depRelOid) == RELKIND_INDEX)
- {
- ereport(NOTICE,
- (errmsg("ALTER TABLE / CONSTRAINT will implicitly rename index "
- "\"%s\" to \"%s\" on table \"%s.%s\"",
- get_rel_name(depRelOid),
- stmt->newname,
- get_namespace_name(nspOid),
- get_rel_name(relid))));
- renamerel(depRelOid, stmt->newname);
- }
- }
- }
- break;
-
default:
/* can't happen */ ;
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 79e4616be13..88d32d837d4 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.528 2006/02/12 03:22:17 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.529 2006/02/12 19:11:01 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -4099,15 +4099,6 @@ RenameStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' RENAME TO name
n->newname = $8;
$$ = (Node *)n;
}
- | ALTER TABLE relation_expr ALTER CONSTRAINT name RENAME TO name
- {
- RenameStmt *n = makeNode(RenameStmt);
- n->renameType = OBJECT_CONSTRAINT;
- n->relation = $3;
- n->subname = $6;
- n->newname = $9;
- $$ = (Node *)n;
- }
| ALTER TRIGGER name ON relation_expr RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 05c943f38bb..b55b1578b38 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.251 2006/02/11 22:17:19 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.252 2006/02/12 19:11:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1406,7 +1406,6 @@ CreateCommandTag(Node *parsetree)
case OBJECT_SCHEMA:
tag = "ALTER SCHEMA";
break;
- case OBJECT_CONSTRAINT:
case OBJECT_COLUMN:
case OBJECT_TABLE:
tag = "ALTER TABLE";