Generate query for the remote fast path query cache

Do not use yet, just generate
remote_prepared_txes
Onder Kalaci 2022-11-16 10:00:18 +01:00
parent ecd0af1e72
commit ccec45c63a
3 changed files with 51 additions and 3 deletions

View File

@ -28,6 +28,8 @@ static FastPathPlanCache * GetFastPathCachedPlan(Task *task,
DistributedPlan *distributedPlan); DistributedPlan *distributedPlan);
static Query * GetLocalShardQueryForCache(Query *jobQuery, Task *task, static Query * GetLocalShardQueryForCache(Query *jobQuery, Task *task,
ParamListInfo paramListInfo); ParamListInfo paramListInfo);
static char * GetFastPathQueryStringForCache(Query *jobQuery, Task *task,
ParamListInfo orig_paramListInfo);
static char * DeparseLocalShardQuery(Query *jobQuery, List *relationShardList, static char * DeparseLocalShardQuery(Query *jobQuery, List *relationShardList,
Oid anchorDistributedTableId, int64 anchorShardId); Oid anchorDistributedTableId, int64 anchorShardId);
static int ExtractParameterTypesForParamListInfo(ParamListInfo originalParamListInfo, static int ExtractParameterTypesForParamListInfo(ParamListInfo originalParamListInfo,
@ -67,6 +69,8 @@ CacheFastPathPlanForShardQuery(Task *task, DistributedPlan *originalDistributedP
* functions/params to have been evaluated in the cached plan. * functions/params to have been evaluated in the cached plan.
*/ */
Query *jobQuery = copyObject(originalDistributedPlan->workerJob->jobQuery); Query *jobQuery = copyObject(originalDistributedPlan->workerJob->jobQuery);
FastPathPlanCache *fastPathPlanCache = CitusMakeNode(FastPathPlanCache);
PlannedStmt *localPlan = NULL; PlannedStmt *localPlan = NULL;
if (TaskAccessesLocalNode(task)) if (TaskAccessesLocalNode(task))
@ -95,12 +99,16 @@ CacheFastPathPlanForShardQuery(Task *task, DistributedPlan *originalDistributedP
LockRelationOid(rangeTableEntry->relid, lockMode); LockRelationOid(rangeTableEntry->relid, lockMode);
localPlan = planner(localShardQuery, NULL, 0, NULL); localPlan = planner(localShardQuery, NULL, 0, NULL);
fastPathPlanCache->localPlan = localPlan;
} }
else else
{ } {
char *queryString =
GetFastPathQueryStringForCache(jobQuery, task, paramListInfo);
fastPathPlanCache->queryString = queryString;
}
FastPathPlanCache *fastPathPlanCache = CitusMakeNode(FastPathPlanCache);
fastPathPlanCache->localPlan = localPlan;
fastPathPlanCache->shardId = task->anchorShardId; fastPathPlanCache->shardId = task->anchorShardId;
fastPathPlanCache->placementGroupIds = TaskGroupIdAccesses(task); fastPathPlanCache->placementGroupIds = TaskGroupIdAccesses(task);
@ -148,6 +156,28 @@ GetLocalShardQueryForCache(Query *jobQuery, Task *task, ParamListInfo orig_param
} }
/*
* GetFastPathQueryStringForCache is a helper function which generates
* the local shard string based on the jobQuery. The function should
* not be used for generic purposes, it is specialized for local cached
* queries.
*
*/
static char *
GetFastPathQueryStringForCache(Query *jobQuery, Task *task, ParamListInfo
orig_paramListInfo)
{
char *shardQueryString =
DeparseLocalShardQuery(jobQuery, task->relationShardList,
task->anchorDistributedTableId,
task->anchorShardId);
ereport(DEBUG5, (errmsg("Local shard query that is going to be cached: %s",
shardQueryString)));
return shardQueryString;
}
/* /*
* DeparseLocalShardQuery is a helper function to deparse given jobQuery for the shard(s) * DeparseLocalShardQuery is a helper function to deparse given jobQuery for the shard(s)
* identified by the relationShardList, anchorDistributedTableId and anchorShardId. * identified by the relationShardList, anchorDistributedTableId and anchorShardId.

View File

@ -340,6 +340,7 @@ CopyNodeFastPathPlanCache(COPYFUNC_ARGS)
COPY_SCALAR_FIELD(shardId); COPY_SCALAR_FIELD(shardId);
COPY_NODE_FIELD(placementGroupIds); COPY_NODE_FIELD(placementGroupIds);
COPY_NODE_FIELD(localPlan); COPY_NODE_FIELD(localPlan);
COPY_STRING_FIELD(queryString);
} }

View File

@ -120,7 +120,24 @@ typedef struct FastPathPlanCache
uint64 shardId; uint64 shardId;
List *placementGroupIds; List *placementGroupIds;
/*
* Cache can be found in different ways and therefore stored differently on the
* definition.
*
* TODO: Ideally we only have either of the fields.
* investigate UNION of a C struct and CopyNodeFastPathPlanCache.
*/
/* union */
/*{*/
/* if fast path cache is for a local shard */
PlannedStmt *localPlan; PlannedStmt *localPlan;
/* if fast path cache is for a remote shard */
char *queryString;
/*} data;*/
} FastPathPlanCache; } FastPathPlanCache;