Revisit AlterTableCreateToastTable's API once again, hoping to make it what
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 11 Jun 2009 20:46:11 +0000 (20:46 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 11 Jun 2009 20:46:11 +0000 (20:46 +0000)
pg_migrator actually needs and not just a partial solution.  We have to be
able to specify the OID that the new toast table should be created with.

src/backend/catalog/toasting.c
src/backend/commands/cluster.c
src/backend/commands/tablecmds.c
src/backend/executor/execMain.c
src/backend/tcop/utility.c
src/include/catalog/toasting.h

index 3395f87a4f6ba910dc1244df025a30c4efc67279..6e7b5cfed55119533bf6ceb37ab9cb5b0986b047 100644 (file)
@@ -43,6 +43,11 @@ static bool needs_toast_table(Relation rel);
  *             then create a toast table for it.  (With the force option, make
  *             a toast table even if it appears unnecessary.)
  *
+ * The caller can also specify the OID to be used for the toast table.
+ * Usually, toastOid should be InvalidOid to allow a free OID to be assigned.
+ * (This option, as well as the force option, is not used by core Postgres,
+ * but is provided to support pg_migrator.)
+ *
  * reloptions for the toast table can be passed, too.  Pass (Datum) 0
  * for default reloptions.
  *
@@ -51,7 +56,8 @@ static bool needs_toast_table(Relation rel);
  * to end with CommandCounterIncrement if it makes any changes.
  */
 void
-AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force)
+AlterTableCreateToastTable(Oid relOid, Oid toastOid,
+                                                  Datum reloptions, bool force)
 {
        Relation        rel;
 
@@ -63,7 +69,7 @@ AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force)
        rel = heap_open(relOid, AccessExclusiveLock);
 
        /* create_toast_table does all the work */
-       (void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions, force);
+       (void) create_toast_table(rel, toastOid, InvalidOid, reloptions, force);
 
        heap_close(rel, NoLock);
 }
@@ -101,8 +107,8 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
  * create_toast_table --- internal workhorse
  *
  * rel is already opened and exclusive-locked
- * toastOid and toastIndexOid are normally InvalidOid, but during
- * bootstrap they can be nonzero to specify hand-assigned OIDs
+ * toastOid and toastIndexOid are normally InvalidOid, but
+ * either or both can be nonzero to specify caller-assigned OIDs
  */
 static bool
 create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
index e68b1cacf1cb844a95411434184cecdbdae3e159..a6ba2ec3cb3e3dc27632d63a5eacab7f1c296291 100644 (file)
@@ -741,7 +741,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace)
                if (isNull)
                        reloptions = (Datum) 0;
        }
-       AlterTableCreateToastTable(OIDNewHeap, reloptions, false);
+       AlterTableCreateToastTable(OIDNewHeap, InvalidOid, reloptions, false);
 
        if (OidIsValid(toastid))
                ReleaseSysCache(tuple);
index 36a4a04f1c398f33815db3694469fb1d2215a818..9401c18d92dc6bc6a6571cebab7f82f2f68bf6b2 100644 (file)
@@ -2585,7 +2585,8 @@ ATRewriteCatalogs(List **wqueue)
                        (tab->subcmds[AT_PASS_ADD_COL] ||
                         tab->subcmds[AT_PASS_ALTER_TYPE] ||
                         tab->subcmds[AT_PASS_COL_ATTRS]))
-                       AlterTableCreateToastTable(tab->relid, (Datum) 0, false);
+                       AlterTableCreateToastTable(tab->relid, InvalidOid,
+                                                                          (Datum) 0, false);
        }
 }
 
index 13c1c14f2213a6e10bad80eddd5426375ab76747..ca16d100671e802def6717f2c0a21e906cf98d26 100644 (file)
@@ -2953,7 +2953,7 @@ OpenIntoRel(QueryDesc *queryDesc)
 
        (void) heap_reloptions(RELKIND_TOASTVALUE, reloptions, true);
 
-       AlterTableCreateToastTable(intoRelationId, reloptions, false);
+       AlterTableCreateToastTable(intoRelationId, InvalidOid, reloptions, false);
 
        /*
         * And open the constructed table for writing.
index 58cb4b8630c17ad021d98f28cbeccc1af709b62b..e6744bf4f3597f46e9c6b42a52912df7002a4077 100644 (file)
@@ -447,6 +447,7 @@ ProcessUtility(Node *parsetree,
                                                                                           true);
 
                                                AlterTableCreateToastTable(relOid,
+                                                                                                  InvalidOid,
                                                                                                   toast_options,
                                                                                                   false);
                                        }
index 765ca98236c2ab847b0137a42e3e30c44766ed7c..bd6e0cf5c8c24319b240452d5bd42dde5506ce9e 100644 (file)
@@ -17,7 +17,8 @@
 /*
  * toasting.c prototypes
  */
-extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force);
+extern void AlterTableCreateToastTable(Oid relOid, Oid toastOid,
+                                                  Datum reloptions, bool force);
 extern void BootstrapToastTable(char *relName,
                                        Oid toastOid, Oid toastIndexOid);