MCPcopy Create free account
hub / github.com/apache/cloudberry / ATExecSetTableSpace

Function ATExecSetTableSpace

src/backend/commands/tablecmds.c:16392–16529  ·  view source on GitHub ↗

* Execute ALTER TABLE SET TABLESPACE for cases where there is no tuple * rewriting to be done, so we just want to copy the data as fast as possible. */

Source from the content-addressed store, hash-verified

16390 * rewriting to be done, so we just want to copy the data as fast as possible.
16391 */
16392static void
16393ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode)
16394{
16395 Relation rel;
16396 Oid reltoastrelid;
16397 Oid relaosegrelid = InvalidOid;
16398 Oid relaoblkdirrelid = InvalidOid;
16399 Oid relaoblkdiridxid = InvalidOid;
16400 Oid relaovisimaprelid = InvalidOid;
16401 Oid relaovisimapidxid = InvalidOid;
16402 Oid relbmrelid = InvalidOid;
16403 Oid relbmidxid = InvalidOid;
16404 Oid newrelfilenode;
16405 RelFileNode newrnode;
16406 List *reltoastidxids = NIL;
16407 ListCell *lc;
16408
16409 /*
16410 * Need lock here in case we are recursing to toast table or index
16411 */
16412 rel = relation_open(tableOid, lockmode);
16413
16414 /* Check first if relation can be moved to new tablespace */
16415 if (!CheckRelationTableSpaceMove(rel, newTableSpace))
16416 {
16417 InvokeObjectPostAlterHook(RelationRelationId,
16418 RelationGetRelid(rel), 0);
16419 relation_close(rel, NoLock);
16420 return;
16421 }
16422
16423 reltoastrelid = rel->rd_rel->reltoastrelid;
16424 /* Fetch the list of indexes on toast relation if necessary */
16425 if (OidIsValid(reltoastrelid))
16426 {
16427 Relation toastRel = relation_open(reltoastrelid, lockmode);
16428
16429 reltoastidxids = RelationGetIndexList(toastRel);
16430 relation_close(toastRel, lockmode);
16431 }
16432
16433 /* Get the ao sub objects */
16434 if (RelationStorageIsAO(rel))
16435 GetAppendOnlyEntryAuxOids(rel,
16436 &relaosegrelid,
16437 &relaoblkdirrelid, &relaoblkdiridxid,
16438 &relaovisimaprelid, &relaovisimapidxid);
16439
16440 /* Get the bitmap sub objects */
16441 if (RelationIsBitmapIndex(rel))
16442 GetBitmapIndexAuxOids(rel, &relbmrelid, &relbmidxid);
16443
16444 /*
16445 * Relfilenodes are not unique in databases across tablespaces, so we need
16446 * to allocate a new one in the new tablespace.
16447 */
16448 newrelfilenode = GetNewRelFileNode(newTableSpace, NULL,
16449 rel->rd_rel->relpersistence);

Callers 1

ATRewriteTablesFunction · 0.85

Calls 15

relation_openFunction · 0.85
relation_closeFunction · 0.85
RelationGetIndexListFunction · 0.85
GetBitmapIndexAuxOidsFunction · 0.85
GetNewRelFileNodeFunction · 0.85
index_copy_dataFunction · 0.85
table_relation_copy_dataFunction · 0.85
SetRelationTableSpaceFunction · 0.85
MetaTrackValidKindNspFunction · 0.85
MetaTrackUpdObjectFunction · 0.85

Tested by

no test coverage detected