* ALTER TABLE SET DISTRIBUTED BY * * set distribution policy for rel */
| 18735 | * set distribution policy for rel |
| 18736 | */ |
| 18737 | static void |
| 18738 | ATExecSetDistributedBy(Relation rel, Node *node, AlterTableCmd *cmd) |
| 18739 | { |
| 18740 | List *lprime; |
| 18741 | List *lwith; |
| 18742 | DistributedBy *ldistro; |
| 18743 | List *cols = NIL; |
| 18744 | ListCell *lc; |
| 18745 | GpPolicy *policy = NULL; |
| 18746 | QueryDesc *queryDesc; |
| 18747 | RangeVar *tmprv; |
| 18748 | Oid tmprelid = InvalidOid; |
| 18749 | Oid tarrelid = RelationGetRelid(rel); |
| 18750 | bool rand_pol = false; |
| 18751 | bool rep_pol = false; |
| 18752 | bool force_reorg = false; |
| 18753 | bool need_reorg; |
| 18754 | bool change_policy = false; |
| 18755 | int numsegments; |
| 18756 | bool save_optimizer_replicated_table_insert; |
| 18757 | Oid relationOid = InvalidOid; |
| 18758 | AutoStatsCmdType cmdType = AUTOSTATS_CMDTYPE_SENTINEL; |
| 18759 | |
| 18760 | /* Can't ALTER TABLE SET system catalogs */ |
| 18761 | if (IsSystemRelation(rel)) |
| 18762 | ereport(ERROR, |
| 18763 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 18764 | errmsg("permission denied: \"%s\" is a system catalog", RelationGetRelationName(rel)))); |
| 18765 | |
| 18766 | Assert(PointerIsValid(node)); |
| 18767 | Assert(IsA(node, List)); |
| 18768 | |
| 18769 | lprime = (List *) node; |
| 18770 | |
| 18771 | /* |
| 18772 | * First element is the WITH clause, second element is the actual |
| 18773 | * distribution clause. |
| 18774 | */ |
| 18775 | lwith = (List *)linitial(lprime); |
| 18776 | ldistro = (DistributedBy *)lsecond(lprime); |
| 18777 | |
| 18778 | if (Gp_role == GP_ROLE_UTILITY) |
| 18779 | ereport(ERROR, |
| 18780 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 18781 | errmsg("SET DISTRIBUTED BY not supported in utility mode"))); |
| 18782 | /* |
| 18783 | * SET DISTRIBUTED BY only change the distribution policy, but should not |
| 18784 | * change numsegments, keep the old value. |
| 18785 | */ |
| 18786 | numsegments = rel->rd_cdbpolicy->numsegments; |
| 18787 | |
| 18788 | if (Gp_role == GP_ROLE_DISPATCH && ldistro) |
| 18789 | ldistro->numsegments = numsegments; |
| 18790 | |
| 18791 | /* we only support partitioned/replicated tables */ |
| 18792 | if (Gp_role == GP_ROLE_DISPATCH) |
| 18793 | { |
| 18794 | if (GpPolicyIsEntry(rel->rd_cdbpolicy)) |
no test coverage detected