8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
33
33
34
34
35
35
static bool create_toast_table (Relation rel , Oid toastOid , Oid toastIndexOid ,
36
- Datum reloptions );
36
+ Datum reloptions , bool force );
37
37
static bool needs_toast_table (Relation rel );
38
38
39
39
40
40
/*
41
41
* AlterTableCreateToastTable
42
42
* 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.
44
48
*
45
49
* We expect the caller to have verified that the relation is a table and have
46
50
* already done any necessary permission checks. Callers expect this function
47
51
* to end with CommandCounterIncrement if it makes any changes.
48
52
*/
49
53
void
50
- AlterTableCreateToastTable (Oid relOid , Datum reloptions )
54
+ AlterTableCreateToastTable (Oid relOid , Datum reloptions , bool force )
51
55
{
52
56
Relation rel ;
53
57
@@ -59,7 +63,7 @@ AlterTableCreateToastTable(Oid relOid, Datum reloptions)
59
63
rel = heap_open (relOid , AccessExclusiveLock );
60
64
61
65
/* 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 );
63
67
64
68
heap_close (rel , NoLock );
65
69
}
@@ -85,7 +89,7 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
85
89
relName )));
86
90
87
91
/* 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 ))
89
93
elog (ERROR , "\"%s\" does not require a toast table" ,
90
94
relName );
91
95
@@ -101,7 +105,8 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
101
105
* bootstrap they can be nonzero to specify hand-assigned OIDs
102
106
*/
103
107
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 )
105
110
{
106
111
Oid relOid = RelationGetRelid (rel );
107
112
HeapTuple reltup ;
@@ -139,8 +144,12 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
139
144
140
145
/*
141
146
* 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.)
142
151
*/
143
- if (!needs_toast_table (rel ))
152
+ if (!force && ! needs_toast_table (rel ))
144
153
return false;
145
154
146
155
/*
0 commit comments