From f952d9c61474be4ec95458fa4e1a80991c63666a Mon Sep 17 00:00:00 2001 From: Nils Dijk Date: Thu, 7 May 2020 19:23:08 +0200 Subject: [PATCH] easily add new join optimization functions --- .../distributed/planner/path_based_planner.c | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/planner/path_based_planner.c b/src/backend/distributed/planner/path_based_planner.c index 8dad7612e..eba3960e7 100644 --- a/src/backend/distributed/planner/path_based_planner.c +++ b/src/backend/distributed/planner/path_based_planner.c @@ -21,6 +21,8 @@ #include "optimizer/pathnode.h" #include "optimizer/restrictinfo.h" +typedef Path * (*optimizeFn)(Path *originalPath); + static Plan * CreateDistributedUnionPlan(PlannerInfo *root, RelOptInfo *rel, struct CustomPath *best_path, List *tlist, List *clauses, List *custom_plans); static List * ReparameterizeDistributedUnion(PlannerInfo *root, List *custom_private, RelOptInfo *child_rel); static CustomPath * WrapTableAccessWithDistributedUnion(Path *originalPath, uint32 colocationId, Expr *partitionValue, Oid sampleRelid); @@ -35,6 +37,11 @@ static void PathBasedPlannerGroupAgg(PlannerInfo *root, RelOptInfo *input_rel, R static Path * OptimizeGroupAgg(PlannerInfo *root, Path *originalPath); static bool CanOptimizeAggPath(PlannerInfo *root, AggPath *apath); +/* list of functions that will be called to optimized in the joinhook*/ +static optimizeFn joinOptimizations[] = { + OptimizeJoinPath, +}; + typedef struct DistributedUnionPath { CustomPath custom_path; @@ -338,7 +345,7 @@ OptimizeJoinPath(Path *originalPath) case T_HashJoin: { const JoinPath *jpath = (JoinPath *) originalPath; - if (CanOptimizeJoinPath(jpath)) + if (jpath->jointype == JOIN_INNER && CanOptimizeJoinPath(jpath)) { /* we can only optimize the Distributed union if the colocationId's are the same, taking any would suffice */ DistributedUnionPath *baseDistUnion = (DistributedUnionPath *) jpath->innerjoinpath; @@ -390,16 +397,16 @@ PathBasedPlannerJoinHook(PlannerInfo *root, */ List *newPaths = NIL; - if (jointype == JOIN_INNER) + ListCell *pathCell = NULL; + foreach(pathCell, joinrel->pathlist) { - ListCell *pathCell = NULL; - foreach(pathCell, joinrel->pathlist) + Path *originalPath = lfirst(pathCell); + for (int i=0; i < sizeof(joinOptimizations)/sizeof(joinOptimizations[1]); i++) { - Path *originalPath = lfirst(pathCell); - Path *optimizedPath = OptimizeJoinPath(originalPath); - if (optimizedPath) + Path *alternativePath = joinOptimizations[i](originalPath); + if (alternativePath) { - newPaths = lappend(newPaths, optimizedPath); + newPaths = lappend(newPaths, alternativePath); } } }