Separate function delagation from non distributed statements planning

use-plancontext-more
Jelte Fennema 2020-01-03 10:10:15 +01:00
parent 6251363bfb
commit 53020a7439
1 changed files with 32 additions and 13 deletions

View File

@ -139,7 +139,10 @@ static PlannedStmt * PlanFastPathDistributedStmt(DistributedPlanningContext *ctx
Const *distributionKeyValue); Const *distributionKeyValue);
static PlannedStmt * PlanDistributedStmt(DistributedPlanningContext *ctx, static PlannedStmt * PlanDistributedStmt(DistributedPlanningContext *ctx,
List *rangeTableList, int rteIdCounter); List *rangeTableList, int rteIdCounter);
static PlannedStmt * PlanNonDistributedStmt(DistributedPlanningContext *ctx); static PlannedStmt * PlanDelegatedFunctionCall(DistributedPlanningContext *ctx,
DistributedPlan *delegatedPlan);
static PlannedStmt * PlanNonDistributedStmt(DistributedPlanningContext *ctx,
bool hasExternParam);
/* Distributed planner hook */ /* Distributed planner hook */
PlannedStmt * PlannedStmt *
@ -255,6 +258,8 @@ distributed_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
* planner relies on both the restriction information per table and parse tree * planner relies on both the restriction information per table and parse tree
* transformations made by postgres' planner. * transformations made by postgres' planner.
*/ */
DistributedPlan *delegatedPlan = NULL;
bool hasExternParam = false;
if (fastPathRouterQuery) if (fastPathRouterQuery)
{ {
result = PlanFastPathDistributedStmt(&ctx, distributionKeyValue); result = PlanFastPathDistributedStmt(&ctx, distributionKeyValue);
@ -263,9 +268,14 @@ distributed_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
{ {
result = PlanDistributedStmt(&ctx, rangeTableList, rteIdCounter); result = PlanDistributedStmt(&ctx, rangeTableList, rteIdCounter);
} }
else if ((delegatedPlan = TryToDelegateFunctionCall(ctx.parse,
&hasExternParam)))
{
result = PlanDelegatedFunctionCall(&ctx, delegatedPlan);
}
else else
{ {
result = PlanNonDistributedStmt(&ctx); result = PlanNonDistributedStmt(&ctx, hasExternParam);
} }
} }
PG_CATCH(); PG_CATCH();
@ -608,23 +618,32 @@ PlanDistributedStmt(DistributedPlanningContext *ctx,
/* /*
* PlanNonDistributedStmt creates a normal (non-distributed) planned statement * PlanDelegatedFunctionCall creates a plan by delagating the function call to
* using the PG planner. * the worker.
*/ */
static PlannedStmt * static PlannedStmt *
PlanNonDistributedStmt(DistributedPlanningContext *ctx) PlanDelegatedFunctionCall(DistributedPlanningContext *ctx, DistributedPlan *delegatedPlan)
{ {
PlannedStmt *result = standard_planner(ctx->parse, ctx->cursorOptions, PlannedStmt *result = standard_planner(ctx->parse, ctx->cursorOptions,
ctx->boundParams); ctx->boundParams);
bool hasExternParam = false; result = FinalizePlan(result, delegatedPlan);
DistributedPlan *delegatePlan = TryToDelegateFunctionCall(ctx->parse,
&hasExternParam); return result;
if (delegatePlan != NULL)
{
result = FinalizePlan(result, delegatePlan);
} }
else if (hasExternParam)
/*
* PlanNonDistributedStmt creates a normal (non-distributed) planned statement
* using the PG planner.
*/
static PlannedStmt *
PlanNonDistributedStmt(DistributedPlanningContext *ctx, bool hasExternParam)
{
PlannedStmt *result = standard_planner(ctx->parse, ctx->cursorOptions,
ctx->boundParams);
if (hasExternParam)
{ {
/* /*
* As in CreateDistributedPlannedStmt, try dissuade planner when planning * As in CreateDistributedPlannedStmt, try dissuade planner when planning