mirror of https://github.com/citusdata/citus.git
Refactor RecursivelyPlanSubqueriesAndCTEs() to make it ready
to work with subqueriespull/1876/head
parent
393e625cb2
commit
71ce42b936
|
@ -595,6 +595,7 @@ CreateDistributedSelectPlan(uint64 planId, Query *originalQuery, Query *query,
|
||||||
MultiTreeRoot *logicalPlan = NULL;
|
MultiTreeRoot *logicalPlan = NULL;
|
||||||
DeferredErrorMessage *error = NULL;
|
DeferredErrorMessage *error = NULL;
|
||||||
List *subPlanList = NIL;
|
List *subPlanList = NIL;
|
||||||
|
RecursivePlanningContext context;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For select queries we, if router executor is enabled, first try to
|
* For select queries we, if router executor is enabled, first try to
|
||||||
|
@ -648,8 +649,12 @@ CreateDistributedSelectPlan(uint64 planId, Query *originalQuery, Query *query,
|
||||||
* Plan subqueries and CTEs that cannot be pushed down by recursively
|
* Plan subqueries and CTEs that cannot be pushed down by recursively
|
||||||
* calling the planner and add the resulting plans to subPlanList.
|
* calling the planner and add the resulting plans to subPlanList.
|
||||||
*/
|
*/
|
||||||
error = RecursivelyPlanSubqueriesAndCTEs(originalQuery, plannerRestrictionContext,
|
context.level = 0;
|
||||||
planId, &subPlanList);
|
context.planId = planId;
|
||||||
|
context.subPlanList = NIL;
|
||||||
|
context.plannerRestrictionContext = plannerRestrictionContext;
|
||||||
|
|
||||||
|
error = RecursivelyPlanSubqueriesAndCTEs(originalQuery, &context);
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
{
|
{
|
||||||
RaiseDeferredError(error, ERROR);
|
RaiseDeferredError(error, ERROR);
|
||||||
|
@ -663,6 +668,7 @@ CreateDistributedSelectPlan(uint64 planId, Query *originalQuery, Query *query,
|
||||||
* with an original query. In that case, we would only have to filter the
|
* with an original query. In that case, we would only have to filter the
|
||||||
* planner restriction context.
|
* planner restriction context.
|
||||||
*/
|
*/
|
||||||
|
subPlanList = context.subPlanList;
|
||||||
if (list_length(subPlanList) > 0)
|
if (list_length(subPlanList) > 0)
|
||||||
{
|
{
|
||||||
Query *newQuery = copyObject(originalQuery);
|
Query *newQuery = copyObject(originalQuery);
|
||||||
|
|
|
@ -73,19 +73,6 @@
|
||||||
#include "utils/guc.h"
|
#include "utils/guc.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* RecursivePlanningContext is used to recursively plan subqueries
|
|
||||||
* and CTEs, pull results to the coordinator, and push it back into
|
|
||||||
* the workers.
|
|
||||||
*/
|
|
||||||
typedef struct RecursivePlanningContext
|
|
||||||
{
|
|
||||||
int level;
|
|
||||||
uint64 planId;
|
|
||||||
List *subPlanList;
|
|
||||||
PlannerRestrictionContext *plannerRestrictionContext;
|
|
||||||
} RecursivePlanningContext;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CteReferenceWalkerContext is used to collect CTE references in
|
* CteReferenceWalkerContext is used to collect CTE references in
|
||||||
* CteReferenceListWalker.
|
* CteReferenceListWalker.
|
||||||
|
@ -133,17 +120,9 @@ static Query * BuildSubPlanResultQuery(Query *subquery, uint64 planId, uint32 su
|
||||||
* subplans will be added to subPlanList.
|
* subplans will be added to subPlanList.
|
||||||
*/
|
*/
|
||||||
DeferredErrorMessage *
|
DeferredErrorMessage *
|
||||||
RecursivelyPlanSubqueriesAndCTEs(Query *query,
|
RecursivelyPlanSubqueriesAndCTEs(Query *query, RecursivePlanningContext *context)
|
||||||
PlannerRestrictionContext *plannerRestrictionContext,
|
|
||||||
uint64 planId, List **subPlanList)
|
|
||||||
{
|
{
|
||||||
DeferredErrorMessage *error = NULL;
|
DeferredErrorMessage *error = NULL;
|
||||||
RecursivePlanningContext context;
|
|
||||||
|
|
||||||
context.level = 0;
|
|
||||||
context.planId = planId;
|
|
||||||
context.subPlanList = NIL;
|
|
||||||
context.plannerRestrictionContext = plannerRestrictionContext;
|
|
||||||
|
|
||||||
error = RecursivelyPlanCTEs(query, &context);
|
error = RecursivelyPlanCTEs(query, &context);
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
|
@ -166,9 +145,8 @@ RecursivelyPlanSubqueriesAndCTEs(Query *query,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: plan subqueries */
|
/* descend into subqueries */
|
||||||
|
query_tree_walker(query, RecursivelyPlanSubqueryWalker, context, 0);
|
||||||
*subPlanList = context.subPlanList;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,6 @@ extern bool IsModifyDistributedPlan(struct DistributedPlan *distributedPlan);
|
||||||
extern bool IsMultiTaskPlan(struct DistributedPlan *distributedPlan);
|
extern bool IsMultiTaskPlan(struct DistributedPlan *distributedPlan);
|
||||||
extern bool IsMultiShardModifyPlan(struct DistributedPlan *distributedPlan);
|
extern bool IsMultiShardModifyPlan(struct DistributedPlan *distributedPlan);
|
||||||
extern RangeTblEntry * RemoteScanRangeTableEntry(List *columnNameList);
|
extern RangeTblEntry * RemoteScanRangeTableEntry(List *columnNameList);
|
||||||
extern char * GenerateResultId(uint64 planId, uint32 subPlanId);
|
|
||||||
|
|
||||||
|
|
||||||
extern int GetRTEIdentity(RangeTblEntry *rte);
|
extern int GetRTEIdentity(RangeTblEntry *rte);
|
||||||
|
|
||||||
#endif /* DISTRIBUTED_PLANNER_H */
|
#endif /* DISTRIBUTED_PLANNER_H */
|
||||||
|
|
|
@ -18,11 +18,23 @@
|
||||||
#include "nodes/relation.h"
|
#include "nodes/relation.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RecursivePlanningContext is used to recursively plan subqueries
|
||||||
|
* and CTEs, pull results to the coordinator, and push it back into
|
||||||
|
* the workers.
|
||||||
|
*/
|
||||||
|
typedef struct RecursivePlanningContext
|
||||||
|
{
|
||||||
|
int level;
|
||||||
|
uint64 planId;
|
||||||
|
List *subPlanList;
|
||||||
|
PlannerRestrictionContext *plannerRestrictionContext;
|
||||||
|
} RecursivePlanningContext;
|
||||||
|
|
||||||
|
|
||||||
extern DeferredErrorMessage * RecursivelyPlanSubqueriesAndCTEs(Query *query,
|
extern DeferredErrorMessage * RecursivelyPlanSubqueriesAndCTEs(Query *query,
|
||||||
PlannerRestrictionContext *
|
RecursivePlanningContext *
|
||||||
plannerRestrictionContext,
|
context);
|
||||||
uint64 planId,
|
|
||||||
List **subPlanList);
|
|
||||||
extern char * GenerateResultId(uint64 planId, uint32 subPlanId);
|
extern char * GenerateResultId(uint64 planId, uint32 subPlanId);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue