mirror of https://github.com/citusdata/citus.git
reindent pathbased planner
parent
51d498e2c2
commit
0341d9fe80
|
@ -1,4 +1,5 @@
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/* Created by Nils Dijk on 17/01/2020. */
|
/* Created by Nils Dijk on 17/01/2020. */
|
||||||
/* */
|
/* */
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
@ -113,6 +114,7 @@ bool EnableBroadcastJoin = true;
|
||||||
static optimizeFn joinOptimizations[] = {
|
static optimizeFn joinOptimizations[] = {
|
||||||
OptimizeJoinPath,
|
OptimizeJoinPath,
|
||||||
OptimizeRepartitionInnerJoinPath,
|
OptimizeRepartitionInnerJoinPath,
|
||||||
|
|
||||||
/* BroadcastOuterJoinPath, */
|
/* BroadcastOuterJoinPath, */
|
||||||
/* BroadcastInnerJoinPath, */
|
/* BroadcastInnerJoinPath, */
|
||||||
/* GeoOverlapJoin, */
|
/* GeoOverlapJoin, */
|
||||||
|
@ -171,7 +173,8 @@ typedef struct TransformVarToParamExternMutatorContext
|
||||||
|
|
||||||
|
|
||||||
static Node *
|
static Node *
|
||||||
TransformVarToParamExternMutator(Node *node, TransformVarToParamExternMutatorContext *context)
|
TransformVarToParamExternMutator(Node *node,
|
||||||
|
TransformVarToParamExternMutatorContext *context)
|
||||||
{
|
{
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
{
|
{
|
||||||
|
@ -189,6 +192,7 @@ TransformVarToParamExternMutator(Node *node, TransformVarToParamExternMutatorCon
|
||||||
originalVarNo = var->varno;
|
originalVarNo = var->varno;
|
||||||
}
|
}
|
||||||
Assert(originalVarNo > 0);
|
Assert(originalVarNo > 0);
|
||||||
|
|
||||||
/* If not to be replaced, we can just return the Var unmodified */
|
/* If not to be replaced, we can just return the Var unmodified */
|
||||||
if (!bms_is_member(originalVarNo, context->root->curOuterRels))
|
if (!bms_is_member(originalVarNo, context->root->curOuterRels))
|
||||||
{
|
{
|
||||||
|
@ -214,11 +218,10 @@ TransformVarToParamExternMutator(Node *node, TransformVarToParamExternMutatorCon
|
||||||
}
|
}
|
||||||
else if (IsA(node, Query))
|
else if (IsA(node, Query))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (Node *) query_tree_mutator((Query *) node,
|
return (Node *) query_tree_mutator((Query *) node,
|
||||||
TransformVarToParamExternMutator,
|
TransformVarToParamExternMutator,
|
||||||
(void *) context,
|
(void *) context,
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression_tree_mutator(node, TransformVarToParamExternMutator,
|
return expression_tree_mutator(node, TransformVarToParamExternMutator,
|
||||||
|
@ -230,8 +233,8 @@ static Query *
|
||||||
TransformVarToParamExtern(Query *query, PlannerInfo *root, Index *varnoMapping)
|
TransformVarToParamExtern(Query *query, PlannerInfo *root, Index *varnoMapping)
|
||||||
{
|
{
|
||||||
TransformVarToParamExternMutatorContext context = {
|
TransformVarToParamExternMutatorContext context = {
|
||||||
root,
|
root,
|
||||||
varnoMapping
|
varnoMapping
|
||||||
};
|
};
|
||||||
|
|
||||||
return castNode(Query, TransformVarToParamExternMutator((Node *) query, &context));
|
return castNode(Query, TransformVarToParamExternMutator((Node *) query, &context));
|
||||||
|
@ -254,7 +257,8 @@ CreateDistributedUnionPlan(PlannerInfo *root,
|
||||||
ShardInterval *shardInterval = NULL;
|
ShardInterval *shardInterval = NULL;
|
||||||
|
|
||||||
Index *varnoMapping = NULL; /* store mapping back for outerrel checks */
|
Index *varnoMapping = NULL; /* store mapping back for outerrel checks */
|
||||||
Query *q = GetQueryFromPath(root, distUnion->worker_path, tlist, clauses, &varnoMapping);
|
Query *q = GetQueryFromPath(root, distUnion->worker_path, tlist, clauses,
|
||||||
|
&varnoMapping);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assume shards are colocated, any shard should suffice for now to find the initial
|
* Assume shards are colocated, any shard should suffice for now to find the initial
|
||||||
|
@ -336,8 +340,8 @@ CreateDistributedUnionPlan(PlannerInfo *root,
|
||||||
/* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
|
/* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
|
||||||
clauses = extract_actual_clauses(clauses, false);
|
clauses = extract_actual_clauses(clauses, false);
|
||||||
|
|
||||||
// plan->scan.plan.qual = clauses;
|
/* plan->scan.plan.qual = clauses; */
|
||||||
// plan->custom_exprs = clauses;
|
/* plan->custom_exprs = clauses; */
|
||||||
|
|
||||||
return (Plan *) plan;
|
return (Plan *) plan;
|
||||||
}
|
}
|
||||||
|
@ -806,11 +810,11 @@ typedef struct GeoJoinPathMatch
|
||||||
{
|
{
|
||||||
Const *stdwithinDistanceConst;
|
Const *stdwithinDistanceConst;
|
||||||
|
|
||||||
// AggPath *innerGrouping;
|
/* AggPath *innerGrouping; */
|
||||||
DistributedUnionPath *innerDistUnion;
|
DistributedUnionPath *innerDistUnion;
|
||||||
GeoScanPath *innerPath;
|
GeoScanPath *innerPath;
|
||||||
|
|
||||||
// AggPath *outerGrouping;
|
/* AggPath *outerGrouping; */
|
||||||
DistributedUnionPath *outerDistUnion;
|
DistributedUnionPath *outerDistUnion;
|
||||||
GeoScanPath *outerPath;
|
GeoScanPath *outerPath;
|
||||||
} GeoJoinPathMatch;
|
} GeoJoinPathMatch;
|
||||||
|
@ -835,6 +839,7 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
MatchJoin(
|
MatchJoin(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
JOIN_INNER,
|
JOIN_INNER,
|
||||||
|
|
||||||
/* match on join restriction info */
|
/* match on join restriction info */
|
||||||
MatchJoinRestrictions(
|
MatchJoinRestrictions(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -849,6 +854,7 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
MatchConst(
|
MatchConst(
|
||||||
&match.stdwithinDistanceConst,
|
&match.stdwithinDistanceConst,
|
||||||
MatchFields(consttype == FLOAT8OID))))),
|
MatchFields(consttype == FLOAT8OID))))),
|
||||||
|
|
||||||
/* match inner path in join */
|
/* match inner path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -858,14 +864,15 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
&match.innerDistUnion,
|
&match.innerDistUnion,
|
||||||
MatchGeoScan(
|
MatchGeoScan(
|
||||||
&match.innerPath)))),
|
&match.innerPath)))),
|
||||||
|
|
||||||
/* match outer path in join */
|
/* match outer path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
MatchGrouping(
|
MatchGrouping(
|
||||||
NoCapture, /*&match.outerGrouping,*/
|
NoCapture, /*&match.outerGrouping,*/
|
||||||
MatchDistributedUnion(&match.outerDistUnion,
|
MatchDistributedUnion(&match.outerDistUnion,
|
||||||
MatchGeoScan(
|
MatchGeoScan(
|
||||||
&match.outerPath))))))
|
&match.outerPath))))))
|
||||||
{
|
{
|
||||||
didMatch = true;
|
didMatch = true;
|
||||||
}
|
}
|
||||||
|
@ -877,6 +884,7 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
MatchJoin(
|
MatchJoin(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
JOIN_INNER,
|
JOIN_INNER,
|
||||||
|
|
||||||
/* match on join restriction info */
|
/* match on join restriction info */
|
||||||
MatchJoinRestrictions(
|
MatchJoinRestrictions(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -891,6 +899,7 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
MatchConst(
|
MatchConst(
|
||||||
&match.stdwithinDistanceConst,
|
&match.stdwithinDistanceConst,
|
||||||
MatchFields(consttype == FLOAT8OID))))),
|
MatchFields(consttype == FLOAT8OID))))),
|
||||||
|
|
||||||
/* match inner path in join */
|
/* match inner path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -898,6 +907,7 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
&match.innerDistUnion,
|
&match.innerDistUnion,
|
||||||
MatchGeoScan(
|
MatchGeoScan(
|
||||||
&match.innerPath))),
|
&match.innerPath))),
|
||||||
|
|
||||||
/* match outer path in join */
|
/* match outer path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -922,17 +932,17 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
|
|
||||||
jpath->innerjoinpath = (Path *) match.innerPath;
|
jpath->innerjoinpath = (Path *) match.innerPath;
|
||||||
jpath->outerjoinpath = (Path *) match.outerPath;
|
jpath->outerjoinpath = (Path *) match.outerPath;
|
||||||
// (Path *) create_append_path(
|
/* (Path *) create_append_path( */
|
||||||
// root,
|
/* root, */
|
||||||
// match.outerPath->custom_path.path.parent,
|
/* match.outerPath->custom_path.path.parent, */
|
||||||
// list_make1(match.outerPath), /* TODO add the result of the shuffled job */
|
/* list_make1(match.outerPath), / * TODO add the result of the shuffled job * / */
|
||||||
// NIL,
|
/* NIL, */
|
||||||
// NIL,
|
/* NIL, */
|
||||||
// NULL,
|
/* NULL, */
|
||||||
// 0,
|
/* 0, */
|
||||||
// false,
|
/* false, */
|
||||||
// NIL,
|
/* NIL, */
|
||||||
// match.outerPath->custom_path.path.rows + 0);
|
/* match.outerPath->custom_path.path.rows + 0); */
|
||||||
|
|
||||||
jpath->path.startup_cost -= 2000; /* remove the double dist union cost */
|
jpath->path.startup_cost -= 2000; /* remove the double dist union cost */
|
||||||
jpath->path.total_cost -= 2000; /* remove the double dist union cost */
|
jpath->path.total_cost -= 2000; /* remove the double dist union cost */
|
||||||
|
@ -965,14 +975,17 @@ OptimizeJoinPath(PlannerInfo *root, Path *originalPath)
|
||||||
MatchJoin(
|
MatchJoin(
|
||||||
&jpath,
|
&jpath,
|
||||||
JOIN_INNER,
|
JOIN_INNER,
|
||||||
|
|
||||||
/* match on join restriction info */
|
/* match on join restriction info */
|
||||||
MatchAny,
|
MatchAny,
|
||||||
|
|
||||||
/* match inner path in join */
|
/* match inner path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
MatchDistributedUnion(
|
MatchDistributedUnion(
|
||||||
&innerDU,
|
&innerDU,
|
||||||
MatchAny)),
|
MatchAny)),
|
||||||
|
|
||||||
/* match outer path in join */
|
/* match outer path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -1036,22 +1049,25 @@ OptimizeRepartitionInnerJoinPath(PlannerInfo *root, Path *originalPath)
|
||||||
* +---------------------+ +---------------------+
|
* +---------------------+ +---------------------+
|
||||||
* | Collect | | Collect |
|
* | Collect | | Collect |
|
||||||
* | - ColocationID: $1 | | - ColocationID: !$1 |
|
* | - ColocationID: $1 | | - ColocationID: !$1 |
|
||||||
* +---------------------+ +---------------------+
|
* +---------------------+ +---------------------+
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
IfPathMatch(
|
IfPathMatch(
|
||||||
originalPath,
|
originalPath,
|
||||||
MatchJoin(
|
MatchJoin(
|
||||||
&joinPath,
|
&joinPath,
|
||||||
JOIN_INNER,
|
JOIN_INNER,
|
||||||
|
|
||||||
/* match on join restriction info */
|
/* match on join restriction info */
|
||||||
MatchAny,
|
MatchAny,
|
||||||
|
|
||||||
/* match inner path in join */
|
/* match inner path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
MatchDistributedUnion(
|
MatchDistributedUnion(
|
||||||
&innerDU,
|
&innerDU,
|
||||||
MatchAny)),
|
MatchAny)),
|
||||||
|
|
||||||
/* match outer path in join */
|
/* match outer path in join */
|
||||||
SkipReadThrough(
|
SkipReadThrough(
|
||||||
NoCapture,
|
NoCapture,
|
||||||
|
@ -1125,11 +1141,11 @@ OptimizeRepartitionInnerJoinPath(PlannerInfo *root, Path *originalPath)
|
||||||
/* create Collect on top of new join, base Collect on matched outer Collect */
|
/* create Collect on top of new join, base Collect on matched outer Collect */
|
||||||
const DistributedUnionPath *baseDistUnion = outerDU;
|
const DistributedUnionPath *baseDistUnion = outerDU;
|
||||||
Path *newPath = (Path *) WrapTableAccessWithDistributedUnion(
|
Path *newPath = (Path *) WrapTableAccessWithDistributedUnion(
|
||||||
(Path *) newJoinPath,
|
(Path *) newJoinPath,
|
||||||
baseDistUnion->colocationId,
|
baseDistUnion->colocationId,
|
||||||
baseDistUnion->partitionValue,
|
baseDistUnion->partitionValue,
|
||||||
baseDistUnion->sampleRelid,
|
baseDistUnion->sampleRelid,
|
||||||
baseDistUnion->custom_path.custom_paths);
|
baseDistUnion->custom_path.custom_paths);
|
||||||
|
|
||||||
return list_make1(newPath);
|
return list_make1(newPath);
|
||||||
}
|
}
|
||||||
|
@ -1142,7 +1158,7 @@ static Path *
|
||||||
CreateRepartitionNode(uint32 colocationId, Path *worker_path)
|
CreateRepartitionNode(uint32 colocationId, Path *worker_path)
|
||||||
{
|
{
|
||||||
RepartitionPath *repartition = (RepartitionPath *)
|
RepartitionPath *repartition = (RepartitionPath *)
|
||||||
newNode(sizeof(RepartitionPath), T_CustomPath);
|
newNode(sizeof(RepartitionPath), T_CustomPath);
|
||||||
|
|
||||||
repartition->custom_path.path.pathtype = T_CustomScan;
|
repartition->custom_path.path.pathtype = T_CustomScan;
|
||||||
repartition->custom_path.path.parent = worker_path->parent;
|
repartition->custom_path.path.parent = worker_path->parent;
|
||||||
|
|
Loading…
Reference in New Issue