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,
|
static DistributedPlan * CreateDistributedInsertSelectPlan(Query *originalQuery,
|
||||||
PlannerRestrictionContext *
|
PlannerRestrictionContext *
|
||||||
plannerRestrictionContext);
|
plannerRestrictionContext);
|
||||||
static bool SafeToPushDownSubquery(PlannerRestrictionContext *plannerRestrictionContext,
|
|
||||||
Query *originalQuery);
|
|
||||||
static Task * RouterModifyTaskForShardInterval(Query *originalQuery,
|
static Task * RouterModifyTaskForShardInterval(Query *originalQuery,
|
||||||
ShardInterval *shardInterval,
|
ShardInterval *shardInterval,
|
||||||
RelationRestrictionContext *
|
RelationRestrictionContext *
|
||||||
|
@ -217,7 +215,7 @@ CreateDistributedInsertSelectPlan(Query *originalQuery,
|
||||||
RelationRestrictionContext *relationRestrictionContext =
|
RelationRestrictionContext *relationRestrictionContext =
|
||||||
plannerRestrictionContext->relationRestrictionContext;
|
plannerRestrictionContext->relationRestrictionContext;
|
||||||
bool allReferenceTables = relationRestrictionContext->allReferenceTables;
|
bool allReferenceTables = relationRestrictionContext->allReferenceTables;
|
||||||
bool safeToPushDownSubquery = false;
|
bool queryContainsDistributionKeyEquality = false;
|
||||||
|
|
||||||
distributedPlan->operation = originalQuery->commandType;
|
distributedPlan->operation = originalQuery->commandType;
|
||||||
|
|
||||||
|
@ -234,8 +232,8 @@ CreateDistributedInsertSelectPlan(Query *originalQuery,
|
||||||
return distributedPlan;
|
return distributedPlan;
|
||||||
}
|
}
|
||||||
|
|
||||||
safeToPushDownSubquery = SafeToPushDownSubquery(plannerRestrictionContext,
|
queryContainsDistributionKeyEquality =
|
||||||
originalQuery);
|
QueryContainsDistributionKeyEquality(plannerRestrictionContext, originalQuery);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Plan select query for each shard in the target table. Do so by replacing the
|
* 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,
|
modifyTask = RouterModifyTaskForShardInterval(originalQuery, targetShardInterval,
|
||||||
relationRestrictionContext,
|
relationRestrictionContext,
|
||||||
taskIdIndex,
|
taskIdIndex,
|
||||||
safeToPushDownSubquery);
|
queryContainsDistributionKeyEquality);
|
||||||
|
|
||||||
/* add the task if it could be created */
|
/* add the task if it could be created */
|
||||||
if (modifyTask != NULL)
|
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
|
* RouterModifyTaskForShardInterval creates a modify task by
|
||||||
* replacing the partitioning qual parameter added in distributed_planner()
|
* replacing the partitioning qual parameter added in distributed_planner()
|
||||||
|
|
|
@ -143,6 +143,34 @@ static bool JoinRestrictionListExistsInContext(JoinRestriction *joinRestrictionI
|
||||||
joinRestrictionContext);
|
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
|
* SafeToPushdownUnionSubquery returns true if all the relations are returns
|
||||||
* partition keys in the same ordinal position and there is no reference table
|
* partition keys in the same ordinal position and there is no reference table
|
||||||
|
|
|
@ -15,14 +15,18 @@
|
||||||
#include "distributed/distributed_planner.h"
|
#include "distributed/distributed_planner.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern bool QueryContainsDistributionKeyEquality(PlannerRestrictionContext *
|
||||||
|
plannerRestrictionContext,
|
||||||
|
Query *originalQuery);
|
||||||
|
extern bool SafeToPushdownUnionSubquery(PlannerRestrictionContext *
|
||||||
|
plannerRestrictionContext);
|
||||||
extern bool ContainsUnionSubquery(Query *queryTree);
|
extern bool ContainsUnionSubquery(Query *queryTree);
|
||||||
extern bool RestrictionEquivalenceForPartitionKeys(PlannerRestrictionContext *
|
extern bool RestrictionEquivalenceForPartitionKeys(PlannerRestrictionContext *
|
||||||
plannerRestrictionContext);
|
plannerRestrictionContext);
|
||||||
extern List * GenerateAllAttributeEquivalences(PlannerRestrictionContext *
|
extern List * GenerateAllAttributeEquivalences(PlannerRestrictionContext *
|
||||||
plannerRestrictionContext);
|
plannerRestrictionContext);
|
||||||
extern uint32 ReferenceRelationCount(RelationRestrictionContext *restrictionContext);
|
extern uint32 ReferenceRelationCount(RelationRestrictionContext *restrictionContext);
|
||||||
extern bool SafeToPushdownUnionSubquery(
|
|
||||||
PlannerRestrictionContext *plannerRestrictionContext);
|
|
||||||
extern List * RelationIdList(Query *query);
|
extern List * RelationIdList(Query *query);
|
||||||
extern PlannerRestrictionContext * FilterPlannerRestrictionForQuery(
|
extern PlannerRestrictionContext * FilterPlannerRestrictionForQuery(
|
||||||
PlannerRestrictionContext *plannerRestrictionContext,
|
PlannerRestrictionContext *plannerRestrictionContext,
|
||||||
|
|
Loading…
Reference in New Issue