diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c index 5574b448ed64d28267806d01d6cc703d6202e0ef..ff9499ca35bf534d81e5d864b14680a2b765f934 100644 --- a/src/backend/catalog/toasting.c +++ b/src/backend/catalog/toasting.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.14 2009/03/31 22:12:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.15 2009/05/07 22:58:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -33,21 +33,25 @@ static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, - Datum reloptions); + Datum reloptions, bool force); static bool needs_toast_table(Relation rel); /* * AlterTableCreateToastTable * If the table needs a toast table, and doesn't already have one, - * then create a toast table for it. + * then create a toast table for it. (With the force option, make + * a toast table even if it appears unnecessary.) + * + * reloptions for the toast table can be passed, too. Pass (Datum) 0 + * for default reloptions. * * We expect the caller to have verified that the relation is a table and have * already done any necessary permission checks. Callers expect this function * to end with CommandCounterIncrement if it makes any changes. */ void -AlterTableCreateToastTable(Oid relOid, Datum reloptions) +AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force) { Relation rel; @@ -59,7 +63,7 @@ AlterTableCreateToastTable(Oid relOid, Datum reloptions) rel = heap_open(relOid, AccessExclusiveLock); /* create_toast_table does all the work */ - (void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions); + (void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions, force); heap_close(rel, NoLock); } @@ -85,7 +89,7 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid) relName))); /* create_toast_table does all the work */ - if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0)) + if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0, false)) elog(ERROR, "\"%s\" does not require a toast table", relName); @@ -101,7 +105,8 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid) * bootstrap they can be nonzero to specify hand-assigned OIDs */ static bool -create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptions) +create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, + Datum reloptions, bool force) { Oid relOid = RelationGetRelid(rel); HeapTuple reltup; @@ -139,8 +144,12 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio /* * Check to see whether the table actually needs a TOAST table. + * + * Caller can optionally override this check. (Note: at present + * no callers in core Postgres do so, but this option is needed by + * pg_migrator.) */ - if (!needs_toast_table(rel)) + if (!force && !needs_toast_table(rel)) return false; /* diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 18f316dd517666a628a19b85d3c1a0af8d01b598..08c09ed435ec1e47e38f92ecdea48265c24cc1c7 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.183 2009/03/31 22:12:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.184 2009/05/07 22:58:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -741,7 +741,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace) if (isNull) reloptions = (Datum) 0; } - AlterTableCreateToastTable(OIDNewHeap, reloptions); + AlterTableCreateToastTable(OIDNewHeap, reloptions, false); if (OidIsValid(toastid)) ReleaseSysCache(tuple); diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 25c58fbbd45c002ba848a45434dbff32b2274099..b910497f1502bcf260547793f888ca184892172e 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.281 2009/03/31 22:12:47 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.282 2009/05/07 22:58:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2584,7 +2584,7 @@ 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); + AlterTableCreateToastTable(tab->relid, (Datum) 0, false); } } diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 2ff4150f601a1af4225c30629bf5e366ca7e022e..03461a235af89e94fcc413e62e15efb43a9bc415 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.323 2009/02/08 18:02:27 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.324 2009/05/07 22:58:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2953,7 +2953,7 @@ OpenIntoRel(QueryDesc *queryDesc) (void) heap_reloptions(RELKIND_TOASTVALUE, reloptions, true); - AlterTableCreateToastTable(intoRelationId, reloptions); + AlterTableCreateToastTable(intoRelationId, reloptions, false); /* * And open the constructed table for writing. diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 6c6b13e17ef43c00a40df86c6c6136b5242c0a83..63aca25ebdf42478dd2b302d385f86846cc5edd5 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.306 2009/02/02 19:31:39 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.307 2009/05/07 22:58:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -442,10 +442,13 @@ ProcessUtility(Node *parsetree, "toast", validnsps, true, false); - (void) heap_reloptions(RELKIND_TOASTVALUE, toast_options, + (void) heap_reloptions(RELKIND_TOASTVALUE, + toast_options, true); - AlterTableCreateToastTable(relOid, toast_options); + AlterTableCreateToastTable(relOid, + toast_options, + false); } else { diff --git a/src/include/catalog/toasting.h b/src/include/catalog/toasting.h index 2d5eb61d29a16e49128a44f7d73b1ba2c2dbf9d8..f363cb0cae62a64f6ad354a5cb6a7474c0fede24 100644 --- a/src/include/catalog/toasting.h +++ b/src/include/catalog/toasting.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/toasting.h,v 1.6 2009/02/02 19:31:40 alvherre Exp $ + * $PostgreSQL: pgsql/src/include/catalog/toasting.h,v 1.7 2009/05/07 22:58:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,7 +17,7 @@ /* * toasting.c prototypes */ -extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions); +extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force); extern void BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid);