提交 c0d1dbd6 编写于 作者: H Heikki Linnakangas

Make more use of make_dist_clause().

We had duplicated code in a few places, to reconstruct a DistributedBy
clause from policy of an existing relation. Use the existing function
to do that.

Rename the function to make_distributedby_for_rel(). That's a more
descriptive name.
Reviewed-by: NNing Yu <nyu@pivotal.io>
上级 636d8f4c
......@@ -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,
......
......@@ -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);
......
......@@ -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; ia<oldTablePolicy->nattrs; 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;
}
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册