easily add new join optimization functions

moonshot/custom-path
Nils Dijk 2020-05-07 19:23:08 +02:00
parent 6b8e0a6105
commit f952d9c614
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
1 changed files with 15 additions and 8 deletions

View File

@ -21,6 +21,8 @@
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"
#include "optimizer/restrictinfo.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 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 List * ReparameterizeDistributedUnion(PlannerInfo *root, List *custom_private, RelOptInfo *child_rel);
static CustomPath * WrapTableAccessWithDistributedUnion(Path *originalPath, uint32 colocationId, Expr *partitionValue, Oid sampleRelid); 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 Path * OptimizeGroupAgg(PlannerInfo *root, Path *originalPath);
static bool CanOptimizeAggPath(PlannerInfo *root, AggPath *apath); 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 typedef struct DistributedUnionPath
{ {
CustomPath custom_path; CustomPath custom_path;
@ -338,7 +345,7 @@ OptimizeJoinPath(Path *originalPath)
case T_HashJoin: case T_HashJoin:
{ {
const JoinPath *jpath = (JoinPath *) originalPath; 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 */ /* we can only optimize the Distributed union if the colocationId's are the same, taking any would suffice */
DistributedUnionPath *baseDistUnion = (DistributedUnionPath *) jpath->innerjoinpath; DistributedUnionPath *baseDistUnion = (DistributedUnionPath *) jpath->innerjoinpath;
@ -390,16 +397,16 @@ PathBasedPlannerJoinHook(PlannerInfo *root,
*/ */
List *newPaths = NIL; List *newPaths = NIL;
if (jointype == JOIN_INNER) ListCell *pathCell = NULL;
foreach(pathCell, joinrel->pathlist)
{ {
ListCell *pathCell = NULL; Path *originalPath = lfirst(pathCell);
foreach(pathCell, joinrel->pathlist) for (int i=0; i < sizeof(joinOptimizations)/sizeof(joinOptimizations[1]); i++)
{ {
Path *originalPath = lfirst(pathCell); Path *alternativePath = joinOptimizations[i](originalPath);
Path *optimizedPath = OptimizeJoinPath(originalPath); if (alternativePath)
if (optimizedPath)
{ {
newPaths = lappend(newPaths, optimizedPath); newPaths = lappend(newPaths, alternativePath);
} }
} }
} }