From bafd0c00f64f7ede5335084e6ce2694c370ed9d6 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Wed, 16 Nov 2022 09:38:47 +0100 Subject: [PATCH] Distinguish GetFastPathCachedPlan and GetLocalShardQueryForCache We do this because we do not want to expose FastPathPlanCache to the local executor as much as possible --- .../distributed/executor/local_executor.c | 2 +- .../planner/fast_path_plan_cache.c | 34 +++++++++++++++---- .../distributed/fast_path_plan_cache.h | 3 +- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/executor/local_executor.c b/src/backend/distributed/executor/local_executor.c index ceea20a05..401936f93 100644 --- a/src/backend/distributed/executor/local_executor.c +++ b/src/backend/distributed/executor/local_executor.c @@ -274,7 +274,7 @@ ExecuteLocalTaskListExtended(List *taskList, continue; } - PlannedStmt *planCache = GetFastPathLocalPlan(task, distributedPlan); + PlannedStmt *planCache = GetCachedFastPathLocalPlan(task, distributedPlan); /* * If the plan is already cached, don't need to re-plan, just diff --git a/src/backend/distributed/planner/fast_path_plan_cache.c b/src/backend/distributed/planner/fast_path_plan_cache.c index b341be25e..3e835dd24 100644 --- a/src/backend/distributed/planner/fast_path_plan_cache.c +++ b/src/backend/distributed/planner/fast_path_plan_cache.c @@ -24,6 +24,8 @@ #include "optimizer/clauses.h" +static FastPathPlanCache * GetFastPathCachedPlan(Task *task, + DistributedPlan *distributedPlan); static Query * GetLocalShardQueryForCache(Query *jobQuery, Task *task, ParamListInfo paramListInfo); static char * DeparseLocalShardQuery(Query *jobQuery, List *relationShardList, @@ -40,7 +42,7 @@ void CacheFastPathPlanForShardQuery(Task *task, DistributedPlan *originalDistributedPlan, ParamListInfo paramListInfo) { - PlannedStmt *planCache = GetFastPathLocalPlan(task, originalDistributedPlan); + FastPathPlanCache *planCache = GetFastPathCachedPlan(task, originalDistributedPlan); if (planCache != NULL) { /* we already have a local plan */ @@ -88,8 +90,8 @@ CacheFastPathPlanForShardQuery(Task *task, DistributedPlan *originalDistributedP LockRelationOid(rangeTableEntry->relid, lockMode); FastPathPlanCache *fastPathPlanCache = CitusMakeNode(FastPathPlanCache); - planCache = planner(localShardQuery, NULL, 0, NULL); - fastPathPlanCache->localPlan = planCache; + PlannedStmt *localPlan = planner(localShardQuery, NULL, 0, NULL); + fastPathPlanCache->localPlan = localPlan; fastPathPlanCache->shardId = task->anchorShardId; fastPathPlanCache->placementGroupIds = TaskGroupIdAccesses(task); @@ -226,13 +228,33 @@ ExtractParameterTypesForParamListInfo(ParamListInfo originalParamListInfo, /* - * GetCachedLocalPlan is a helper function which return the cached + * GetCachedFastPathLocalPlan is a helper function which return the cached * plan in the distributedPlan for the given task if exists. * * Otherwise, the function returns NULL. */ PlannedStmt * -GetFastPathLocalPlan(Task *task, DistributedPlan *distributedPlan) +GetCachedFastPathLocalPlan(Task *task, DistributedPlan *distributedPlan) +{ + FastPathPlanCache *fastPathPlanCache = GetFastPathCachedPlan(task, distributedPlan); + + if (fastPathPlanCache != NULL) + { + return fastPathPlanCache->localPlan; + } + + return NULL; +} + + +/* + * GetFastPathCachedPlan is a helper function which return the cached + * plan in the distributedPlan for the given task if exists. + * + * Otherwise, the function returns NULL. + */ +static FastPathPlanCache * +GetFastPathCachedPlan(Task *task, DistributedPlan *distributedPlan) { if (distributedPlan == NULL || distributedPlan->workerJob == NULL) { @@ -250,7 +272,7 @@ GetFastPathLocalPlan(Task *task, DistributedPlan *distributedPlan) fastPathPlanCache->placementGroupIds) == NIL) { /* already have a cached plan, no need to continue */ - return fastPathPlanCache->localPlan; + return fastPathPlanCache; } } diff --git a/src/include/distributed/fast_path_plan_cache.h b/src/include/distributed/fast_path_plan_cache.h index 8fb756bf6..1472416c5 100644 --- a/src/include/distributed/fast_path_plan_cache.h +++ b/src/include/distributed/fast_path_plan_cache.h @@ -3,7 +3,8 @@ extern bool IsFastPathPlanCachingSupported(Job *currentJob, DistributedPlan *originalDistributedPlan); -extern PlannedStmt * GetFastPathLocalPlan(Task *task, DistributedPlan *distributedPlan); +extern PlannedStmt * GetCachedFastPathLocalPlan(Task *task, + DistributedPlan *distributedPlan); extern void CacheFastPathPlanForShardQuery(Task *task, DistributedPlan *originalDistributedPlan, ParamListInfo paramListInfo);