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

Function ATRewriteTable

src/backend/commands/tablecmds.c:7369–7745  ·  view source on GitHub ↗

* ATRewriteTable: scan or rewrite one table * * OIDNewHeap is InvalidOid if we don't need to rewrite */

Source from the content-addressed store, hash-verified

7367 * OIDNewHeap is InvalidOid if we don't need to rewrite
7368 */
7369static void
7370ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
7371{
7372 Relation oldrel;
7373 Relation newrel;
7374 TupleDesc oldTupDesc;
7375 TupleDesc newTupDesc;
7376 bool needscan = false;
7377 List *notnull_attrs;
7378 int i;
7379 ListCell *l;
7380 EState *estate;
7381 CommandId mycid;
7382 BulkInsertState bistate;
7383 int ti_options;
7384 ExprState *partqualstate = NULL;
7385
7386 /*
7387 * Open the relation(s). We have surely already locked the existing
7388 * table.
7389 */
7390 oldrel = table_open(tab->relid, NoLock);
7391 oldTupDesc = tab->oldDesc;
7392 newTupDesc = RelationGetDescr(oldrel); /* includes all mods */
7393
7394 if (OidIsValid(OIDNewHeap))
7395 newrel = table_open(OIDNewHeap, lockmode);
7396 else
7397 newrel = NULL;
7398
7399 /*
7400 * Prepare a BulkInsertState and options for table_tuple_insert. Because
7401 * we're building a new heap, we can skip WAL-logging and fsync it to disk
7402 * at the end instead (unless WAL-logging is required for archiving or
7403 * streaming replication). The FSM is empty too, so don't bother using it.
7404 */
7405 if (newrel)
7406 {
7407 mycid = GetCurrentCommandId(true);
7408 bistate = GetBulkInsertState();
7409 ti_options = TABLE_INSERT_SKIP_FSM;
7410 }
7411 else
7412 {
7413 /* keep compiler quiet about using these uninitialized */
7414 mycid = 0;
7415 bistate = NULL;
7416 ti_options = 0;
7417 }
7418
7419 /*
7420 * Generate the constraint and default execution states
7421 */
7422
7423 estate = CreateExecutorState();
7424
7425 /* Build the needed expression execution states */
7426 foreach(l, tab->constraints)

Callers 1

ATRewriteTablesFunction · 0.85

Calls 15

table_openFunction · 0.85
GetCurrentCommandIdFunction · 0.85
GetBulkInsertStateFunction · 0.85
CreateExecutorStateFunction · 0.85
ExecPrepareExprFunction · 0.85
ExecInitExprFunction · 0.85
lappend_intFunction · 0.85
MakeSingleTupleTableSlotFunction · 0.85
table_slot_callbacksFunction · 0.85
ExecStoreAllNullTupleFunction · 0.85
RegisterSnapshotFunction · 0.85

Tested by

no test coverage detected