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