PostgreSQL Source Code  git master
pg_namespace.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_namespace_d.h"
#include "utils/acl.h"
Include dependency graph for pg_namespace.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_namespaceForm_pg_namespace
 

Functions

 CATALOG (pg_namespace, 2615, NamespaceRelationId)
 
 DECLARE_TOAST (pg_namespace, 4163, 4164)
 
 DECLARE_UNIQUE_INDEX (pg_namespace_nspname_index, 2684, NamespaceNameIndexId, pg_namespace, btree(nspname name_ops))
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_namespace_oid_index, 2685, NamespaceOidIndexId, pg_namespace, btree(oid oid_ops))
 
 MAKE_SYSCACHE (NAMESPACENAME, pg_namespace_nspname_index, 4)
 
 MAKE_SYSCACHE (NAMESPACEOID, pg_namespace_oid_index, 16)
 
Oid NamespaceCreate (const char *nspName, Oid ownerId, bool isTemp)
 

Variables

 FormData_pg_namespace
 

Typedef Documentation

◆ Form_pg_namespace

Definition at line 52 of file pg_namespace.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_namespace  ,
2615  ,
NamespaceRelationId   
)

Definition at line 35 of file pg_namespace.h.

36 {
37  Oid oid; /* oid */
38 
39  NameData nspname;
40  Oid nspowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
41 
42 #ifdef CATALOG_VARLEN /* variable-length fields start here */
43  aclitem nspacl[1];
44 #endif
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_DEFAULT(value)
Definition: genbki.h:35
FormData_pg_namespace
Definition: pg_namespace.h:45
unsigned int Oid
Definition: postgres_ext.h:31
Definition: c.h:741

References BKI_DEFAULT, and BKI_LOOKUP.

◆ DECLARE_TOAST()

DECLARE_TOAST ( pg_namespace  ,
4163  ,
4164   
)

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_namespace_nspname_index  ,
2684  ,
NamespaceNameIndexId  ,
pg_namespace  ,
btree(nspname name_ops)   
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_namespace_oid_index  ,
2685  ,
NamespaceOidIndexId  ,
pg_namespace  ,
btree(oid oid_ops)   
)

◆ MAKE_SYSCACHE() [1/2]

MAKE_SYSCACHE ( NAMESPACENAME  ,
pg_namespace_nspname_index  ,
 
)

◆ MAKE_SYSCACHE() [2/2]

MAKE_SYSCACHE ( NAMESPACEOID  ,
pg_namespace_oid_index  ,
16   
)

◆ NamespaceCreate()

Oid NamespaceCreate ( const char *  nspName,
Oid  ownerId,
bool  isTemp 
)

Definition at line 43 of file pg_namespace.c.

44 {
45  Relation nspdesc;
46  HeapTuple tup;
47  Oid nspoid;
48  bool nulls[Natts_pg_namespace];
49  Datum values[Natts_pg_namespace];
50  NameData nname;
51  TupleDesc tupDesc;
52  ObjectAddress myself;
53  int i;
54  Acl *nspacl;
55 
56  /* sanity checks */
57  if (!nspName)
58  elog(ERROR, "no namespace name supplied");
59 
60  /* make sure there is no existing namespace of same name */
61  if (SearchSysCacheExists1(NAMESPACENAME, PointerGetDatum(nspName)))
62  ereport(ERROR,
63  (errcode(ERRCODE_DUPLICATE_SCHEMA),
64  errmsg("schema \"%s\" already exists", nspName)));
65 
66  if (!isTemp)
67  nspacl = get_user_default_acl(OBJECT_SCHEMA, ownerId,
68  InvalidOid);
69  else
70  nspacl = NULL;
71 
72  nspdesc = table_open(NamespaceRelationId, RowExclusiveLock);
73  tupDesc = nspdesc->rd_att;
74 
75  /* initialize nulls and values */
76  for (i = 0; i < Natts_pg_namespace; i++)
77  {
78  nulls[i] = false;
79  values[i] = (Datum) NULL;
80  }
81 
82  nspoid = GetNewOidWithIndex(nspdesc, NamespaceOidIndexId,
83  Anum_pg_namespace_oid);
84  values[Anum_pg_namespace_oid - 1] = ObjectIdGetDatum(nspoid);
85  namestrcpy(&nname, nspName);
86  values[Anum_pg_namespace_nspname - 1] = NameGetDatum(&nname);
87  values[Anum_pg_namespace_nspowner - 1] = ObjectIdGetDatum(ownerId);
88  if (nspacl != NULL)
89  values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(nspacl);
90  else
91  nulls[Anum_pg_namespace_nspacl - 1] = true;
92 
93 
94  tup = heap_form_tuple(tupDesc, values, nulls);
95 
96  CatalogTupleInsert(nspdesc, tup);
97  Assert(OidIsValid(nspoid));
98 
99  table_close(nspdesc, RowExclusiveLock);
100 
101  /* Record dependencies */
102  myself.classId = NamespaceRelationId;
103  myself.objectId = nspoid;
104  myself.objectSubId = 0;
105 
106  /* dependency on owner */
107  recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId);
108 
109  /* dependencies on roles mentioned in default ACL */
110  recordDependencyOnNewAcl(NamespaceRelationId, nspoid, 0, ownerId, nspacl);
111 
112  /* dependency on extension ... but not for magic temp schemas */
113  if (!isTemp)
114  recordDependencyOnCurrentExtension(&myself, false);
115 
116  /* Post creation hook for new schema */
117  InvokeObjectPostCreateHook(NamespaceRelationId, nspoid, 0);
118 
119  return nspoid;
120 }
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Definition: aclchk.c:4365
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition: aclchk.c:4289
static Datum values[MAXATTR]
Definition: bootstrap.c:152
#define Assert(condition)
Definition: c.h:858
#define OidIsValid(objectId)
Definition: c.h:775
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:391
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
int i
Definition: isn.c:73
#define RowExclusiveLock
Definition: lockdefs.h:38
void namestrcpy(Name name, const char *str)
Definition: name.c:233
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:173
@ OBJECT_SCHEMA
Definition: parsenodes.h:2299
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:192
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:160
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum NameGetDatum(const NameData *X)
Definition: postgres.h:373
#define InvalidOid
Definition: postgres_ext.h:36
TupleDesc rd_att
Definition: rel.h:112
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:95
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References Assert, CatalogTupleInsert(), ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, get_user_default_acl(), GetNewOidWithIndex(), heap_form_tuple(), i, InvalidOid, InvokeObjectPostCreateHook, NameGetDatum(), namestrcpy(), OBJECT_SCHEMA, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, PointerGetDatum(), RelationData::rd_att, recordDependencyOnCurrentExtension(), recordDependencyOnNewAcl(), recordDependencyOnOwner(), RowExclusiveLock, SearchSysCacheExists1, table_close(), table_open(), and values.

Referenced by CreateSchemaCommand(), and InitTempTableNamespace().

Variable Documentation

◆ FormData_pg_namespace

FormData_pg_namespace

Definition at line 45 of file pg_namespace.h.