PostreSQL 的模式创建的代码位于何处

本文深入探讨了PostgreSQL源代码中NamespaceCreate函数的功能,该函数用于创建命名空间,并详细解释了其核心操作过程。通过剖析代码实现,揭示了命名空间创建流程及其对后续数据库操作的影响。

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

主要代码在 src/backend/catalog/pg_namespace.c

/* ----------------                        
 * NamespaceCreate                        
 *                        
 * Create a namespace (schema) with the given name and owner OID.                        
 *                        
 * If isTemp is true, this schema is a per-backend schema for holding                        
 * temporary tables.  Currently, the only effect of that is to prevent it                        
 * from being linked as a member of any active extension.  (If someone                        
 * does CREATE TEMP TABLE in an extension script, we don't want the temp                        
 * schema to become part of the extension.)                        
 * ---------------                        
 */                        
Oid                        
NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)                        
{                        
    ……                    
    nspoid = simple_heap_insert(nspdesc, tup);                    
    Assert(OidIsValid(nspoid));                    
                        
    CatalogUpdateIndexes(nspdesc, tup);                    
                        
    heap_close(nspdesc, RowExclusiveLock);                    
                        
    /* Record dependencies */                    
    myself.classId = NamespaceRelationId;                    
    myself.objectId = nspoid;                    
    myself.objectSubId = 0;                    
                        
    /* dependency on owner */                    
    recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId);                    
                        
    /* dependency on extension ... but not for magic temp schemas */                    
    if (!isTemp)                    
        recordDependencyOnCurrentExtension(&myself, false);                
                        
    /* Post creation hook for new schema */                    
    InvokeObjectAccessHook(OAT_POST_CREATE,                    
                   NamespaceRelationId, nspoid, 0, NULL);        
                        
    return nspoid;                    
    ……                    
}                        
NamespaceCreate 被 src/backend/commands/schemacmds.c 的 CreateSchemaCommand 调用
/*                            
 * CREATE SCHEMA                            
 */                            
void                            
CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)                            
{                            
    ……                        
    /* Create the schema's namespace */                        
    namespaceId = NamespaceCreate(schemaName, owner_uid, false);                        
                            
    /* Advance cmd counter to make the namespace visible */                        
    CommandCounterIncrement();                        
    ……                        
}                            

接下来,我特别想知道,得到的 oid ,被用到了什么地方,以何种方式存储。

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值