Merge pull request #610 from citusdata/501_single_worker_queries

Refactor multi_planner to create router plan directly
pull/615/head
Murat Tuncer 2016-06-21 12:54:30 +03:00 committed by GitHub
commit aa94a0b1ca
3 changed files with 19 additions and 17 deletions

View File

@ -72,15 +72,8 @@ MultiPlan *
CreatePhysicalPlan(Query *parse) CreatePhysicalPlan(Query *parse)
{ {
Query *parseCopy = copyObject(parse); Query *parseCopy = copyObject(parse);
MultiPlan *physicalPlan = NULL; MultiPlan *physicalPlan = MultiRouterPlanCreate(parseCopy, TaskExecutorType);
bool routerPlannable = MultiRouterPlannableQuery(parseCopy, TaskExecutorType); if (physicalPlan == NULL)
if (routerPlannable)
{
ereport(DEBUG2, (errmsg("Creating router plan")));
physicalPlan = MultiRouterPlanCreate(parseCopy);
CheckNodeIsDumpable((Node *) physicalPlan);
}
else
{ {
/* Create and optimize logical plan */ /* Create and optimize logical plan */
MultiTreeRoot *logicalPlan = MultiLogicalPlanCreate(parseCopy); MultiTreeRoot *logicalPlan = MultiLogicalPlanCreate(parseCopy);

View File

@ -70,19 +70,20 @@ static Oid ExtractFirstDistributedTableId(Query *query);
static Const * ExtractInsertPartitionValue(Query *query, Var *partitionColumn); static Const * ExtractInsertPartitionValue(Query *query, Var *partitionColumn);
static Task * RouterSelectTask(Query *query); static Task * RouterSelectTask(Query *query);
static Job * RouterQueryJob(Query *query, Task *task); static Job * RouterQueryJob(Query *query, Task *task);
static bool MultiRouterPlannableQuery(Query *query, MultiExecutorType taskExecutorType);
static bool ColumnMatchExpressionAtTopLevelConjunction(Node *node, Var *column); static bool ColumnMatchExpressionAtTopLevelConjunction(Node *node, Var *column);
static void SetRangeTablesInherited(Query *query); static void SetRangeTablesInherited(Query *query);
/* /*
* MultiRouterPlanCreate creates a physical plan for given router plannable query. * MultiRouterPlanCreate creates a physical plan for given query. The created plan is
* Created plan is either a modify task that changes a single shard, or a router task * either a modify task that changes a single shard, or a router task that returns
* that returns query results from a single shard. Supported modify queries * query results from a single shard. Supported modify queries (insert/update/delete)
* (insert/update/delete) are router plannble by default. The caller is expected to call * are router plannable by default. If query is not router plannable then the function
* MultiRouterPlannableQuery to see if the query is router plannable for select queries. * returns NULL.
*/ */
MultiPlan * MultiPlan *
MultiRouterPlanCreate(Query *query) MultiRouterPlanCreate(Query *query, MultiExecutorType taskExecutorType)
{ {
Task *task = NULL; Task *task = NULL;
Job *job = NULL; Job *job = NULL;
@ -90,6 +91,14 @@ MultiRouterPlanCreate(Query *query)
CmdType commandType = query->commandType; CmdType commandType = query->commandType;
bool modifyTask = false; bool modifyTask = false;
bool routerPlannable = MultiRouterPlannableQuery(query, taskExecutorType);
if (!routerPlannable)
{
return NULL;
}
ereport(DEBUG2, (errmsg("Creating router plan")));
if (commandType == CMD_INSERT || commandType == CMD_UPDATE || if (commandType == CMD_INSERT || commandType == CMD_UPDATE ||
commandType == CMD_DELETE) commandType == CMD_DELETE)
{ {

View File

@ -30,8 +30,8 @@
#define UPSERT_ALIAS "citus_table_alias" #define UPSERT_ALIAS "citus_table_alias"
#endif #endif
extern MultiPlan * MultiRouterPlanCreate(Query *query); extern MultiPlan * MultiRouterPlanCreate(Query *query,
MultiExecutorType taskExecutorType);
extern void ErrorIfModifyQueryNotSupported(Query *queryTree); extern void ErrorIfModifyQueryNotSupported(Query *queryTree);
extern bool MultiRouterPlannableQuery(Query *query, MultiExecutorType taskExecutorType);
#endif /* MULTI_ROUTER_PLANNER_H */ #endif /* MULTI_ROUTER_PLANNER_H */