YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/postgres/src/backend/catalog/pg_namespace.c
Line
Count
Source (jump to first uncovered line)
1
/*-------------------------------------------------------------------------
2
 *
3
 * pg_namespace.c
4
 *    routines to support manipulation of the pg_namespace relation
5
 *
6
 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
7
 * Portions Copyright (c) 1994, Regents of the University of California
8
 *
9
 *
10
 * IDENTIFICATION
11
 *    src/backend/catalog/pg_namespace.c
12
 *
13
 *-------------------------------------------------------------------------
14
 */
15
#include "postgres.h"
16
17
#include "access/heapam.h"
18
#include "access/htup_details.h"
19
#include "catalog/dependency.h"
20
#include "catalog/indexing.h"
21
#include "catalog/objectaccess.h"
22
#include "catalog/pg_namespace.h"
23
#include "utils/builtins.h"
24
#include "utils/rel.h"
25
#include "utils/syscache.h"
26
27
28
/* ----------------
29
 * NamespaceCreate
30
 *
31
 * Create a namespace (schema) with the given name and owner OID.
32
 *
33
 * If isTemp is true, this schema is a per-backend schema for holding
34
 * temporary tables.  Currently, it is used to prevent it from being
35
 * linked as a member of any active extension.  (If someone does CREATE
36
 * TEMP TABLE in an extension script, we don't want the temp schema to
37
 * become part of the extension). And to avoid checking for default ACL
38
 * for temp namespace (as it is not necessary).
39
 * ---------------
40
 */
41
Oid
42
NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
43
65
{
44
65
  Relation  nspdesc;
45
65
  HeapTuple tup;
46
65
  Oid     nspoid;
47
65
  bool    nulls[Natts_pg_namespace];
48
65
  Datum   values[Natts_pg_namespace];
49
65
  NameData  nname;
50
65
  TupleDesc tupDesc;
51
65
  ObjectAddress myself;
52
65
  int     i;
53
65
  Acl      *nspacl;
54
55
  /* sanity checks */
56
65
  if (!nspName)
57
0
    elog(ERROR, "no namespace name supplied");
58
59
  /* make sure there is no existing namespace of same name */
60
65
  if (SearchSysCacheExists1(NAMESPACENAME, PointerGetDatum(nspName)))
61
65
    ereport(ERROR,
62
65
        (errcode(ERRCODE_DUPLICATE_SCHEMA),
63
65
         errmsg("schema \"%s\" already exists", nspName)));
64
65
65
  if (!isTemp)
66
33
    nspacl = get_user_default_acl(OBJECT_SCHEMA, ownerId,
67
33
                    InvalidOid);
68
32
  else
69
32
    nspacl = NULL;
70
71
  /* initialize nulls and values */
72
260
  for (i = 0; i < Natts_pg_namespace; i++)
73
195
  {
74
195
    nulls[i] = false;
75
195
    values[i] = (Datum) NULL;
76
195
  }
77
65
  namestrcpy(&nname, nspName);
78
65
  values[Anum_pg_namespace_nspname - 1] = NameGetDatum(&nname);
79
65
  values[Anum_pg_namespace_nspowner - 1] = ObjectIdGetDatum(ownerId);
80
65
  if (nspacl != NULL)
81
2
    values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(nspacl);
82
65
  else
83
63
    nulls[Anum_pg_namespace_nspacl - 1] = true;
84
85
65
  nspdesc = heap_open(NamespaceRelationId, RowExclusiveLock);
86
65
  tupDesc = nspdesc->rd_att;
87
88
65
  tup = heap_form_tuple(tupDesc, values, nulls);
89
90
65
  nspoid = CatalogTupleInsert(nspdesc, tup);
91
65
  Assert(OidIsValid(nspoid));
92
93
65
  heap_close(nspdesc, RowExclusiveLock);
94
95
  /* Record dependencies */
96
65
  myself.classId = NamespaceRelationId;
97
65
  myself.objectId = nspoid;
98
65
  myself.objectSubId = 0;
99
100
  /* dependency on owner */
101
65
  recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId);
102
103
  /* dependences on roles mentioned in default ACL */
104
65
  recordDependencyOnNewAcl(NamespaceRelationId, nspoid, 0, ownerId, nspacl);
105
106
  /* dependency on extension ... but not for magic temp schemas */
107
65
  if (!isTemp)
108
33
    recordDependencyOnCurrentExtension(&myself, false);
109
110
  /* Post creation hook for new schema */
111
65
  InvokeObjectPostCreateHook(NamespaceRelationId, nspoid, 0);
112
113
65
  return nspoid;
114
65
}