Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1e06ed1

Browse files
committed
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.
1 parent 48caf91 commit 1e06ed1

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

src/backend/catalog/toasting.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.14 2009/03/31 22:12:46 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.15 2009/05/07 22:58:28 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -33,21 +33,25 @@
3333

3434

3535
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
36-
Datum reloptions);
36+
Datum reloptions, bool force);
3737
static bool needs_toast_table(Relation rel);
3838

3939

4040
/*
4141
* AlterTableCreateToastTable
4242
* If the table needs a toast table, and doesn't already have one,
43-
* then create a toast table for it.
43+
* then create a toast table for it. (With the force option, make
44+
* a toast table even if it appears unnecessary.)
45+
*
46+
* reloptions for the toast table can be passed, too. Pass (Datum) 0
47+
* for default reloptions.
4448
*
4549
* We expect the caller to have verified that the relation is a table and have
4650
* already done any necessary permission checks. Callers expect this function
4751
* to end with CommandCounterIncrement if it makes any changes.
4852
*/
4953
void
50-
AlterTableCreateToastTable(Oid relOid, Datum reloptions)
54+
AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force)
5155
{
5256
Relation rel;
5357

@@ -59,7 +63,7 @@ AlterTableCreateToastTable(Oid relOid, Datum reloptions)
5963
rel = heap_open(relOid, AccessExclusiveLock);
6064

6165
/* create_toast_table does all the work */
62-
(void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions);
66+
(void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions, force);
6367

6468
heap_close(rel, NoLock);
6569
}
@@ -85,7 +89,7 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
8589
relName)));
8690

8791
/* create_toast_table does all the work */
88-
if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0))
92+
if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0, false))
8993
elog(ERROR, "\"%s\" does not require a toast table",
9094
relName);
9195

@@ -101,7 +105,8 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
101105
* bootstrap they can be nonzero to specify hand-assigned OIDs
102106
*/
103107
static bool
104-
create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptions)
108+
create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
109+
Datum reloptions, bool force)
105110
{
106111
Oid relOid = RelationGetRelid(rel);
107112
HeapTuple reltup;
@@ -139,8 +144,12 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
139144

140145
/*
141146
* Check to see whether the table actually needs a TOAST table.
147+
*
148+
* Caller can optionally override this check. (Note: at present
149+
* no callers in core Postgres do so, but this option is needed by
150+
* pg_migrator.)
142151
*/
143-
if (!needs_toast_table(rel))
152+
if (!force && !needs_toast_table(rel))
144153
return false;
145154

146155
/*

src/backend/commands/cluster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.183 2009/03/31 22:12:46 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.184 2009/05/07 22:58:28 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -741,7 +741,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace)
741741
if (isNull)
742742
reloptions = (Datum) 0;
743743
}
744-
AlterTableCreateToastTable(OIDNewHeap, reloptions);
744+
AlterTableCreateToastTable(OIDNewHeap, reloptions, false);
745745

746746
if (OidIsValid(toastid))
747747
ReleaseSysCache(tuple);

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.281 2009/03/31 22:12:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.282 2009/05/07 22:58:28 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2584,7 +2584,7 @@ ATRewriteCatalogs(List **wqueue)
25842584
(tab->subcmds[AT_PASS_ADD_COL] ||
25852585
tab->subcmds[AT_PASS_ALTER_TYPE] ||
25862586
tab->subcmds[AT_PASS_COL_ATTRS]))
2587-
AlterTableCreateToastTable(tab->relid, (Datum) 0);
2587+
AlterTableCreateToastTable(tab->relid, (Datum) 0, false);
25882588
}
25892589
}
25902590

src/backend/executor/execMain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.323 2009/02/08 18:02:27 tgl Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.324 2009/05/07 22:58:28 tgl Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -2953,7 +2953,7 @@ OpenIntoRel(QueryDesc *queryDesc)
29532953

29542954
(void) heap_reloptions(RELKIND_TOASTVALUE, reloptions, true);
29552955

2956-
AlterTableCreateToastTable(intoRelationId, reloptions);
2956+
AlterTableCreateToastTable(intoRelationId, reloptions, false);
29572957

29582958
/*
29592959
* And open the constructed table for writing.

src/backend/tcop/utility.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.306 2009/02/02 19:31:39 alvherre Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.307 2009/05/07 22:58:28 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -442,10 +442,13 @@ ProcessUtility(Node *parsetree,
442442
"toast",
443443
validnsps,
444444
true, false);
445-
(void) heap_reloptions(RELKIND_TOASTVALUE, toast_options,
445+
(void) heap_reloptions(RELKIND_TOASTVALUE,
446+
toast_options,
446447
true);
447448

448-
AlterTableCreateToastTable(relOid, toast_options);
449+
AlterTableCreateToastTable(relOid,
450+
toast_options,
451+
false);
449452
}
450453
else
451454
{

src/include/catalog/toasting.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/toasting.h,v 1.6 2009/02/02 19:31:40 alvherre Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/toasting.h,v 1.7 2009/05/07 22:58:28 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,7 +17,7 @@
1717
/*
1818
* toasting.c prototypes
1919
*/
20-
extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions);
20+
extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions, bool force);
2121
extern void BootstrapToastTable(char *relName,
2222
Oid toastOid, Oid toastIndexOid);
2323

0 commit comments

Comments
 (0)