diff --git a/src/backend/cdb/cdbpartition.c b/src/backend/cdb/cdbpartition.c index 6fa2a4f7f6ca64f53d7b56e43427dcf236edbb79..b668bfa62f7bd15d3e356422a5c3941225a14056 100644 --- a/src/backend/cdb/cdbpartition.c +++ b/src/backend/cdb/cdbpartition.c @@ -6611,7 +6611,7 @@ atpxPartAddList(Relation rel, ct->ownerid = ownerid; if (!ct->distributedBy) - ct->distributedBy = make_dist_clause(rel); + ct->distributedBy = make_distributedby_for_rel(rel); /* this function does transformExpr on the boundary specs */ (void) atpxPart_validate_spec(pBy, rel, ct, pelem, pNode, partName, diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index a486a9a55e9b86e221c6834e87348cac6061bf21..8285a1b30316553dd6ee27132d46442527241de1 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -15008,7 +15008,7 @@ ATExecSetDistributedBy(Relation rel, Node *node, AlterTableCmd *cmd) } if (!ldistro) - ldistro = make_dist_clause(rel); + ldistro = make_distributedby_for_rel(rel); /* * Force the use of legacy query optimizer, since PQO will not @@ -17163,12 +17163,12 @@ split_rows(Relation intoa, Relation intob, Relation temprel) /* ALTER TABLE ... SPLIT PARTITION */ -/* Given a Relation, make a distributed by () clause for parser consumption. */ +/* Given a Relation, make a DISTRIBUTED BY (...) clause for parser consumption. */ DistributedBy * -make_dist_clause(Relation rel) +make_distributedby_for_rel(Relation rel) { - int i; - DistributedBy *dist; + int i; + DistributedBy *dist; List *distro = NIL; dist = makeNode(DistributedBy); @@ -17522,7 +17522,7 @@ ATPExecPartSplit(Relation *rel, existrel = heap_open(prule->topRule->parchildrelid, NoLock); existstorage_opts = reloptions_list(RelationGetRelid(existrel)); - distro = make_dist_clause(existrel); + distro = make_distributedby_for_rel(existrel); colencs = rel_get_column_encodings(existrel); orient = make_orientation_options(existrel); diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 57d06b9b6b583c722bfd7fcb2bbdde88def60c87..27a74d4ecc8a8317deb5c289068c25a27fabebbb 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -1845,8 +1845,11 @@ transformDistributedBy(CreateStmtContext *cxt, foreach(entry, cxt->inhRelations) { RangeVar *parent = (RangeVar *) lfirst(entry); - Oid relId = RangeVarGetRelid(parent, NoLock, false); - GpPolicy *oldTablePolicy = GpPolicyFetch(relId); + GpPolicy *parentPolicy; + Relation parentrel; + + parentrel = heap_openrv(parent, AccessShareLock); + parentPolicy = parentrel->rd_cdbpolicy; /* * Partitioned child must have partitioned parents. During binary @@ -1854,26 +1857,24 @@ transformDistributedBy(CreateStmtContext *cxt, * segment in utility mode and the distribution policy isn't stored * in the segments. */ - if ((oldTablePolicy == NULL || - oldTablePolicy->ptype == POLICYTYPE_ENTRY) && + if ((parentPolicy == NULL || + parentPolicy->ptype == POLICYTYPE_ENTRY) && !IsBinaryUpgrade) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot inherit from catalog table \"%s\" " - "to create table \"%s\".", + errmsg("cannot inherit from catalog table \"%s\" to create table \"%s\"", parent->relname, cxt->relation->relname), errdetail("An inheritance hierarchy cannot contain a " "mixture of distributed and " "non-distributed tables."))); } - if ((oldTablePolicy == NULL || - GpPolicyIsReplicated(oldTablePolicy)) && + if ((parentPolicy == NULL || + GpPolicyIsReplicated(parentPolicy)) && !IsBinaryUpgrade) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot inherit from replicated table \"%s\" " - "to create table \"%s\".", + errmsg("cannot inherit from replicated table \"%s\" to create table \"%s\".", parent->relname, cxt->relation->relname), errdetail("An inheritance hierarchy cannot contain a " "mixture of distributed and " @@ -1885,41 +1886,17 @@ transformDistributedBy(CreateStmtContext *cxt, * is an inherited table, set the distribution based on the * parent (or one of the parents) */ - if (distrkeys == NIL && oldTablePolicy->nattrs >= 0) + if (distrkeys == NIL && parentPolicy->nattrs >= 0) { - int ia; - if (!bQuiet) - elog(NOTICE, "Table has parent, setting distribution columns " - "to match parent table"); + elog(NOTICE, "Table has parent, setting distribution columns to match parent table"); - /* - * Inherited tables must have the same numsegments with - * parent table. - */ - numsegments = oldTablePolicy->numsegments; - - if (oldTablePolicy->nattrs > 0) - { - for (ia=0; ianattrs; ia++) - { - char *attname = - get_attname(relId, oldTablePolicy->attrs[ia]); + distributedBy = make_distributedby_for_rel(parentrel); + heap_close(parentrel, AccessShareLock); - distrkeys = lappend(distrkeys, - (Node *) makeString(attname)); - } - } - else - { - pfree(oldTablePolicy); - distributedBy = makeNode(DistributedBy); - distributedBy->ptype = POLICYTYPE_PARTITIONED; - distributedBy->numsegments = numsegments; - return distributedBy; - } + return distributedBy; } - pfree(oldTablePolicy); + heap_close(parentrel, AccessShareLock); } } @@ -4208,41 +4185,18 @@ setSchemaName(char *context_schema, char **stmt_schema_name) static DistributedBy * getLikeDistributionPolicy(TableLikeClause *e) { - DistributedBy *likeDistributedBy = NULL; - Oid relId; - GpPolicy* oldTablePolicy; + DistributedBy *likeDistributedBy = NULL; + Relation rel; - relId = RangeVarGetRelid(e->relation, NoLock, false); - oldTablePolicy = GpPolicyFetch(relId); + rel = relation_openrv(e->relation, AccessShareLock); - if (oldTablePolicy != NULL && oldTablePolicy->ptype != POLICYTYPE_ENTRY) + if (rel->rd_cdbpolicy != NULL && rel->rd_cdbpolicy->ptype != POLICYTYPE_ENTRY) { - likeDistributedBy = makeNode(DistributedBy); - - if (GpPolicyIsReplicated(oldTablePolicy)) - { - likeDistributedBy->ptype = POLICYTYPE_REPLICATED; - likeDistributedBy->numsegments = oldTablePolicy->numsegments; - likeDistributedBy->keys = NIL; - } - else - { - int ia; - List *keys = NIL; - - for (ia = 0 ; ia < oldTablePolicy->nattrs ; ia++) - { - char *attname = get_attname(relId, oldTablePolicy->attrs[ia]); - - keys = lappend(keys, (Node *) makeString(attname)); - } - - likeDistributedBy->ptype = POLICYTYPE_PARTITIONED; - likeDistributedBy->numsegments = oldTablePolicy->numsegments; - likeDistributedBy->keys = keys; - } + likeDistributedBy = make_distributedby_for_rel(rel); } + relation_close(rel, AccessShareLock); + return likeDistributedBy; } diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h index 87d56074e9f9beea8b87822c4d19ded9e4616b6b..f7ea91d618c3a61c7778e7013e592dbedf4b1fa1 100644 --- a/src/include/commands/tablecmds.h +++ b/src/include/commands/tablecmds.h @@ -122,7 +122,7 @@ extern Oid get_settable_tablespace_oid(char *tablespacename); extern List * MergeAttributes(List *schema, List *supers, bool istemp, bool isPartitioned, List **supOids, List **supconstr, int *supOidCount); -extern DistributedBy *make_dist_clause(Relation rel); +extern DistributedBy *make_distributedby_for_rel(Relation rel); extern Oid transformFkeyCheckAttrs(Relation pkrel, int numattrs, int16 *attnums,