Tweak dependency code to suppress NOTICEs generated by new method for
authorTom Lane <[email protected]>
Thu, 6 Mar 2003 22:55:03 +0000 (22:55 +0000)
committerTom Lane <[email protected]>
Thu, 6 Mar 2003 22:55:03 +0000 (22:55 +0000)
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...

src/backend/catalog/dependency.c
src/backend/catalog/namespace.c
src/include/catalog/dependency.h

index fdbe412559520c7a5a9ab5cbc02b1cb7697ef6b1..73f0f149fc4e9053deffc9059386e38aca0885ab 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.12.2.2 2003/02/07 01:33:39 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.12.2.3 2003/03/06 22:55:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -96,12 +96,14 @@ static void findAutoDeletableObjects(const ObjectAddress *object,
                                     Relation depRel);
 static bool recursiveDeletion(const ObjectAddress *object,
                  DropBehavior behavior,
+                 int msglevel,
                  const ObjectAddress *callingObject,
                  ObjectAddresses *oktodelete,
                  Relation depRel);
 static bool deleteDependentObjects(const ObjectAddress *object,
                                   const char *objDescription,
                                   DropBehavior behavior,
+                                  int msglevel,
                                   ObjectAddresses *oktodelete,
                                   Relation depRel);
 static void doDeletion(const ObjectAddress *object);
@@ -163,7 +165,8 @@ performDeletion(const ObjectAddress *object,
 
    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"
             "\n\tUse DROP ... CASCADE to drop the dependent objects too",
             objDescription);
@@ -182,10 +185,12 @@ performDeletion(const ObjectAddress *object,
  * CASCADE.
  *
  * 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
-deleteWhatDependsOn(const ObjectAddress *object)
+deleteWhatDependsOn(const ObjectAddress *object,
+                   bool showNotices)
 {
    char       *objDescription;
    Relation    depRel;
@@ -217,7 +222,9 @@ deleteWhatDependsOn(const ObjectAddress *object)
     * stuff dependent on the given object.
     */
    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",
             objDescription);
 
@@ -341,7 +348,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
  * 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
  * 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
@@ -369,6 +376,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
 static bool
 recursiveDeletion(const ObjectAddress *object,
                  DropBehavior behavior,
+                 int msglevel,
                  const ObjectAddress *callingObject,
                  ObjectAddresses *oktodelete,
                  Relation depRel)
@@ -517,18 +525,17 @@ recursiveDeletion(const ObjectAddress *object,
                 getObjectDescription(&owningObject));
        else if (behavior == DROP_RESTRICT)
        {
-           elog(NOTICE, "%s depends on %s",
+           elog(msglevel, "%s depends on %s",
                 getObjectDescription(&owningObject),
                 objDescription);
            ok = false;
        }
        else
-           elog(NOTICE, "Drop cascades to %s",
+           elog(msglevel, "Drop cascades to %s",
                 getObjectDescription(&owningObject));
 
-       if (!recursiveDeletion(&owningObject, behavior,
-                              object,
-                              oktodelete, depRel))
+       if (!recursiveDeletion(&owningObject, behavior, msglevel,
+                              object, oktodelete, depRel))
            ok = false;
 
        pfree(objDescription);
@@ -545,7 +552,8 @@ recursiveDeletion(const ObjectAddress *object,
     * constraint.
     */
    if (!deleteDependentObjects(object, objDescription,
-                               behavior, oktodelete, depRel))
+                               behavior, msglevel,
+                               oktodelete, depRel))
        ok = false;
 
    /*
@@ -612,6 +620,7 @@ static bool
 deleteDependentObjects(const ObjectAddress *object,
                       const char *objDescription,
                       DropBehavior behavior,
+                      int msglevel,
                       ObjectAddresses *oktodelete,
                       Relation depRel)
 {
@@ -663,18 +672,17 @@ deleteDependentObjects(const ObjectAddress *object,
                         getObjectDescription(&otherObject));
                else if (behavior == DROP_RESTRICT)
                {
-                   elog(NOTICE, "%s depends on %s",
+                   elog(msglevel, "%s depends on %s",
                         getObjectDescription(&otherObject),
                         objDescription);
                    ok = false;
                }
                else
-                   elog(NOTICE, "Drop cascades to %s",
+                   elog(msglevel, "Drop cascades to %s",
                         getObjectDescription(&otherObject));
 
-               if (!recursiveDeletion(&otherObject, behavior,
-                                      object,
-                                      oktodelete, depRel))
+               if (!recursiveDeletion(&otherObject, behavior, msglevel,
+                                      object, oktodelete, depRel))
                    ok = false;
                break;
            case DEPENDENCY_AUTO:
@@ -688,9 +696,8 @@ deleteDependentObjects(const ObjectAddress *object,
                elog(DEBUG1, "Drop auto-cascades to %s",
                     getObjectDescription(&otherObject));
 
-               if (!recursiveDeletion(&otherObject, behavior,
-                                      object,
-                                      oktodelete, depRel))
+               if (!recursiveDeletion(&otherObject, behavior, msglevel,
+                                      object, oktodelete, depRel))
                    ok = false;
                break;
            case DEPENDENCY_PIN:
index b7d785646eeb48d0ae3f922d719b63d7e58e1043..5450b6d110f9f569a6559cf71d7c16ab76f51184 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.38.2.1 2003/02/07 01:33:39 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.38.2.2 2003/03/06 22:55:03 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1615,7 +1615,7 @@ RemoveTempRelations(Oid tempNamespaceId)
    object.objectId = tempNamespaceId;
    object.objectSubId = 0;
 
-   deleteWhatDependsOn(&object);
+   deleteWhatDependsOn(&object, false);
 }
 
 /*
index 198a98cee16ac853bbf29a3f4aa3714a9faa003d..33ac35513c049c35e287a89e5aac73058b376f61 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: dependency.h,v 1.5.2.1 2003/02/07 01:33:39 tgl Exp $
+ * $Id: dependency.h,v 1.5.2.2 2003/03/06 22:55:03 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -84,7 +84,8 @@ typedef struct ObjectAddress
 extern void performDeletion(const ObjectAddress *object,
                DropBehavior behavior);
 
-extern void deleteWhatDependsOn(const ObjectAddress *object);
+extern void deleteWhatDependsOn(const ObjectAddress *object,
+                               bool showNotices);
 
 extern void recordDependencyOnExpr(const ObjectAddress *depender,
                       Node *expr, List *rtable,