<variablelist>
<varlistentry>
<term>
- <literal>create</>
+ <literal>create</>
+ <replaceable class="parameter">tablename</replaceable>
+ <replaceable class="parameter">tableoid</replaceable>
<optional><literal>bootstrap</></optional>
<optional><literal>shared_relation</></optional>
<optional><literal>without_oids</></optional>
- <replaceable class="parameter">tablename</replaceable>
- <replaceable class="parameter">tableoid</replaceable>
+ <optional><literal>rowtype_oid</> <replaceable>oid</></optional>
(<replaceable class="parameter">name1</replaceable> =
<replaceable class="parameter">type1</replaceable> <optional>,
<replaceable class="parameter">name2</replaceable> = <replaceable
The table is created as shared if <literal>shared_relation</> is
specified.
It will have OIDs unless <literal>without_oids</> is specified.
+ The table's rowtype OID (<structname>pg_type</> OID) can optionally
+ be specified via the <literal>rowtype_oid</> clause; if not specified,
+ an OID is automatically generated for it. (The <literal>rowtype_oid</>
+ clause is useless if <literal>bootstrap</> is specified, but it can be
+ provided anyway for documentation.)
</para>
</listitem>
</varlistentry>
%type <ival> boot_const boot_ident
%type <ival> optbootstrap optsharedrelation optwithoutoids
%type <ival> boot_tuple boot_tuplelist
-%type <oidval> oidspec optoideq
+%type <oidval> oidspec optoideq optrowtypeoid
%token <ival> CONST_P ID
%token OPEN XCLOSE XCREATE INSERT_TUPLE
%token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE XTOAST
%token COMMA EQUALS LPAREN RPAREN
-%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS NULLVAL
+%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS XROWTYPE_OID NULLVAL
%start TopLevel
%nonassoc low
;
Boot_CreateStmt:
- XCREATE optbootstrap optsharedrelation optwithoutoids boot_ident oidspec LPAREN
+ XCREATE boot_ident oidspec optbootstrap optsharedrelation optwithoutoids optrowtypeoid LPAREN
{
do_start();
numattr = 0;
elog(DEBUG4, "creating%s%s relation %s %u",
- $2 ? " bootstrap" : "",
- $3 ? " shared" : "",
- LexIDStr($5),
- $6);
+ $4 ? " bootstrap" : "",
+ $5 ? " shared" : "",
+ LexIDStr($2),
+ $3);
}
boot_typelist
{
do_start();
- tupdesc = CreateTupleDesc(numattr, !($4), attrtypes);
+ tupdesc = CreateTupleDesc(numattr, !($6), attrtypes);
- if ($2)
+ if ($4)
{
if (boot_reldesc)
{
closerel(NULL);
}
- boot_reldesc = heap_create(LexIDStr($5),
+ boot_reldesc = heap_create(LexIDStr($2),
PG_CATALOG_NAMESPACE,
- $3 ? GLOBALTABLESPACE_OID : 0,
- $6,
+ $5 ? GLOBALTABLESPACE_OID : 0,
+ $3,
tupdesc,
RELKIND_RELATION,
- $3,
+ $5,
true);
elog(DEBUG4, "bootstrap relation created");
}
{
Oid id;
- id = heap_create_with_catalog(LexIDStr($5),
+ id = heap_create_with_catalog(LexIDStr($2),
PG_CATALOG_NAMESPACE,
- $3 ? GLOBALTABLESPACE_OID : 0,
- $6,
+ $5 ? GLOBALTABLESPACE_OID : 0,
+ $3,
+ $7,
BOOTSTRAP_SUPERUSERID,
tupdesc,
NIL,
RELKIND_RELATION,
- $3,
+ $5,
true,
0,
ONCOMMIT_NOOP,
| { $$ = 0; }
;
+optrowtypeoid:
+ XROWTYPE_OID oidspec { $$ = $2; }
+ | { $$ = InvalidOid; }
+ ;
+
boot_typelist:
boot_type_thing
| boot_typelist COMMA boot_type_thing
optoideq:
OBJ_ID EQUALS oidspec { $$ = $3; }
- | { $$ = (Oid) 0; }
+ | { $$ = InvalidOid; }
;
boot_tuplelist:
bootstrap { return(XBOOTSTRAP); }
"shared_relation" { return(XSHARED_RELATION); }
"without_oids" { return(XWITHOUT_OIDS); }
+"rowtype_oid" { return(XROWTYPE_OID); }
_null_ { return(NULLVAL); }
insert { return(INSERT_TUPLE); }
bootstrap = "";
shared_relation = "";
without_oids = "";
+ rowtype_oid = "";
nc = 0;
reln_open = 0;
comment_level = 0;
oid = substr(catalogandoid, pos+1, length(catalogandoid)-pos);
if ($0 ~ /BKI_BOOTSTRAP/) {
- bootstrap = "bootstrap ";
+ bootstrap = " bootstrap";
}
if ($0 ~ /BKI_SHARED_RELATION/) {
- shared_relation = "shared_relation ";
+ shared_relation = " shared_relation";
}
if ($0 ~ /BKI_WITHOUT_OIDS/) {
- without_oids = "without_oids ";
+ without_oids = " without_oids";
+ }
+ if ($0 ~ /BKI_ROWTYPE_OID\([0-9]*\)/) {
+ rowtype_oid = gensub(/^.*BKI_ROWTYPE_OID\(([0-9]*)\).*$/, " rowtype_oid \\1", 1);
}
i = 1;
# if this is the last line, then output the bki catalog stuff.
# ----
if ($1 ~ /}/) {
- print "create " bootstrap shared_relation without_oids catalog " " oid;
+ print "create " catalog " " oid bootstrap shared_relation without_oids rowtype_oid;
print "\t(";
for (j=1; j<i-1; j++) {
bootstrap = "";
shared_relation = "";
without_oids = "";
+ rowtype_oid = "";
next;
}
Oid new_rel_oid,
char new_rel_kind,
Oid ownerid,
+ Oid new_row_type,
Oid new_array_type);
static void RelationRemoveInheritance(Oid relid);
static void StoreRelCheck(Relation rel, char *ccname, Node *expr,
Oid new_rel_oid,
char new_rel_kind,
Oid ownerid,
+ Oid new_row_type,
Oid new_array_type)
{
return
- TypeCreate(InvalidOid, /* no predetermined OID */
+ TypeCreate(new_row_type, /* optional predetermined OID */
typeName, /* type name */
typeNamespace, /* type namespace */
new_rel_oid, /* relation oid */
Oid relnamespace,
Oid reltablespace,
Oid relid,
+ Oid reltypeid,
Oid ownerid,
TupleDesc tupdesc,
List *cooked_constraints,
/*
* Since defining a relation also defines a complex type, we add a new
- * system type corresponding to the new relation.
+ * system type corresponding to the new relation. The OID of the type
+ * can be preselected by the caller, but if reltypeid is InvalidOid,
+ * we'll generate a new OID for it.
*
* NOTE: we could get a unique-index failure here, in case someone else is
* creating the same type name in parallel but hadn't committed yet when
relid,
relkind,
ownerid,
+ reltypeid,
new_array_oid);
/*
namespaceid,
rel->rd_rel->reltablespace,
toastOid,
+ InvalidOid,
rel->rd_rel->relowner,
tupdesc,
NIL,
RelationGetNamespace(OldHeap),
NewTableSpace,
InvalidOid,
+ InvalidOid,
OldHeap->rd_rel->relowner,
tupdesc,
NIL,
namespaceId,
tablespaceId,
InvalidOid,
+ InvalidOid,
GetUserId(),
descriptor,
list_concat(cookedDefaults,
namespaceId,
tablespaceId,
InvalidOid,
+ InvalidOid,
GetUserId(),
tupdesc,
NIL,
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200909221
+#define CATALOG_VERSION_NO 200909261
#endif
#
# note: we exclude BKI_BOOTSTRAP relations since they are expected to have
-# matching DATA lines in pg_class.h
+# matching DATA lines in pg_class.h and pg_type.h
cat pg_*.h toasting.h indexing.h | \
egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \
sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \
+ -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \
-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
-e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
-e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
#define BKI_BOOTSTRAP
#define BKI_SHARED_RELATION
#define BKI_WITHOUT_OIDS
+#define BKI_ROWTYPE_OID(oid)
/* Declarations that provide the initial content of a catalog */
/* In C, these need to expand into some harmless, repeatable declaration */
Oid relnamespace,
Oid reltablespace,
Oid relid,
+ Oid reltypeid,
Oid ownerid,
TupleDesc tupdesc,
List *cooked_constraints,
* ----------------
*/
#define AttributeRelationId 1249
+#define AttributeRelation_Rowtype_Id 75
-CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS
+CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75)
{
Oid attrelid; /* OID of relation containing this attribute */
NameData attname; /* name of attribute */
* ----------------
*/
#define RelationRelationId 1259
+#define RelationRelation_Rowtype_Id 83
-CATALOG(pg_class,1259) BKI_BOOTSTRAP
+CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83)
{
NameData relname; /* class name */
Oid relnamespace; /* OID of namespace containing this class */
* ----------------
*/
#define DatabaseRelationId 1262
+#define DatabaseRelation_Rowtype_Id 1248
-CATALOG(pg_database,1262) BKI_SHARED_RELATION
+CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248)
{
NameData datname; /* database name */
Oid datdba; /* owner of database */
* ----------------
*/
#define ProcedureRelationId 1255
+#define ProcedureRelation_Rowtype_Id 81
-CATALOG(pg_proc,1255) BKI_BOOTSTRAP
+CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81)
{
NameData proname; /* procedure name */
Oid pronamespace; /* OID of namespace containing this proc */
* ----------------
*/
#define TypeRelationId 1247
+#define TypeRelation_Rowtype_Id 71
-CATALOG(pg_type,1247) BKI_BOOTSTRAP
+CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71)
{
NameData typname; /* type name */
Oid typnamespace; /* OID of namespace containing this type */
DESCR("array of oids, used in system tables");
#define OIDVECTOROID 30
-/* hand-built rowtype entries for bootstrapped catalogs: */
+/* hand-built rowtype entries for bootstrapped catalogs */
+/* NB: OIDs assigned here must match the BKI_ROWTYPE_OID declarations */
DATA(insert OID = 71 ( pg_type PGNSP PGUID -1 f c C f t \054 1247 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 _null_ _null_ ));
DATA(insert OID = 75 ( pg_attribute PGNSP PGUID -1 f c C f t \054 1249 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 _null_ _null_ ));
# this part (down to the uniq step) should match the duplicate_oids script
# note: we exclude BKI_BOOTSTRAP relations since they are expected to have
-# matching DATA lines in pg_class.h
+# matching DATA lines in pg_class.h and pg_type.h
cat pg_*.h toasting.h indexing.h | \
egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \
sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \
+ -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \
-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
-e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
-e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
my $bootstrap = "";
my $shared_relation = "";
my $without_oids = "";
+ my $rowtype_oid = "";
my $nc = 0;
my $inside = 0;
my @attr;
my @fields = split /,/,$1;
$catalog = $fields[0];
$oid = $fields[1];
- $bootstrap=$shared_relation=$without_oids="";
+ $bootstrap=$shared_relation=$without_oids=$rowtype_oid="";
if ($rest =~ /BKI_BOOTSTRAP/)
{
- $bootstrap = "bootstrap ";
+ $bootstrap = " bootstrap";
}
if ($rest =~ /BKI_SHARED_RELATION/)
{
- $shared_relation = "shared_relation ";
+ $shared_relation = " shared_relation";
}
if ($rest =~ /BKI_WITHOUT_OIDS/)
{
- $without_oids = "without_oids ";
+ $without_oids = " without_oids";
+ }
+ if ($rest =~ /BKI_ROWTYPE_OID\((\d+)\)/)
+ {
+ $rowtype_oid = " rowtype_oid $1";
}
$nc++;
$inside = 1;
{
# Last line
- $bki .= "create $bootstrap$shared_relation$without_oids$catalog $oid\n (\n";
+ $bki .= "create $catalog $oid$bootstrap$shared_relation$without_oids$rowtype_oid\n\t(\n";
my $first = 1;
for (my $i = 0; $i <= $#attr; $i++)
{