Commit f7cffbbb authored by Tom Lane's avatar Tom Lane

Tweak dependency code to suppress NOTICEs generated by new method for

cleaning out temp namespaces.  We don't really want the server log to be
cluttered with 'Drop cascades to table foo' every time someone uses a
temp table...
parent 0c693b49
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.22 2003/02/16 02:30:37 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.23 2003/03/06 22:54:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -97,12 +97,14 @@ static void findAutoDeletableObjects(const ObjectAddress *object, ...@@ -97,12 +97,14 @@ static void findAutoDeletableObjects(const ObjectAddress *object,
Relation depRel); Relation depRel);
static bool recursiveDeletion(const ObjectAddress *object, static bool recursiveDeletion(const ObjectAddress *object,
DropBehavior behavior, DropBehavior behavior,
int msglevel,
const ObjectAddress *callingObject, const ObjectAddress *callingObject,
ObjectAddresses *oktodelete, ObjectAddresses *oktodelete,
Relation depRel); Relation depRel);
static bool deleteDependentObjects(const ObjectAddress *object, static bool deleteDependentObjects(const ObjectAddress *object,
const char *objDescription, const char *objDescription,
DropBehavior behavior, DropBehavior behavior,
int msglevel,
ObjectAddresses *oktodelete, ObjectAddresses *oktodelete,
Relation depRel); Relation depRel);
static void doDeletion(const ObjectAddress *object); static void doDeletion(const ObjectAddress *object);
...@@ -164,7 +166,8 @@ performDeletion(const ObjectAddress *object, ...@@ -164,7 +166,8 @@ performDeletion(const ObjectAddress *object,
findAutoDeletableObjects(object, &oktodelete, depRel); findAutoDeletableObjects(object, &oktodelete, depRel);
if (!recursiveDeletion(object, behavior, NULL, &oktodelete, depRel)) if (!recursiveDeletion(object, behavior, NOTICE,
NULL, &oktodelete, depRel))
elog(ERROR, "Cannot drop %s because other objects depend on it" elog(ERROR, "Cannot drop %s because other objects depend on it"
"\n\tUse DROP ... CASCADE to drop the dependent objects too", "\n\tUse DROP ... CASCADE to drop the dependent objects too",
objDescription); objDescription);
...@@ -183,10 +186,12 @@ performDeletion(const ObjectAddress *object, ...@@ -183,10 +186,12 @@ performDeletion(const ObjectAddress *object,
* CASCADE. * CASCADE.
* *
* This is currently used only to clean out the contents of a schema * This is currently used only to clean out the contents of a schema
* (namespace): the passed object is a namespace. * (namespace): the passed object is a namespace. We normally want this
* to be done silently, so there's an option to suppress NOTICE messages.
*/ */
void void
deleteWhatDependsOn(const ObjectAddress *object) deleteWhatDependsOn(const ObjectAddress *object,
bool showNotices)
{ {
char *objDescription; char *objDescription;
Relation depRel; Relation depRel;
...@@ -218,7 +223,9 @@ deleteWhatDependsOn(const ObjectAddress *object) ...@@ -218,7 +223,9 @@ deleteWhatDependsOn(const ObjectAddress *object)
* stuff dependent on the given object. * stuff dependent on the given object.
*/ */
if (!deleteDependentObjects(object, objDescription, if (!deleteDependentObjects(object, objDescription,
DROP_CASCADE, &oktodelete, depRel)) DROP_CASCADE,
showNotices ? NOTICE : DEBUG1,
&oktodelete, depRel))
elog(ERROR, "Failed to drop all objects depending on %s", elog(ERROR, "Failed to drop all objects depending on %s",
objDescription); objDescription);
...@@ -342,7 +349,7 @@ findAutoDeletableObjects(const ObjectAddress *object, ...@@ -342,7 +349,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
* depRel is the already-open pg_depend relation. * depRel is the already-open pg_depend relation.
* *
* *
* In RESTRICT mode, we perform all the deletions anyway, but elog a NOTICE * In RESTRICT mode, we perform all the deletions anyway, but elog a message
* and return FALSE if we find a restriction violation. performDeletion * and return FALSE if we find a restriction violation. performDeletion
* will then abort the transaction to nullify the deletions. We have to * will then abort the transaction to nullify the deletions. We have to
* do it this way to (a) report all the direct and indirect dependencies * do it this way to (a) report all the direct and indirect dependencies
...@@ -370,6 +377,7 @@ findAutoDeletableObjects(const ObjectAddress *object, ...@@ -370,6 +377,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
static bool static bool
recursiveDeletion(const ObjectAddress *object, recursiveDeletion(const ObjectAddress *object,
DropBehavior behavior, DropBehavior behavior,
int msglevel,
const ObjectAddress *callingObject, const ObjectAddress *callingObject,
ObjectAddresses *oktodelete, ObjectAddresses *oktodelete,
Relation depRel) Relation depRel)
...@@ -518,18 +526,17 @@ recursiveDeletion(const ObjectAddress *object, ...@@ -518,18 +526,17 @@ recursiveDeletion(const ObjectAddress *object,
getObjectDescription(&owningObject)); getObjectDescription(&owningObject));
else if (behavior == DROP_RESTRICT) else if (behavior == DROP_RESTRICT)
{ {
elog(NOTICE, "%s depends on %s", elog(msglevel, "%s depends on %s",
getObjectDescription(&owningObject), getObjectDescription(&owningObject),
objDescription); objDescription);
ok = false; ok = false;
} }
else else
elog(NOTICE, "Drop cascades to %s", elog(msglevel, "Drop cascades to %s",
getObjectDescription(&owningObject)); getObjectDescription(&owningObject));
if (!recursiveDeletion(&owningObject, behavior, if (!recursiveDeletion(&owningObject, behavior, msglevel,
object, object, oktodelete, depRel))
oktodelete, depRel))
ok = false; ok = false;
pfree(objDescription); pfree(objDescription);
...@@ -546,7 +553,8 @@ recursiveDeletion(const ObjectAddress *object, ...@@ -546,7 +553,8 @@ recursiveDeletion(const ObjectAddress *object,
* constraint. * constraint.
*/ */
if (!deleteDependentObjects(object, objDescription, if (!deleteDependentObjects(object, objDescription,
behavior, oktodelete, depRel)) behavior, msglevel,
oktodelete, depRel))
ok = false; ok = false;
/* /*
...@@ -613,6 +621,7 @@ static bool ...@@ -613,6 +621,7 @@ static bool
deleteDependentObjects(const ObjectAddress *object, deleteDependentObjects(const ObjectAddress *object,
const char *objDescription, const char *objDescription,
DropBehavior behavior, DropBehavior behavior,
int msglevel,
ObjectAddresses *oktodelete, ObjectAddresses *oktodelete,
Relation depRel) Relation depRel)
{ {
...@@ -664,18 +673,17 @@ deleteDependentObjects(const ObjectAddress *object, ...@@ -664,18 +673,17 @@ deleteDependentObjects(const ObjectAddress *object,
getObjectDescription(&otherObject)); getObjectDescription(&otherObject));
else if (behavior == DROP_RESTRICT) else if (behavior == DROP_RESTRICT)
{ {
elog(NOTICE, "%s depends on %s", elog(msglevel, "%s depends on %s",
getObjectDescription(&otherObject), getObjectDescription(&otherObject),
objDescription); objDescription);
ok = false; ok = false;
} }
else else
elog(NOTICE, "Drop cascades to %s", elog(msglevel, "Drop cascades to %s",
getObjectDescription(&otherObject)); getObjectDescription(&otherObject));
if (!recursiveDeletion(&otherObject, behavior, if (!recursiveDeletion(&otherObject, behavior, msglevel,
object, object, oktodelete, depRel))
oktodelete, depRel))
ok = false; ok = false;
break; break;
case DEPENDENCY_AUTO: case DEPENDENCY_AUTO:
...@@ -689,9 +697,8 @@ deleteDependentObjects(const ObjectAddress *object, ...@@ -689,9 +697,8 @@ deleteDependentObjects(const ObjectAddress *object,
elog(DEBUG1, "Drop auto-cascades to %s", elog(DEBUG1, "Drop auto-cascades to %s",
getObjectDescription(&otherObject)); getObjectDescription(&otherObject));
if (!recursiveDeletion(&otherObject, behavior, if (!recursiveDeletion(&otherObject, behavior, msglevel,
object, object, oktodelete, depRel))
oktodelete, depRel))
ok = false; ok = false;
break; break;
case DEPENDENCY_PIN: case DEPENDENCY_PIN:
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.47 2003/02/09 06:56:26 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.48 2003/03/06 22:54:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1698,7 +1698,7 @@ RemoveTempRelations(Oid tempNamespaceId) ...@@ -1698,7 +1698,7 @@ RemoveTempRelations(Oid tempNamespaceId)
object.objectId = tempNamespaceId; object.objectId = tempNamespaceId;
object.objectSubId = 0; object.objectSubId = 0;
deleteWhatDependsOn(&object); deleteWhatDependsOn(&object, false);
} }
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: dependency.h,v 1.6 2003/02/07 01:33:06 tgl Exp $ * $Id: dependency.h,v 1.7 2003/03/06 22:54:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -84,7 +84,8 @@ typedef struct ObjectAddress ...@@ -84,7 +84,8 @@ typedef struct ObjectAddress
extern void performDeletion(const ObjectAddress *object, extern void performDeletion(const ObjectAddress *object,
DropBehavior behavior); DropBehavior behavior);
extern void deleteWhatDependsOn(const ObjectAddress *object); extern void deleteWhatDependsOn(const ObjectAddress *object,
bool showNotices);
extern void recordDependencyOnExpr(const ObjectAddress *depender, extern void recordDependencyOnExpr(const ObjectAddress *depender,
Node *expr, List *rtable, Node *expr, List *rtable,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment