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

Function ATExecExpandTableCTAS

src/backend/commands/tablecmds.c:18576–18730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18574}
18575
18576static void
18577ATExecExpandTableCTAS(AlterTableCmd *rootCmd, Relation rel, AlterTableCmd *cmd, int numsegments)
18578{
18579 RangeVar *tmprv;
18580 Oid tmprelid;
18581 Oid relid = RelationGetRelid(rel);
18582 ReindexParams params = {0};
18583 /*--
18584 * a) Ensure that the proposed policy is sensible
18585 * b) Create a temporary table and reorganise data according to our desired
18586 * distribution policy. To do this, we build a Query node which express
18587 * the query:
18588 * CREATE TABLE tmp_tab_nam AS SELECT * FROM cur_table DISTRIBUTED BY (policy)
18589 * c) Execute the query across all nodes
18590 * d) Update our parse tree to include the details of the newly created
18591 * table
18592 * e) Update the ownership of the temporary table
18593 * f) Swap the relfilenodes of the existing table and the temporary table
18594 * g) Update the policy on the QD to reflect the underlying data
18595 * h) Drop the temporary table -- and with it, the old copy of the data
18596 *--
18597 */
18598 if (Gp_role == GP_ROLE_DISPATCH)
18599 {
18600 AutoStatsCmdType cmdType = AUTOSTATS_CMDTYPE_SENTINEL;
18601 DistributedBy *distby;
18602 QueryDesc *queryDesc;
18603 Oid relationOid = InvalidOid;
18604 bool saveOptimizerGucValue;;
18605
18606 /* Step (a) */
18607 /*
18608 * Force the use of Postgres based planner, since GPORCA will not
18609 * redistribute the tuples if the current and required distributions
18610 * are both RANDOM even when reorganize is set to "true"
18611 */
18612 saveOptimizerGucValue = optimizer;
18613 optimizer = false;
18614
18615 /* Step (b) - build CTAS */
18616 distby = make_distributedby_for_rel(rel);
18617 distby->numsegments = numsegments;
18618
18619 queryDesc = build_ctas_with_dist(rel, distby,
18620 untransformRelOptions(get_rel_opts(rel)),
18621 &tmprv,
18622 true);
18623
18624 /*
18625 * We need to update our snapshot here to make sure we see all
18626 * committed work. We have an exclusive lock on the table so no one
18627 * will be able to access the table now.
18628 */
18629 PushActiveSnapshot(GetLatestSnapshot());
18630
18631 /* Step (c) - run on all nodes */
18632 queryDesc->ddesc = makeNode(QueryDispatchDesc);
18633 queryDesc->ddesc->useChangedAOOpts = false;

Callers 1

ATExecExpandTableFunction · 0.85

Calls 15

build_ctas_with_distFunction · 0.85
untransformRelOptionsFunction · 0.85
get_rel_optsFunction · 0.85
PushActiveSnapshotFunction · 0.85
GetLatestSnapshotFunction · 0.85
ExecutorStartFunction · 0.85
ExecutorRunFunction · 0.85
autostats_get_cmdtypeFunction · 0.85
ExecutorFinishFunction · 0.85

Tested by

no test coverage detected