mirror of https://github.com/citusdata/citus.git
more add_path hook experiments
parent
d092ef5e02
commit
51b65d7dec
|
@ -74,6 +74,7 @@ static uint64 NextPlanId = 1;
|
||||||
/* keep track of planner call stack levels */
|
/* keep track of planner call stack levels */
|
||||||
int PlannerLevel = 0;
|
int PlannerLevel = 0;
|
||||||
bool UseCustomPath = false;
|
bool UseCustomPath = false;
|
||||||
|
bool PlanAllPaths = false;
|
||||||
bool OnlyGeoPartitioning = false;
|
bool OnlyGeoPartitioning = false;
|
||||||
bool UseGeoPartitioning = true;
|
bool UseGeoPartitioning = true;
|
||||||
bool EnableGeoPartitioningGrouping = true;
|
bool EnableGeoPartitioningGrouping = true;
|
||||||
|
|
|
@ -2502,6 +2502,30 @@ PathTreeWalker(Node *node, bool (*walker)(), void *context)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case T_MaterialPath:
|
||||||
|
{
|
||||||
|
MaterialPath *path = castNode(MaterialPath, node);
|
||||||
|
if (walker(path->subpath, context))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
case T_SortPath:
|
||||||
|
{
|
||||||
|
SortPath *path = castNode(SortPath, node);
|
||||||
|
if (walker(path->subpath, context))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
case T_ProjectionPath:
|
||||||
|
{
|
||||||
|
ProjectionPath *path = castNode(ProjectionPath, node);
|
||||||
|
if (walker(path->subpath, context))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* paths not having nesting */
|
/* paths not having nesting */
|
||||||
case T_Path:
|
case T_Path:
|
||||||
case T_IndexPath:
|
case T_IndexPath:
|
||||||
|
@ -2533,8 +2557,13 @@ ColocationGroupsForPathWalker(Node *node, ColocationGroups *context)
|
||||||
DistributedUnionPath *collect = NULL;
|
DistributedUnionPath *collect = NULL;
|
||||||
if (IsDistributedUnion((Path *) node, false, &collect))
|
if (IsDistributedUnion((Path *) node, false, &collect))
|
||||||
{
|
{
|
||||||
|
int colocationId = (int) collect->colocationId;
|
||||||
|
if (colocationId == -1)
|
||||||
|
{
|
||||||
|
colocationId = 0;
|
||||||
|
}
|
||||||
context->colocationIds = bms_add_member(context->colocationIds,
|
context->colocationIds = bms_add_member(context->colocationIds,
|
||||||
(int) collect->colocationId);
|
colocationId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2550,24 +2579,77 @@ ColocationGroupsForPath(Path *node)
|
||||||
return context.colocationIds;
|
return context.colocationIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct ColocationGroupsList
|
||||||
|
{
|
||||||
|
/* configuration */
|
||||||
|
bool unique;
|
||||||
|
bool sorted;
|
||||||
|
|
||||||
|
/* output */
|
||||||
|
List *list;
|
||||||
|
} ColocationGroupsList;
|
||||||
|
|
||||||
|
static bool ColocationGroupsForPathListWalker(Node *node, ColocationGroupsList *context);
|
||||||
|
static bool
|
||||||
|
ColocationGroupsForPathListWalker(Node *node, ColocationGroupsList *context)
|
||||||
|
{
|
||||||
|
if (node == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DistributedUnionPath *collect = NULL;
|
||||||
|
if (IsDistributedUnion((Path *) node, false, &collect))
|
||||||
|
{
|
||||||
|
int colocationId = (int) collect->colocationId;
|
||||||
|
if (!context->unique || !list_member_int(context->list, colocationId))
|
||||||
|
context->list = lappend_int(context->list, colocationId);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PathTreeWalker(node, ColocationGroupsForPathListWalker, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static List *
|
||||||
|
ColocationGroupsForPathList(Path *node)
|
||||||
|
{
|
||||||
|
ColocationGroupsList context = { .unique = true, .sorted = true };
|
||||||
|
ColocationGroupsForPathListWalker((Node *)node, &context);
|
||||||
|
|
||||||
|
if (context.sorted)
|
||||||
|
list_sort(context.list, list_int_cmp);
|
||||||
|
|
||||||
|
return context.list;
|
||||||
|
}
|
||||||
|
|
||||||
PathComparison
|
PathComparison
|
||||||
PathBasedPlannerComparePath(Path *new_path, Path *old_path)
|
PathBasedPlannerComparePath(Path *new_path, Path *old_path)
|
||||||
{
|
{
|
||||||
|
if (PlanAllPaths)
|
||||||
|
{
|
||||||
|
return PATH_DIFFERENT;
|
||||||
|
}
|
||||||
|
|
||||||
if (!UseCustomPath)
|
if (!UseCustomPath)
|
||||||
{
|
{
|
||||||
return PATH_EQUAL;
|
return PATH_EQUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmapset *newColocationIds = ColocationGroupsForPath(new_path);
|
return PATH_EQUAL;
|
||||||
Bitmapset *oldColocationIds = ColocationGroupsForPath(old_path);
|
}
|
||||||
|
|
||||||
BMS_Comparison cmp = bms_subset_compare(newColocationIds, oldColocationIds);
|
add_path_merit_list_hook_type prev_add_path_merit_list_hook = NULL;
|
||||||
|
List *
|
||||||
bms_free(newColocationIds);
|
PathBasedMeritListHook(Path *path)
|
||||||
bms_free(oldColocationIds);
|
{
|
||||||
|
List *merits = NIL;
|
||||||
if (cmp == BMS_EQUAL)
|
if (prev_add_path_merit_list_hook)
|
||||||
return PATH_EQUAL;
|
{
|
||||||
|
merits = prev_add_path_merit_list_hook(path);
|
||||||
return PATH_DIFFERENT;
|
}
|
||||||
|
|
||||||
|
List *colocationIds = ColocationGroupsForPathList(path);
|
||||||
|
return lappend(merits, colocationIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,6 +300,8 @@ _PG_init(void)
|
||||||
set_join_pathlist_hook = multi_join_restriction_hook;
|
set_join_pathlist_hook = multi_join_restriction_hook;
|
||||||
create_upper_paths_hook = PathBasedPlannedUpperPathHook;
|
create_upper_paths_hook = PathBasedPlannedUpperPathHook;
|
||||||
compare_path_hook = PathBasedPlannerComparePath;
|
compare_path_hook = PathBasedPlannerComparePath;
|
||||||
|
prev_add_path_merit_list_hook = add_path_merit_list_hook;
|
||||||
|
add_path_merit_list_hook = PathBasedMeritListHook;
|
||||||
|
|
||||||
ExecutorStart_hook = CitusExecutorStart;
|
ExecutorStart_hook = CitusExecutorStart;
|
||||||
ExecutorRun_hook = CitusExecutorRun;
|
ExecutorRun_hook = CitusExecutorRun;
|
||||||
|
@ -1148,6 +1150,16 @@ RegisterCitusConfigVariables(void)
|
||||||
GUC_STANDARD,
|
GUC_STANDARD,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
|
DefineCustomBoolVariable(
|
||||||
|
"citus.plan_all_paths",
|
||||||
|
gettext_noop("Disable any pruning of paths in add_path for debugging purposes"),
|
||||||
|
NULL,
|
||||||
|
&PlanAllPaths,
|
||||||
|
false,
|
||||||
|
PGC_USERSET,
|
||||||
|
GUC_STANDARD,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
DefineCustomStringVariable(
|
DefineCustomStringVariable(
|
||||||
"citus.local_hostname",
|
"citus.local_hostname",
|
||||||
gettext_noop("Sets the hostname when connecting back to itself."),
|
gettext_noop("Sets the hostname when connecting back to itself."),
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
/* level of planner calls */
|
/* level of planner calls */
|
||||||
extern int PlannerLevel;
|
extern int PlannerLevel;
|
||||||
extern bool UseCustomPath;
|
extern bool UseCustomPath;
|
||||||
|
extern bool PlanAllPaths;
|
||||||
extern bool OnlyGeoPartitioning;
|
extern bool OnlyGeoPartitioning;
|
||||||
extern bool UseGeoPartitioning;
|
extern bool UseGeoPartitioning;
|
||||||
extern bool EnableGeoPartitioningGrouping;
|
extern bool EnableGeoPartitioningGrouping;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
#include "nodes/pathnodes.h"
|
#include "nodes/pathnodes.h"
|
||||||
|
#include "optimizer/paths.h"
|
||||||
|
|
||||||
typedef List *(*optimizeFn)(PlannerInfo *root, Path *originalPath);
|
typedef List *(*optimizeFn)(PlannerInfo *root, Path *originalPath);
|
||||||
|
|
||||||
|
@ -47,5 +48,8 @@ extern void PathBasedPlannedUpperPathHook(PlannerInfo *root,
|
||||||
void *extra);
|
void *extra);
|
||||||
|
|
||||||
extern PathComparison PathBasedPlannerComparePath(Path *new_path, Path *old_path);
|
extern PathComparison PathBasedPlannerComparePath(Path *new_path, Path *old_path);
|
||||||
|
extern List * PathBasedMeritListHook(Path *path);
|
||||||
|
|
||||||
|
extern add_path_merit_list_hook_type prev_add_path_merit_list_hook;
|
||||||
|
|
||||||
#endif //CITUS_PATH_BASED_PLANNER_H
|
#endif //CITUS_PATH_BASED_PLANNER_H
|
||||||
|
|
Loading…
Reference in New Issue