summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-05-07 22:58:28 +0000
committerTom Lane2009-05-07 22:58:28 +0000
commitda129ba009b894f14cc917028408e4fdef972219 (patch)
tree7b9664f07b1a0b208969acd817abf7bdc86d6fad
parenta036a849edd1bae8bb866bf530ac3b6032034e95 (diff)
Add an option to AlterTableCreateToastTable() to allow its caller to force
a toast table to be built, even if the sum-of-column-widths calculation indicates one isn't needed. This is needed by pg_migrator because if the old table has a toast table, we have to migrate over the toast table since it might contain some live data, even though subsequent column drops could mean that no recently-added rows could require toasting.
-rw-r--r--src/backend/catalog/toasting.c23
-rw-r--r--src/backend/commands/cluster.c2
-rw-r--r--src/backend/commands/tablecmds.c2
-rw-r--r--src/backend/executor/execMain.c2
-rw-r--r--src/backend/tcop/utility.c7
-rw-r--r--src/include/catalog/toasting.h2
6 files changed, 25 insertions, 13 deletions
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index e87cc2e84b..bca0c450a8 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -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 ba1cda6a63..215bbb3e69 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -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 0ba4c2c983..13b30d419b 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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 7931926a34..60ec27ccde 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -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 80070e39b2..c302c950e8 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -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 4024103a5f..765ca98236 100644
--- a/src/include/catalog/toasting.h
+++ b/src/include/catalog/toasting.h
@@ -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);