【postgresql】namespace.c代码解析

本文深入解析PostgreSQL中`namespace.c`的实现,涉及RangeVarGetAndCheckCreationNamespace、PushOverrideSearchPath等关键函数,阐述namespace搜索路径的概念及如何处理relation的创建与查找。通过对pg_namespace系统表的操作,理解数据库对象命名空间的管理。
摘要由CSDN通过智能技术生成

DefineRelation

ObjectAddress
DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
			   ObjectAddress *typaddress, const char *queryString)
{
   
	/*
	 * Look up the namespace in which we are supposed to create the relation,
	 * check we have permission to create there, lock it against concurrent
	 * drop, and mark stmt->relation as RELPERSISTENCE_TEMP if a temporary
	 * namespace is selected.
	 */
	namespaceId =
		RangeVarGetAndCheckCreationNamespace(stmt->relation, NoLock, NULL);
}

其中RangeVarGetAndCheckCreationNamespace输入一个关系relation,返回对应应该创建的namespaceid。

namespace.c

src/backend/catalog/namespace.c
支持访问和查找namespace
而pg_namespace.c包含的是对pg_namespace系统表的操作。
本文件提供定义一个namespace search path以及操作search-path-controlled的搜索。

namespace search path是namespace id的集合。

RangeVarGetAndCheckCreationNamespace

Oid
RangeVarGetAndCheckCreationNamespace(RangeVar *relation,
									 LOCKMODE lockmode,
									 Oid *existing_relation_id)
{
   
	Oid			nspid;
	nspid = RangeVarGetCreationNamespace(relation);
}

RangeVarGetCreationNamespace

给定一个relation,选择它的创建用的namespace

Oid
RangeVarGetCreationNamespace(const RangeVar *newRelation)
{
   
	Oid			namespaceId;
	// 这个activeCreationNamespace是个全局变量
	namespaceId 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值