mirror of https://github.com/citusdata/citus.git
Refactor checks for distribution key equality
Change some function names, ensure we stick to Citus' function order rules etc.pull/2016/head
parent
846b8b1536
commit
e8aa532a90
|
@ -41,8 +41,6 @@
|
|||
static DistributedPlan * CreateDistributedInsertSelectPlan(Query *originalQuery,
|
||||
PlannerRestrictionContext *
|
||||
plannerRestrictionContext);
|
||||
static bool SafeToPushDownSubquery(PlannerRestrictionContext *plannerRestrictionContext,
|
||||
Query *originalQuery);
|
||||
static Task * RouterModifyTaskForShardInterval(Query *originalQuery,
|
||||
ShardInterval *shardInterval,
|
||||
RelationRestrictionContext *
|
||||
|
@ -217,7 +215,7 @@ CreateDistributedInsertSelectPlan(Query *originalQuery,
|
|||
RelationRestrictionContext *relationRestrictionContext =
|
||||
plannerRestrictionContext->relationRestrictionContext;
|
||||
bool allReferenceTables = relationRestrictionContext->allReferenceTables;
|
||||
bool safeToPushDownSubquery = false;
|
||||
bool queryContainsDistributionKeyEquality = false;
|
||||
|
||||
distributedPlan->operation = originalQuery->commandType;
|
||||
|
||||
|
@ -234,8 +232,8 @@ CreateDistributedInsertSelectPlan(Query *originalQuery,
|
|||
return distributedPlan;
|
||||
}
|
||||
|
||||
safeToPushDownSubquery = SafeToPushDownSubquery(plannerRestrictionContext,
|
||||
originalQuery);
|
||||
queryContainsDistributionKeyEquality =
|
||||
QueryContainsDistributionKeyEquality(plannerRestrictionContext, originalQuery);
|
||||
|
||||
/*
|
||||
* Plan select query for each shard in the target table. Do so by replacing the
|
||||
|
@ -255,7 +253,7 @@ CreateDistributedInsertSelectPlan(Query *originalQuery,
|
|||
modifyTask = RouterModifyTaskForShardInterval(originalQuery, targetShardInterval,
|
||||
relationRestrictionContext,
|
||||
taskIdIndex,
|
||||
safeToPushDownSubquery);
|
||||
queryContainsDistributionKeyEquality);
|
||||
|
||||
/* add the task if it could be created */
|
||||
if (modifyTask != NULL)
|
||||
|
@ -392,34 +390,6 @@ DistributedInsertSelectSupported(Query *queryTree, RangeTblEntry *insertRte,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* SafeToPushDownSubquery returns true if either
|
||||
* (i) there exists join in the query and all relations joined on their
|
||||
* partition keys
|
||||
* (ii) there exists only union set operations and all relations has
|
||||
* partition keys in the same ordinal position in the query
|
||||
*/
|
||||
static bool
|
||||
SafeToPushDownSubquery(PlannerRestrictionContext *plannerRestrictionContext,
|
||||
Query *originalQuery)
|
||||
{
|
||||
bool restrictionEquivalenceForPartitionKeys =
|
||||
RestrictionEquivalenceForPartitionKeys(plannerRestrictionContext);
|
||||
|
||||
if (restrictionEquivalenceForPartitionKeys)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ContainsUnionSubquery(originalQuery))
|
||||
{
|
||||
return SafeToPushdownUnionSubquery(plannerRestrictionContext);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* RouterModifyTaskForShardInterval creates a modify task by
|
||||
* replacing the partitioning qual parameter added in distributed_planner()
|
||||
|
|
|
@ -143,6 +143,34 @@ static bool JoinRestrictionListExistsInContext(JoinRestriction *joinRestrictionI
|
|||
joinRestrictionContext);
|
||||
|
||||
|
||||
/*
|
||||
* QueryContainsDistributionKeyEquality returns true if either
|
||||
* (i) there exists join in the query and all relations joined on their
|
||||
* partition keys
|
||||
* (ii) there exists only union set operations and all relations has
|
||||
* partition keys in the same ordinal position in the query
|
||||
*/
|
||||
bool
|
||||
QueryContainsDistributionKeyEquality(PlannerRestrictionContext *plannerRestrictionContext,
|
||||
Query *originalQuery)
|
||||
{
|
||||
bool restrictionEquivalenceForPartitionKeys =
|
||||
RestrictionEquivalenceForPartitionKeys(plannerRestrictionContext);
|
||||
|
||||
if (restrictionEquivalenceForPartitionKeys)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ContainsUnionSubquery(originalQuery))
|
||||
{
|
||||
return SafeToPushdownUnionSubquery(plannerRestrictionContext);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SafeToPushdownUnionSubquery returns true if all the relations are returns
|
||||
* partition keys in the same ordinal position and there is no reference table
|
||||
|
|
|
@ -15,14 +15,18 @@
|
|||
#include "distributed/distributed_planner.h"
|
||||
|
||||
|
||||
extern bool QueryContainsDistributionKeyEquality(PlannerRestrictionContext *
|
||||
plannerRestrictionContext,
|
||||
Query *originalQuery);
|
||||
extern bool SafeToPushdownUnionSubquery(PlannerRestrictionContext *
|
||||
plannerRestrictionContext);
|
||||
extern bool ContainsUnionSubquery(Query *queryTree);
|
||||
extern bool RestrictionEquivalenceForPartitionKeys(PlannerRestrictionContext *
|
||||
plannerRestrictionContext);
|
||||
extern List * GenerateAllAttributeEquivalences(PlannerRestrictionContext *
|
||||
plannerRestrictionContext);
|
||||
extern uint32 ReferenceRelationCount(RelationRestrictionContext *restrictionContext);
|
||||
extern bool SafeToPushdownUnionSubquery(
|
||||
PlannerRestrictionContext *plannerRestrictionContext);
|
||||
|
||||
extern List * RelationIdList(Query *query);
|
||||
extern PlannerRestrictionContext * FilterPlannerRestrictionForQuery(
|
||||
PlannerRestrictionContext *plannerRestrictionContext,
|
||||
|
|
Loading…
Reference in New Issue