模式的删除与dodeletion

代码位于src/backend/catalog/dependency.c,这里有一个 dodeletion 函数。

不过这个函数是通用的。

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

/*                            
 * doDeletion: actually delete a single object                            
 */                            
static void                            
doDeletion(const ObjectAddress *object, int flags)                            
{                            
    switch (getObjectClass(object))                        
    {                        
        ……                    
        case OCLASS_SCHEMA:                    
            RemoveSchemaById(object->objectId);                
            break;                
                            
        ……                    
        default:                    
            elog(ERROR, "unrecognized object class: %u",                
                 object->classId);            
    }                        
}                            

而它又是被 depency.c 中的 deleteOneObject 调用

/*                            
 * deleteOneObject: delete a single object for performDeletion.                            
 *                            
 * depRel is the already-open pg_depend relation.                            
 */                            
static void                            
deleteOneObject(const ObjectAddress *object, Relation depRel, int flags)                            
{                            
    ……                        
    /*                        
     * Now delete the object itself, in an object-type-dependent way.                        
     */                        
    doDeletion(object, flags);                        
                            
    ……                        
    /*                        
     * And we're done!                        
     */                        
}                            

而它又是被 performDeletion 所调用:

/*                            
 * performDeletion: attempt to drop the specified object.  If CASCADE                            
 * behavior is specified, also drop any dependent objects (recursively).                            
 * If RESTRICT behavior is specified, error out if there are any dependent                            
 * objects, except for those that should be implicitly dropped anyway                            
 * according to the dependency type.                            
 *                            
 * This is the outer control routine for all forms of DROP that drop objects                            
 * that can participate in dependencies.  Note that the next two routines                            
 * are variants on the same theme; if you change anything here you'll likely                            
 * need to fix them too.                            
 *                            
 * flags should include PERFORM_DELETION_INTERNAL when the drop operation is                            
 * not the direct result of a user-initiated action.  For example, when a                            
 * temporary schema is cleaned out so that a new backend can use it, or when                            
 * a column default is dropped as an intermediate step while adding a new one,                            
 * that's an internal operation.  On the other hand, when the we drop something                            
 * because the user issued a DROP statement against it, that's not internal.                            
 */                            
void                            
performDeletion(const ObjectAddress *object,                            
                DropBehavior behavior, int flags)            
{                            
    ……                        
    /*                        
     * Delete all the objects in the proper order.                        
     */                        
    for (i = 0; i < targetObjects->numrefs; i++)                        
    {                        
        ObjectAddress *thisobj = targetObjects->refs + i;                    
                            
        deleteOneObject(thisobj, depRel, flags);                    
    }                        
                            
    /* And clean up */                        
    free_object_addresses(targetObjects);                        
                            
    heap_close(depRel, RowExclusiveLock);                        
}                            

今后继续。

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

原文地址:https://www.cnblogs.com/gaojian/p/2740938.html