| 18574 | } |
| 18575 | |
| 18576 | static void |
| 18577 | ATExecExpandTableCTAS(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; |
no test coverage detected