Rejigger things so that indexes don't go through heap_create().
authorRobert Haas <rhaas@postgresql.org>
Wed, 13 Jun 2012 18:58:04 +0000 (14:58 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 14 Jun 2012 14:33:05 +0000 (10:33 -0400)
src/backend/bootstrap/bootparse.y
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/utils/cache/relcache.c
src/include/catalog/heap.h

index 18f0add852e7832739e3877811e385abcb540fab..9655bfd2b0d3267f37555058a57c7fb737359724 100644 (file)
@@ -217,7 +217,6 @@ Boot_CreateStmt:
                                                                                                   PG_CATALOG_NAMESPACE,
                                                                                                   shared_relation ? GLOBALTABLESPACE_OID : 0,
                                                                                                   $3,
-                                                                                                  InvalidOid,
                                                                                                   tupdesc,
                                                                                                   RELKIND_RELATION,
                                                                                                   RELPERSISTENCE_PERMANENT,
index c91df9003811d1ff24590e88271a3c579c4a52f1..cb162810f7e711c4d35feee1b20f8e81de200127 100644 (file)
@@ -224,10 +224,6 @@ SystemAttributeByName(const char *attname, bool relhasoids)
 /* ----------------------------------------------------------------
  *             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.
  * ----------------------------------------------------------------
@@ -237,7 +233,6 @@ heap_create(const char *relname,
                        Oid relnamespace,
                        Oid reltablespace,
                        Oid relid,
-                       Oid relfilenode,
                        TupleDesc tupDesc,
                        char relkind,
                        char relpersistence,
@@ -250,6 +245,9 @@ heap_create(const char *relname,
        /* 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.
@@ -281,28 +279,6 @@ heap_create(const char *relname,
                        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.
         */
@@ -310,7 +286,7 @@ heap_create(const char *relname,
                                                                         relnamespace,
                                                                         tupDesc,
                                                                         relid,
-                                                                        relfilenode,
+                                                                        relid,
                                                                         reltablespace,
                                                                         shared_relation,
                                                                         mapped_relation,
@@ -1106,7 +1082,6 @@ heap_create_with_catalog(const char *relname,
                                                           relnamespace,
                                                           reltablespace,
                                                           relid,
-                                                          InvalidOid,
                                                           tupdesc,
                                                           relkind,
                                                           relpersistence,
index 0c51923be86420edb0b3937a19fbaeebe9446980..d1c02180c20e6889ce989dadccd13e889ebf2629 100644 (file)
@@ -803,23 +803,32 @@ index_create(Relation heapRelation,
        }
 
        /*
-        * 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
index b187a4ebf082d5ddb8c8483462d5252558a17e5b..65e4372b11a6549ef1ce4d18a319b1ac5df9625e 100644 (file)
@@ -2428,6 +2428,19 @@ RelationBuildLocalRelation(const char *relname,
        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.
index bc8c63a15e1c72f3e999e021970919abc054636e..adb7ea2a1e08cc00766f8693e5840f7481b649aa 100644 (file)
@@ -41,7 +41,6 @@ extern Relation heap_create(const char *relname,
                        Oid relnamespace,
                        Oid reltablespace,
                        Oid relid,
-                       Oid relfilenode,
                        TupleDesc tupDesc,
                        char relkind,
                        char relpersistence,