/* ----------------------------------------------------------------
* heap_create - Create an uncataloged heap relation
*
- * Note API change: the caller must now always provide the OID
- * to use for the relation. The relfilenode may (and, normally,
- * should) be left unspecified.
- *
* rel->rd_rel is initialized by RelationBuildLocalRelation,
* and is mostly zeroes at return.
* ----------------------------------------------------------------
Oid relnamespace,
Oid reltablespace,
Oid relid,
- Oid relfilenode,
TupleDesc tupDesc,
char relkind,
char relpersistence,
/* The caller must have provided an OID for the relation. */
Assert(OidIsValid(relid));
+ /* Use index_create() for indexes. */
+ Assert(relkind != RELKIND_INDEX);
+
/*
* Decide if we need storage or not, and handle a couple other special
* cases for particular relkinds.
break;
}
- /*
- * Unless otherwise requested, the physical ID (relfilenode) is initially
- * the same as the logical ID (OID). When the caller did specify a
- * relfilenode, it already exists; do not attempt to create it.
- */
- if (OidIsValid(relfilenode))
- create_storage = false;
- else
- relfilenode = relid;
-
- /*
- * Never allow a pg_class entry to explicitly specify the database's
- * default tablespace in reltablespace; force it to zero instead. This
- * ensures that if the database is cloned with a different default
- * tablespace, the pg_class entry will still match where CREATE DATABASE
- * will put the physically copied relation.
- *
- * Yes, this is a bit of a hack.
- */
- if (reltablespace == MyDatabaseTableSpace)
- reltablespace = InvalidOid;
-
/*
* build the relcache entry.
*/
relnamespace,
tupDesc,
relid,
- relfilenode,
+ relid,
reltablespace,
shared_relation,
mapped_relation,
relnamespace,
reltablespace,
relid,
- InvalidOid,
tupdesc,
relkind,
relpersistence,
}
/*
- * create the index relation's relcache entry and physical disk file. (If
- * we fail further down, it's the smgr's responsibility to remove the disk
- * file again.)
- */
- indexRelation = heap_create(indexRelationName,
- namespaceId,
- tableSpaceId,
- indexRelationId,
- relFileNode,
- indexTupDesc,
- RELKIND_INDEX,
- relpersistence,
- shared_relation,
- mapped_relation);
+ * create the index relation's relcache entry.
+ */
+ indexRelation = RelationBuildLocalRelation(indexRelationName,
+ namespaceId,
+ indexTupDesc,
+ indexRelationId,
+ OidIsValid(relFileNode) ? relFileNode : indexRelationId,
+ tableSpaceId,
+ shared_relation,
+ mapped_relation,
+ relpersistence,
+ RELKIND_INDEX);
Assert(indexRelationId == RelationGetRelid(indexRelation));
+ /*
+ * create the physical disk file, unless the caller provided an existing
+ * relFileNode for reuse. (If we fail further down, it's the smgr's
+ * responsibility to remove the disk file again.)
+ */
+ if (!OidIsValid(relFileNode))
+ {
+ RelationOpenSmgr(indexRelation);
+ RelationCreateStorage(indexRelation->rd_node, relpersistence);
+ }
+
/*
* Obtain exclusive lock on it. Although no other backends can see it
* until we commit, this prevents deadlock-risk complaints from lock
bool nailit;
AssertArg(natts >= 0);
+ Assert(OidIsValid(relfilenode));
+
+ /*
+ * Never allow a pg_class entry to explicitly specify the database's
+ * default tablespace in reltablespace; force it to zero instead. This
+ * ensures that if the database is cloned with a different default
+ * tablespace, the pg_class entry will still match where CREATE DATABASE
+ * will put the physically copied relation.
+ *
+ * Yes, this is a bit of a hack.
+ */
+ if (reltablespace == MyDatabaseTableSpace)
+ reltablespace = InvalidOid;
/*
* check for creation of a rel that must be nailed in cache.