Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * toasting.c
4 : : * This file contains routines to support creation of toast tables
5 : : *
6 : : *
7 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8 : : * Portions Copyright (c) 1994, Regents of the University of California
9 : : *
10 : : * IDENTIFICATION
11 : : * src/backend/catalog/toasting.c
12 : : *
13 : : *-------------------------------------------------------------------------
14 : : */
15 : : #include "postgres.h"
16 : :
17 : : #include "access/genam.h"
18 : : #include "access/heapam.h"
19 : : #include "access/toast_compression.h"
20 : : #include "access/xact.h"
21 : : #include "catalog/binary_upgrade.h"
22 : : #include "catalog/catalog.h"
23 : : #include "catalog/dependency.h"
24 : : #include "catalog/heap.h"
25 : : #include "catalog/index.h"
26 : : #include "catalog/namespace.h"
27 : : #include "catalog/pg_am.h"
28 : : #include "catalog/pg_namespace.h"
29 : : #include "catalog/pg_opclass.h"
30 : : #include "catalog/toasting.h"
31 : : #include "miscadmin.h"
32 : : #include "nodes/makefuncs.h"
33 : : #include "utils/fmgroids.h"
34 : : #include "utils/rel.h"
35 : : #include "utils/lsyscache.h"
36 : : #include "utils/syscache.h"
37 : :
38 : : static void CheckAndCreateToastTable(Oid relOid, Datum reloptions,
39 : : LOCKMODE lockmode, bool check,
40 : : Oid OIDOldToast);
41 : : static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
42 : : Datum reloptions, LOCKMODE lockmode, bool check,
43 : : Oid OIDOldToast);
44 : : static bool needs_toast_table(Relation rel);
45 : :
46 : :
47 : : /*
48 : : * CreateToastTable variants
49 : : * If the table needs a toast table, and doesn't already have one,
50 : : * then create a toast table for it.
51 : : *
52 : : * reloptions for the toast table can be passed, too. Pass (Datum) 0
53 : : * for default reloptions.
54 : : *
55 : : * We expect the caller to have verified that the relation is a table and have
56 : : * already done any necessary permission checks. Callers expect this function
57 : : * to end with CommandCounterIncrement if it makes any changes.
58 : : */
59 : : void
4550 simon@2ndQuadrant.co 60 :CBC 18897 : AlterTableCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode)
61 : : {
1852 akapila@postgresql.o 62 : 18897 : CheckAndCreateToastTable(relOid, reloptions, lockmode, true, InvalidOid);
4550 simon@2ndQuadrant.co 63 : 18897 : }
64 : :
65 : : void
1852 akapila@postgresql.o 66 : 595 : NewHeapCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode,
67 : : Oid OIDOldToast)
68 : : {
69 : 595 : CheckAndCreateToastTable(relOid, reloptions, lockmode, false, OIDOldToast);
4550 simon@2ndQuadrant.co 70 : 595 : }
71 : :
72 : : void
73 : 25492 : NewRelationCreateToastTable(Oid relOid, Datum reloptions)
74 : : {
1852 akapila@postgresql.o 75 : 25492 : CheckAndCreateToastTable(relOid, reloptions, AccessExclusiveLock, false,
76 : : InvalidOid);
4550 simon@2ndQuadrant.co 77 : 25492 : }
78 : :
79 : : static void
1852 akapila@postgresql.o 80 : 44984 : CheckAndCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode,
81 : : bool check, Oid OIDOldToast)
82 : : {
83 : : Relation rel;
84 : :
2799 andres@anarazel.de 85 : 44984 : rel = table_open(relOid, lockmode);
86 : :
87 : : /* create_toast_table does all the work */
1852 akapila@postgresql.o 88 : 44984 : (void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions, lockmode,
89 : : check, OIDOldToast);
90 : :
2799 andres@anarazel.de 91 : 44984 : table_close(rel, NoLock);
7356 tgl@sss.pgh.pa.us 92 : 44984 : }
93 : :
94 : : /*
95 : : * Create a toast table during bootstrap
96 : : *
97 : : * Here we need to prespecify the OIDs of the toast table and its index
98 : : */
99 : : void
100 : 2030 : BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
101 : : {
102 : : Relation rel;
103 : :
2799 andres@anarazel.de 104 : 2030 : rel = table_openrv(makeRangeVar(NULL, relName, -1), AccessExclusiveLock);
105 : :
4949 kgrittn@postgresql.o 106 [ - + ]: 2030 : if (rel->rd_rel->relkind != RELKIND_RELATION &&
4949 kgrittn@postgresql.o 107 [ # # ]:UBC 0 : rel->rd_rel->relkind != RELKIND_MATVIEW)
1900 peter@eisentraut.org 108 [ # # ]: 0 : elog(ERROR, "\"%s\" is not a table or materialized view",
109 : : relName);
110 : :
111 : : /* create_toast_table does all the work */
4550 simon@2ndQuadrant.co 112 [ - + ]:CBC 2030 : if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0,
113 : : AccessExclusiveLock, false, InvalidOid))
7356 tgl@sss.pgh.pa.us 114 [ # # ]:UBC 0 : elog(ERROR, "\"%s\" does not require a toast table",
115 : : relName);
116 : :
2799 andres@anarazel.de 117 :CBC 2030 : table_close(rel, NoLock);
7356 tgl@sss.pgh.pa.us 118 : 2030 : }
119 : :
120 : :
121 : : /*
122 : : * create_toast_table --- internal workhorse
123 : : *
124 : : * rel is already opened and locked
125 : : * toastOid and toastIndexOid are normally InvalidOid, but during
126 : : * bootstrap they can be nonzero to specify hand-assigned OIDs
127 : : */
128 : : static bool
4550 simon@2ndQuadrant.co 129 : 47014 : create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
130 : : Datum reloptions, LOCKMODE lockmode, bool check,
131 : : Oid OIDOldToast)
132 : : {
7356 tgl@sss.pgh.pa.us 133 : 47014 : Oid relOid = RelationGetRelid(rel);
134 : : HeapTuple reltup;
135 : : TupleDesc tupdesc;
136 : : bool shared_relation;
137 : : bool mapped_relation;
138 : : Relation toast_rel;
139 : : Relation class_rel;
140 : : Oid toast_relid;
141 : : Oid namespaceid;
142 : : char toast_relname[NAMEDATALEN];
143 : : char toast_idxname[NAMEDATALEN];
144 : : IndexInfo *indexInfo;
145 : : Oid collationIds[2];
146 : : Oid opclassIds[2];
147 : : int16 coloptions[2];
148 : : ObjectAddress baseobject,
149 : : toastobject;
9 michael@paquier.xyz 150 :GNC 47014 : Oid toast_chunkid_typid = OIDOID;
151 : :
152 : : /*
153 : : * Is it already toasted?
154 : : */
7356 tgl@sss.pgh.pa.us 155 [ + + ]:CBC 47014 : if (rel->rd_rel->reltoastrelid != InvalidOid)
156 : 6671 : return false;
157 : :
158 : : /*
159 : : * Check to see whether the table actually needs a TOAST table.
160 : : */
4427 bruce@momjian.us 161 [ + + ]: 40343 : if (!IsBinaryUpgrade)
162 : : {
163 : : StdRdOptToastValueType value_type;
164 : :
165 : : /* Normal mode, normal check */
166 [ + + ]: 38563 : if (!needs_toast_table(rel))
167 : 27801 : return false;
168 : :
9 michael@paquier.xyz 169 [ + + ]:GNC 10762 : value_type = RelationGetToastValueType(rel, STDRD_OPTION_TOAST_VALUE_TYPE_OID);
170 : :
171 : : /* no default clause to catch new values added */
172 [ + + - - ]: 10762 : switch (value_type)
173 : : {
174 : 10731 : case STDRD_OPTION_TOAST_VALUE_TYPE_OID:
175 : 10731 : toast_chunkid_typid = OIDOID;
176 : 10731 : break;
5 177 : 31 : case STDRD_OPTION_TOAST_VALUE_TYPE_OID8:
178 : 31 : toast_chunkid_typid = OID8OID;
179 : 31 : break;
9 michael@paquier.xyz 180 :UNC 0 : case STDRD_OPTION_TOAST_VALUE_TYPE_INVALID:
181 [ # # ]: 0 : elog(ERROR, "unexpected toast_value_type value %d",
182 : : value_type);
183 : : break;
184 : : }
185 : : }
186 : : else
187 : : {
188 : : /*
189 : : * In binary-upgrade mode, create a TOAST table if and only if
190 : : * pg_upgrade told us to (ie, a TOAST table OID has been provided).
191 : : *
192 : : * This indicates that the old cluster had a TOAST table for the
193 : : * current table. We must create a TOAST table to receive the old
194 : : * TOAST file, even if the table seems not to need one.
195 : : *
196 : : * Contrariwise, if the old cluster did not have a TOAST table, we
197 : : * should be able to get along without one even if the new version's
198 : : * needs_toast_table rules suggest we should have one. There is a lot
199 : : * of daylight between where we will create a TOAST table and where
200 : : * one is really necessary to avoid failures, so small cross-version
201 : : * differences in the when-to-create heuristic shouldn't be a problem.
202 : : * If we tried to create a TOAST table anyway, we would have the
203 : : * problem that it might take up an OID that will conflict with some
204 : : * old-cluster table we haven't seen yet.
205 : : */
2266 tgl@sss.pgh.pa.us 206 [ + + ]:CBC 1780 : if (!OidIsValid(binary_upgrade_next_toast_pg_class_oid))
4427 bruce@momjian.us 207 : 1502 : return false;
208 : :
209 : : /*
210 : : * The attribute type for chunk_id should have been set when
211 : : * requesting a TOAST table creation.
212 : : */
9 michael@paquier.xyz 213 [ - + ]:GNC 278 : if (!OidIsValid(binary_upgrade_next_toast_chunk_id_typoid))
9 michael@paquier.xyz 214 [ # # ]:UNC 0 : ereport(ERROR,
215 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
216 : : errmsg("toast chunk_id type not set while in binary upgrade mode")));
5 michael@paquier.xyz 217 [ + + ]:GNC 278 : if (binary_upgrade_next_toast_chunk_id_typoid != OIDOID &&
218 [ - + ]: 1 : binary_upgrade_next_toast_chunk_id_typoid != OID8OID)
9 michael@paquier.xyz 219 [ # # ]:UNC 0 : ereport(ERROR,
220 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
221 : : errmsg("cannot support toast chunk_id type %u in binary upgrade mode",
222 : : binary_upgrade_next_toast_chunk_id_typoid)));
223 : :
9 michael@paquier.xyz 224 :GNC 278 : toast_chunkid_typid = binary_upgrade_next_toast_chunk_id_typoid;
225 : 278 : binary_upgrade_next_toast_chunk_id_typoid = InvalidOid;
226 : : }
227 : :
228 : : /*
229 : : * If requested check lockmode is sufficient. This is a cross check in
230 : : * case of errors or conflicting decisions in earlier code.
231 : : */
4550 simon@2ndQuadrant.co 232 [ + + - + ]:CBC 11040 : if (check && lockmode != AccessExclusiveLock)
4550 simon@2ndQuadrant.co 233 [ # # ]:UBC 0 : elog(ERROR, "AccessExclusiveLock required to add toast table.");
234 : :
235 : : /*
236 : : * Create the toast table and its index
237 : : */
7356 tgl@sss.pgh.pa.us 238 :CBC 11040 : snprintf(toast_relname, sizeof(toast_relname),
239 : : "pg_toast_%u", relOid);
240 : 11040 : snprintf(toast_idxname, sizeof(toast_idxname),
241 : : "pg_toast_%u_index", relOid);
242 : :
243 : : /*
244 : : * Special case here. If OIDOldToast is defined, rely on the existing
245 : : * TOAST table and its chunk_id type, not the reloption value. This
246 : : * guarantees that the same TOAST table is kept across rewrites of the
247 : : * parent.
248 : : */
5 michael@paquier.xyz 249 [ + + ]:GNC 11040 : if (OidIsValid(OIDOldToast))
250 : : {
251 : 570 : toast_chunkid_typid = get_atttype(OIDOldToast, 1);
252 [ - + ]: 570 : if (!OidIsValid(toast_chunkid_typid))
5 michael@paquier.xyz 253 [ # # ]:UNC 0 : elog(ERROR, "cache lookup failed for relation %u", OIDOldToast);
254 : : }
255 : :
256 : : /* this is pretty painful... need a tuple descriptor */
2861 andres@anarazel.de 257 :CBC 11040 : tupdesc = CreateTemplateTupleDesc(3);
7356 tgl@sss.pgh.pa.us 258 : 11040 : TupleDescInitEntry(tupdesc, (AttrNumber) 1,
259 : : "chunk_id",
260 : : toast_chunkid_typid,
261 : : -1, 0);
262 : 11040 : TupleDescInitEntry(tupdesc, (AttrNumber) 2,
263 : : "chunk_seq",
264 : : INT4OID,
265 : : -1, 0);
266 : 11040 : TupleDescInitEntry(tupdesc, (AttrNumber) 3,
267 : : "chunk_data",
268 : : BYTEAOID,
269 : : -1, 0);
270 : :
271 : : /*
272 : : * Ensure that the toast table doesn't itself get toasted, or we'll be
273 : : * toast :-(. This is essential for chunk_data because type bytea is
274 : : * toastable; hit the other two just to be sure.
275 : : */
2391 276 : 11040 : TupleDescAttr(tupdesc, 0)->attstorage = TYPSTORAGE_PLAIN;
277 : 11040 : TupleDescAttr(tupdesc, 1)->attstorage = TYPSTORAGE_PLAIN;
278 : 11040 : TupleDescAttr(tupdesc, 2)->attstorage = TYPSTORAGE_PLAIN;
279 : :
280 : : /* Toast field should not be compressed */
2011 rhaas@postgresql.org 281 : 11040 : TupleDescAttr(tupdesc, 0)->attcompression = InvalidCompressionMethod;
282 : 11040 : TupleDescAttr(tupdesc, 1)->attcompression = InvalidCompressionMethod;
283 : 11040 : TupleDescAttr(tupdesc, 2)->attcompression = InvalidCompressionMethod;
284 : :
188 drowley@postgresql.o 285 : 11040 : populate_compact_attribute(tupdesc, 0);
286 : 11040 : populate_compact_attribute(tupdesc, 1);
287 : 11040 : populate_compact_attribute(tupdesc, 2);
288 : :
289 : 11040 : TupleDescFinalize(tupdesc);
290 : :
291 : : /*
292 : : * Toast tables for regular relations go in pg_toast; those for temp
293 : : * relations go into the per-backend temp-toast-table namespace.
294 : : */
4409 bruce@momjian.us 295 [ + + ]: 11040 : if (isTempOrTempToastNamespace(rel->rd_rel->relnamespace))
6997 tgl@sss.pgh.pa.us 296 : 670 : namespaceid = GetTempToastNamespace();
297 : : else
298 : 10370 : namespaceid = PG_TOAST_NAMESPACE;
299 : :
300 : : /* Toast table is shared if and only if its parent is. */
2742 peter@eisentraut.org 301 : 11040 : shared_relation = rel->rd_rel->relisshared;
302 : :
303 : : /* It's mapped if and only if its parent is, too */
304 [ + + + - : 11040 : mapped_relation = RelationIsMapped(rel);
+ - + - +
- + + ]
305 : :
7356 tgl@sss.pgh.pa.us 306 : 22080 : toast_relid = heap_create_with_catalog(toast_relname,
307 : : namespaceid,
308 : 11040 : rel->rd_rel->reltablespace,
309 : : toastOid,
310 : : InvalidOid,
311 : : InvalidOid,
312 : 11040 : rel->rd_rel->relowner,
313 : : table_relation_toast_am(rel),
314 : : tupdesc,
315 : : NIL,
316 : : RELKIND_TOASTVALUE,
5760 rhaas@postgresql.org 317 : 11040 : rel->rd_rel->relpersistence,
318 : : shared_relation,
319 : : mapped_relation,
320 : : ONCOMMIT_NOOP,
321 : : reloptions,
322 : : false,
323 : : true,
324 : : true,
325 : : OIDOldToast,
326 : : NULL);
5901 327 [ - + ]: 11040 : Assert(toast_relid != InvalidOid);
328 : :
329 : : /* make the toast relation visible, else table_open will fail */
7356 tgl@sss.pgh.pa.us 330 : 11040 : CommandCounterIncrement();
331 : :
332 : : /* ShareLock is not really needed here, but take it anyway */
2799 andres@anarazel.de 333 : 11040 : toast_rel = table_open(toast_relid, ShareLock);
334 : :
335 : : /*
336 : : * Create unique index on chunk_id, chunk_seq.
337 : : *
338 : : * NOTE: the normal TOAST access routines could actually function with a
339 : : * single-column index on chunk_id only. However, the slice access
340 : : * routines use both columns for faster access to an individual chunk. In
341 : : * addition, we want it to be unique as a check against the possibility of
342 : : * duplicate TOAST chunk OIDs. The index might also be a little more
343 : : * efficient this way, since btree isn't all that happy with large numbers
344 : : * of equal keys.
345 : : */
346 : :
7356 tgl@sss.pgh.pa.us 347 : 11040 : indexInfo = makeNode(IndexInfo);
348 : 11040 : indexInfo->ii_NumIndexAttrs = 2;
3088 teodor@sigaev.ru 349 : 11040 : indexInfo->ii_NumIndexKeyAttrs = 2;
3083 350 : 11040 : indexInfo->ii_IndexAttrNumbers[0] = 1;
351 : 11040 : indexInfo->ii_IndexAttrNumbers[1] = 2;
7356 tgl@sss.pgh.pa.us 352 : 11040 : indexInfo->ii_Expressions = NIL;
353 : 11040 : indexInfo->ii_ExpressionsState = NIL;
354 : 11040 : indexInfo->ii_Predicate = NIL;
3477 andres@anarazel.de 355 : 11040 : indexInfo->ii_PredicateState = NULL;
6131 tgl@sss.pgh.pa.us 356 : 11040 : indexInfo->ii_ExclusionOps = NULL;
357 : 11040 : indexInfo->ii_ExclusionProcs = NULL;
358 : 11040 : indexInfo->ii_ExclusionStrats = NULL;
7356 359 : 11040 : indexInfo->ii_Unique = true;
1690 peter@eisentraut.org 360 : 11040 : indexInfo->ii_NullsNotDistinct = false;
6940 tgl@sss.pgh.pa.us 361 : 11040 : indexInfo->ii_ReadyForInserts = true;
1712 pg@bowt.ie 362 : 11040 : indexInfo->ii_CheckedUnchanged = false;
363 : 11040 : indexInfo->ii_IndexUnchanged = false;
7331 tgl@sss.pgh.pa.us 364 : 11040 : indexInfo->ii_Concurrent = false;
6940 365 : 11040 : indexInfo->ii_BrokenHotChain = false;
3152 rhaas@postgresql.org 366 : 11040 : indexInfo->ii_ParallelWorkers = 0;
3166 alvherre@alvh.no-ip. 367 : 11040 : indexInfo->ii_Am = BTREE_AM_OID;
3510 tgl@sss.pgh.pa.us 368 : 11040 : indexInfo->ii_AmCache = NULL;
369 : 11040 : indexInfo->ii_Context = CurrentMemoryContext;
370 : :
1124 peter@eisentraut.org 371 : 11040 : collationIds[0] = InvalidOid;
372 : 11040 : collationIds[1] = InvalidOid;
373 : :
5 michael@paquier.xyz 374 [ + + ]:GNC 11040 : if (toast_chunkid_typid == OID8OID)
375 : 32 : opclassIds[0] = OID8_BTREE_OPS_OID;
376 : : else
377 : 11008 : opclassIds[0] = OID_BTREE_OPS_OID;
1124 peter@eisentraut.org 378 :CBC 11040 : opclassIds[1] = INT4_BTREE_OPS_OID;
379 : :
7194 tgl@sss.pgh.pa.us 380 : 11040 : coloptions[0] = 0;
381 : 11040 : coloptions[1] = 0;
382 : :
383 : : /*
384 : : * Don't let index creation overwrite progress information for the command
385 : : * that caused the TOAST table to be created.
386 : : */
5543 rhaas@postgresql.org 387 : 11040 : index_create(toast_rel, toast_idxname, toastIndexOid, InvalidOid,
388 : : InvalidOid, InvalidOid,
389 : : indexInfo,
5582 bruce@momjian.us 390 : 11040 : list_make2("chunk_id", "chunk_seq"),
391 : : BTREE_AM_OID,
392 : 11040 : rel->rd_rel->reltablespace,
393 : : collationIds, opclassIds, NULL, coloptions, NULL, (Datum) 0,
394 : : INDEX_CREATE_IS_PRIMARY | INDEX_CREATE_SUPPRESS_PROGRESS,
395 : : 0, true, true, NULL);
396 : :
2799 andres@anarazel.de 397 : 11040 : table_close(toast_rel, NoLock);
398 : :
399 : : /*
400 : : * Store the toast table's OID in the parent relation's pg_class row
401 : : */
402 : 11040 : class_rel = table_open(RelationRelationId, RowExclusiveLock);
403 : :
7356 tgl@sss.pgh.pa.us 404 [ + + ]: 11040 : if (!IsBootstrapProcessingMode())
405 : : {
406 : : /* normal case, use a transactional update */
726 noah@leadboat.com 407 : 9010 : reltup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relOid));
408 [ - + ]: 9010 : if (!HeapTupleIsValid(reltup))
726 noah@leadboat.com 409 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for relation %u", relOid);
410 : :
726 noah@leadboat.com 411 :CBC 9010 : ((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid;
412 : :
3519 alvherre@alvh.no-ip. 413 : 9010 : CatalogTupleUpdate(class_rel, &reltup->t_self, reltup);
414 : : }
415 : : else
416 : : {
417 : : /* While bootstrapping, we cannot UPDATE, so overwrite in-place */
418 : :
419 : : ScanKeyData key[1];
420 : : void *state;
421 : :
726 noah@leadboat.com 422 : 2030 : ScanKeyInit(&key[0],
423 : : Anum_pg_class_oid,
424 : : BTEqualStrategyNumber, F_OIDEQ,
425 : : ObjectIdGetDatum(relOid));
426 : 2030 : systable_inplace_update_begin(class_rel, ClassOidIndexId, true,
427 : : NULL, 1, key, &reltup, &state);
428 [ - + ]: 2030 : if (!HeapTupleIsValid(reltup))
726 noah@leadboat.com 429 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for relation %u", relOid);
430 : :
726 noah@leadboat.com 431 :CBC 2030 : ((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid;
432 : :
433 : 2030 : systable_inplace_update_finish(state, reltup);
434 : : }
435 : :
7356 tgl@sss.pgh.pa.us 436 : 11040 : heap_freetuple(reltup);
437 : :
2799 andres@anarazel.de 438 : 11040 : table_close(class_rel, RowExclusiveLock);
439 : :
440 : : /*
441 : : * Register dependency from the toast table to the main, so that the toast
442 : : * table will be deleted if the main is. Skip this in bootstrap mode.
443 : : */
7356 tgl@sss.pgh.pa.us 444 [ + + ]: 11040 : if (!IsBootstrapProcessingMode())
445 : : {
446 : 9010 : baseobject.classId = RelationRelationId;
447 : 9010 : baseobject.objectId = relOid;
448 : 9010 : baseobject.objectSubId = 0;
449 : 9010 : toastobject.classId = RelationRelationId;
450 : 9010 : toastobject.objectId = toast_relid;
451 : 9010 : toastobject.objectSubId = 0;
452 : :
453 : 9010 : recordDependencyOn(&toastobject, &baseobject, DEPENDENCY_INTERNAL);
454 : : }
455 : :
456 : : /*
457 : : * Make changes visible
458 : : */
459 : 11040 : CommandCounterIncrement();
460 : :
461 : 11040 : return true;
462 : : }
463 : :
464 : : /*
465 : : * Check to see whether the table needs a TOAST table.
466 : : */
467 : : static bool
468 : 38563 : needs_toast_table(Relation rel)
469 : : {
470 : : /*
471 : : * No need to create a TOAST table for partitioned tables.
472 : : */
3104 rhaas@postgresql.org 473 [ + + ]: 38563 : if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
474 : 5541 : return false;
475 : :
476 : : /*
477 : : * We cannot allow toasting a shared relation after initdb (because
478 : : * there's no way to mark it toasted in other databases' pg_class).
479 : : */
2742 peter@eisentraut.org 480 [ + + + + ]: 33022 : if (rel->rd_rel->relisshared && !IsBootstrapProcessingMode())
481 : 392 : return false;
482 : :
483 : : /*
484 : : * Ignore attempts to create toast tables on catalog tables after initdb.
485 : : * Which catalogs get toast tables is explicitly chosen in catalog/pg_*.h.
486 : : * (We could get here via some ALTER TABLE command if the catalog doesn't
487 : : * have a toast table.)
488 : : */
489 [ + + + + ]: 32630 : if (IsCatalogRelation(rel) && !IsBootstrapProcessingMode())
490 : 2520 : return false;
491 : :
492 : : /* Otherwise, let the AM decide. */
2679 rhaas@postgresql.org 493 : 30110 : return table_relation_needs_toast_table(rel);
494 : : }
|