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

Function ATExecSetDistributedBy

src/backend/commands/tablecmds.c:18737–19333  ·  view source on GitHub ↗

* ALTER TABLE SET DISTRIBUTED BY * * set distribution policy for rel */

Source from the content-addressed store, hash-verified

18735 * set distribution policy for rel
18736 */
18737static void
18738ATExecSetDistributedBy(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))

Callers 1

ATExecCmdFunction · 0.85

Calls 15

IsSystemRelationFunction · 0.85
GpPolicyIsEntryFunction · 0.85
rel_is_external_tableFunction · 0.85
GetExtTableEntryFunction · 0.85
list_lengthFunction · 0.85
pg_strcasecmpFunction · 0.85
relationHasPrimaryKeyFunction · 0.85
relationHasUniqueIndexFunction · 0.85
GpPolicyIsReplicatedFunction · 0.85
GpPolicyReplaceFunction · 0.85

Tested by

no test coverage detected