Reduce calls to FastPathRouterQuery()

Before this commit, we called it twice durning planning. Instead,
we save the information and pass it.
pull/3332/head
Onder Kalaci 2019-12-19 10:59:42 +01:00 committed by Jelte Fennema
parent 270571c106
commit ca293116fa
4 changed files with 35 additions and 2 deletions

View File

@ -128,6 +128,7 @@ distributed_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
bool setPartitionedTablesInherited = false;
List *rangeTableList = ExtractRangeTableEntryList(parse);
int rteIdCounter = 1;
bool fastPathRouterQuery = false;
if (cursorOptions & CURSOR_OPT_FORCE_DISTRIBUTED)
{
@ -151,6 +152,10 @@ distributed_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
else
{
needsDistributedPlanning = ListContainsDistributedTableRTE(rangeTableList);
if (needsDistributedPlanning)
{
fastPathRouterQuery = FastPathRouterQuery(parse);
}
}
}
@ -215,8 +220,11 @@ distributed_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
* transformations made by postgres' planner.
*/
if (needsDistributedPlanning && FastPathRouterQuery(originalQuery))
if (needsDistributedPlanning && fastPathRouterQuery)
{
plannerRestrictionContext->fastPathRestrictionContext->fastPathRouterQuery =
true;
result = FastPathPlanner(originalQuery, parse, boundParams);
}
else
@ -1870,6 +1878,9 @@ CreateAndPushPlannerRestrictionContext(void)
plannerRestrictionContext->joinRestrictionContext =
palloc0(sizeof(JoinRestrictionContext));
plannerRestrictionContext->fastPathRestrictionContext =
palloc0(sizeof(FastPathRestrictionContext));
plannerRestrictionContext->memoryContext = CurrentMemoryContext;
/* we'll apply logical AND as we add tables */
@ -1929,6 +1940,10 @@ ResetPlannerRestrictionContext(PlannerRestrictionContext *plannerRestrictionCont
plannerRestrictionContext->joinRestrictionContext =
palloc0(sizeof(JoinRestrictionContext));
plannerRestrictionContext->fastPathRestrictionContext =
palloc0(sizeof(FastPathRestrictionContext));
/* we'll apply logical AND as we add tables */
plannerRestrictionContext->relationRestrictionContext->allReferenceTables = true;
}

View File

@ -441,6 +441,9 @@ RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInter
plannerRestrictionContext->relationRestrictionContext);
copyOfPlannerRestrictionContext->joinRestrictionContext =
plannerRestrictionContext->joinRestrictionContext;
copyOfPlannerRestrictionContext->fastPathRestrictionContext =
plannerRestrictionContext->fastPathRestrictionContext;
relationRestrictionList =
copyOfPlannerRestrictionContext->relationRestrictionContext->
relationRestrictionList;

View File

@ -2014,6 +2014,8 @@ PlanRouterQuery(Query *originalQuery,
bool shardsPresent = false;
uint64 shardId = INVALID_SHARD_ID;
CmdType commandType = originalQuery->commandType;
bool fastPathRouterQuery =
plannerRestrictionContext->fastPathRestrictionContext->fastPathRouterQuery;
*placementList = NIL;
@ -2022,7 +2024,7 @@ PlanRouterQuery(Query *originalQuery,
* not been called. Thus, restriction information is not avaliable and we do the
* shard pruning based on the distribution column in the quals of the query.
*/
if (FastPathRouterQuery(originalQuery))
if (fastPathRouterQuery)
{
List *shardIntervalList =
TargetShardIntervalForFastPathQuery(originalQuery, partitionValueConst,

View File

@ -85,10 +85,23 @@ typedef struct JoinRestriction
RelOptInfo *outerrel;
} JoinRestriction;
typedef struct FastPathRestrictionContext
{
bool fastPathRouterQuery;
}FastPathRestrictionContext;
typedef struct PlannerRestrictionContext
{
RelationRestrictionContext *relationRestrictionContext;
JoinRestrictionContext *joinRestrictionContext;
/*
* When the query is qualified for fast path, we don't have
* the RelationRestrictionContext and JoinRestrictionContext
* since those are dependent to calling standard_planner.
* Instead, we keep this struct to pass some extra information.
*/
FastPathRestrictionContext *fastPathRestrictionContext;
bool hasSemiJoin;
MemoryContext memoryContext;
} PlannerRestrictionContext;