mirror of https://github.com/citusdata/citus.git
pluggable optimizations
parent
3e88dde672
commit
88e639283c
|
@ -31,8 +31,6 @@
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
|
||||||
typedef List *(*optimizeFn)(PlannerInfo *root, Path *originalPath);
|
|
||||||
|
|
||||||
typedef struct DistributedUnionPath
|
typedef struct DistributedUnionPath
|
||||||
{
|
{
|
||||||
CustomPath custom_path;
|
CustomPath custom_path;
|
||||||
|
@ -136,20 +134,22 @@ Cost RepartitionStartupCost = 1000;
|
||||||
Cost RepartitionPerRowCost = .000;
|
Cost RepartitionPerRowCost = .000;
|
||||||
Cost RepartitionPerMBCost = .01;
|
Cost RepartitionPerMBCost = .01;
|
||||||
|
|
||||||
/* list of functions that will be called to optimized in the joinhook*/
|
/* list of functions that will be called to optimized in the join hook */
|
||||||
static optimizeFn joinOptimizations[] = {
|
OptimizationEntry joinOptimizations[] = {
|
||||||
OptimizeJoinPath,
|
{.name = "pushdown", .fn = OptimizeJoinPath, .enabled = true},
|
||||||
OptimizeRepartitionInnerJoinPath,
|
{.name = "repartition", .fn = OptimizeRepartitionInnerJoinPath, .enabled = true},
|
||||||
|
|
||||||
/* BroadcastOuterJoinPath, */
|
{.name = "broadcast_outer", .fn = BroadcastOuterJoinPath, .enabled = false},
|
||||||
/* BroadcastInnerJoinPath, */
|
{.name = "broadcast_inner", .fn = BroadcastInnerJoinPath, .enabled = false},
|
||||||
/* GeoOverlapJoin, */
|
{.name = "geooverlap", .fn = GeoOverlapJoin, .enabled = false},
|
||||||
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
static optimizeFn groupOptimizations[] = {
|
OptimizationEntry groupOptimizations[] = {
|
||||||
PushDownAggPath,
|
{.name = "pushdown", .fn = PushDownAggPath, .enabled = true},
|
||||||
PartialPushDownAggPath,
|
{.name = "partial_pushdown", .fn = PartialPushDownAggPath, .enabled = true},
|
||||||
RepartitionAggPath,
|
{.name = "repartition", .fn = RepartitionAggPath, .enabled = true},
|
||||||
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
const CustomPathMethods geoScanMethods = {
|
const CustomPathMethods geoScanMethods = {
|
||||||
|
@ -1600,9 +1600,15 @@ PathBasedPlannerJoinHook(PlannerInfo *root,
|
||||||
Path *originalPath = NULL;
|
Path *originalPath = NULL;
|
||||||
foreach_ptr(originalPath, joinrel->pathlist)
|
foreach_ptr(originalPath, joinrel->pathlist)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sizeof(joinOptimizations) / sizeof(joinOptimizations[1]); i++)
|
for (int i = 0; joinOptimizations[i].fn != NULL; i++)
|
||||||
{
|
{
|
||||||
List *alternativePaths = joinOptimizations[i](root, originalPath);
|
if (!joinOptimizations[i].enabled)
|
||||||
|
{
|
||||||
|
/* skip disabled optimizations */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *alternativePaths = joinOptimizations[i].fn(root, originalPath);
|
||||||
newPaths = list_concat(newPaths, alternativePaths);
|
newPaths = list_concat(newPaths, alternativePaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1998,9 +2004,15 @@ PathBasedPlannerGroupAgg(PlannerInfo *root,
|
||||||
foreach_ptr(originalPath, output_rel->pathlist)
|
foreach_ptr(originalPath, output_rel->pathlist)
|
||||||
{
|
{
|
||||||
/* apply all optimizations on every available path */
|
/* apply all optimizations on every available path */
|
||||||
for (int i = 0; i < sizeof(groupOptimizations) / sizeof(groupOptimizations[1]); i++)
|
for (int i = 0; groupOptimizations[i].fn != NULL; i++)
|
||||||
{
|
{
|
||||||
List *alternativePaths = groupOptimizations[i](root, originalPath);
|
if (!groupOptimizations[i].enabled)
|
||||||
|
{
|
||||||
|
/* skip optimizations when they are disabled */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *alternativePaths = groupOptimizations[i].fn(root, originalPath);
|
||||||
newPaths = list_concat(newPaths, alternativePaths);
|
newPaths = list_concat(newPaths, alternativePaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1260,6 +1260,40 @@ RegisterCitusConfigVariables(void)
|
||||||
GUC_STANDARD,
|
GUC_STANDARD,
|
||||||
NULL,NULL,NULL);
|
NULL,NULL,NULL);
|
||||||
|
|
||||||
|
/* pathbased planner optimization rules */
|
||||||
|
StringInfoData buf = { 0 };
|
||||||
|
initStringInfo(&buf);
|
||||||
|
|
||||||
|
for (int i = 0; joinOptimizations[i].fn != NULL; i++)
|
||||||
|
{
|
||||||
|
resetStringInfo(&buf);
|
||||||
|
appendStringInfo(&buf, "citus.path_based_planner_join_%s", joinOptimizations[i].name);
|
||||||
|
DefineCustomBoolVariable(
|
||||||
|
pstrdup(buf.data),
|
||||||
|
gettext_noop("Path based planner join optimization"),
|
||||||
|
NULL,
|
||||||
|
&joinOptimizations[i].enabled,
|
||||||
|
joinOptimizations[i].enabled,
|
||||||
|
PGC_USERSET,
|
||||||
|
GUC_STANDARD,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; groupOptimizations[i].fn != NULL; i++)
|
||||||
|
{
|
||||||
|
resetStringInfo(&buf);
|
||||||
|
appendStringInfo(&buf, "citus.path_based_planner_group_%s", groupOptimizations[i].name);
|
||||||
|
DefineCustomBoolVariable(
|
||||||
|
pstrdup(buf.data),
|
||||||
|
gettext_noop("Path based planner join optimization"),
|
||||||
|
NULL,
|
||||||
|
&groupOptimizations[i].enabled,
|
||||||
|
groupOptimizations[i].enabled,
|
||||||
|
PGC_USERSET,
|
||||||
|
GUC_STANDARD,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
DefineCustomIntVariable(
|
DefineCustomIntVariable(
|
||||||
"citus.local_shared_pool_size",
|
"citus.local_shared_pool_size",
|
||||||
gettext_noop(
|
gettext_noop(
|
||||||
|
|
|
@ -8,6 +8,15 @@
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
#include "nodes/pathnodes.h"
|
#include "nodes/pathnodes.h"
|
||||||
|
|
||||||
|
typedef List *(*optimizeFn)(PlannerInfo *root, Path *originalPath);
|
||||||
|
|
||||||
|
typedef struct OptimizationEntry
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
bool enabled;
|
||||||
|
optimizeFn fn;
|
||||||
|
} OptimizationEntry;
|
||||||
|
|
||||||
extern bool EnableBroadcastJoin;
|
extern bool EnableBroadcastJoin;
|
||||||
|
|
||||||
extern Cost CollectStartupCost;
|
extern Cost CollectStartupCost;
|
||||||
|
@ -18,6 +27,9 @@ extern Cost RepartitionStartupCost;
|
||||||
extern Cost RepartitionPerRowCost;
|
extern Cost RepartitionPerRowCost;
|
||||||
extern Cost RepartitionPerMBCost;
|
extern Cost RepartitionPerMBCost;
|
||||||
|
|
||||||
|
extern OptimizationEntry joinOptimizations[];
|
||||||
|
extern OptimizationEntry groupOptimizations[];
|
||||||
|
|
||||||
extern void PathBasedPlannerRelationHook(PlannerInfo *root,
|
extern void PathBasedPlannerRelationHook(PlannerInfo *root,
|
||||||
RelOptInfo *relOptInfo,
|
RelOptInfo *relOptInfo,
|
||||||
Index restrictionIndex,
|
Index restrictionIndex,
|
||||||
|
|
Loading…
Reference in New Issue