rewriting tree to distributed plan

moonshot/custom-path
Nils Dijk 2021-01-25 14:43:51 +01:00
parent 1aa86f6b1c
commit 089650db11
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
2 changed files with 119 additions and 37 deletions

View File

@ -739,11 +739,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;
@ -755,51 +755,132 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
{ {
GeoJoinPathMatch match = { 0 }; GeoJoinPathMatch match = { 0 };
IfPathMatch( bool didMatch = false;
originalPath,
MatchJoin( /*
NoCapture, * temporary nest the matcher till we figure out the final grouping, for now we need
JOIN_INNER, * to be able to toggle between
/* match on join restriction info */ */
MatchJoinRestrictions( if (EnableGeoPartitioningGrouping)
{
IfPathMatch(
originalPath,
MatchJoin(
NoCapture, NoCapture,
MatchExprNamedOperation( JOIN_INNER,
/* match on join restriction info */
MatchJoinRestrictions(
NoCapture, NoCapture,
geometry_overlaps, MatchExprNamedOperation(
MatchVar(NoCapture),
MatchExprNamedFunction(
NoCapture, NoCapture,
st_expand, geometry_overlaps,
MatchVar(NoCapture), MatchVar(NoCapture),
MatchConst( MatchExprNamedFunction(
&match.stdwithinDistanceConst, NoCapture,
MatchFields(consttype == FLOAT8OID))))), st_expand,
/* match inner path in join */ MatchVar(NoCapture),
SkipReadThrough( MatchConst(
&match.stdwithinDistanceConst,
MatchFields(consttype == FLOAT8OID))))),
/* match inner path in join */
SkipReadThrough(
NoCapture,
MatchGrouping(
NoCapture, /*&match.innerGrouping,*/
MatchDistributedUnion(
&match.innerDistUnion,
MatchGeoScan(
&match.innerPath)))),
/* match outer path in join */
SkipReadThrough(
NoCapture,
MatchGrouping(
NoCapture, /*&match.outerGrouping,*/
MatchDistributedUnion(&match.outerDistUnion,
MatchGeoScan(
&match.outerPath))))))
{
didMatch = true;
}
}
else
{
IfPathMatch(
originalPath,
MatchJoin(
NoCapture, NoCapture,
MatchGrouping( JOIN_INNER,
&match.innerGrouping, /* match on join restriction info */
MatchJoinRestrictions(
NoCapture,
MatchExprNamedOperation(
NoCapture,
geometry_overlaps,
MatchVar(NoCapture),
MatchExprNamedFunction(
NoCapture,
st_expand,
MatchVar(NoCapture),
MatchConst(
&match.stdwithinDistanceConst,
MatchFields(consttype == FLOAT8OID))))),
/* match inner path in join */
SkipReadThrough(
NoCapture,
MatchDistributedUnion( MatchDistributedUnion(
&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(
&match.outerGrouping,
MatchDistributedUnion(&match.outerDistUnion, MatchDistributedUnion(&match.outerDistUnion,
MatchGeoScan( MatchGeoScan(
&match.outerPath)))))) &match.outerPath)))))
{ {
/* have a match on the geo join pattern, all fields are stored in `match` */ didMatch = true;
ereport(DEBUG1, (errmsg("my custom code %p: %f", }
match.innerGrouping,
DatumGetFloat8(match.stdwithinDistanceConst->constvalue)
)));
} }
(void) &match; if (didMatch)
{
/* have a match on the geo join pattern, all fields are stored in `match` */
ereport(DEBUG1, (errmsg("distance join with distance: %f",
DatumGetFloat8(match.stdwithinDistanceConst->constvalue)
)));
JoinPath *jpath = makeNode(NestPath);
*jpath = *((JoinPath *) originalPath); /* copy basic join settings */
jpath->path.type = T_NestPath;
jpath->innerjoinpath = (Path *) match.innerPath;
jpath->outerjoinpath = (Path *) match.outerPath;
// (Path *) create_append_path(
// root,
// match.outerPath->custom_path.path.parent,
// list_make1(match.outerPath), /* TODO add the result of the shuffled job */
// NIL,
// NIL,
// NULL,
// 0,
// false,
// NIL,
// match.outerPath->custom_path.path.rows + 0);
jpath->path.startup_cost -= 2000; /* remove the double dist union cost */
jpath->path.total_cost -= 2000; /* remove the double dist union cost */
/* TODO add grouping */
Path *newPath = (Path *) WrapTableAccessWithDistributedUnion(
(Path *) jpath,
match.innerDistUnion->colocationId,
match.innerDistUnion->partitionValue,
match.innerDistUnion->sampleRelid,
NIL); /* TODO is this ok? */
return list_make1(newPath);
}
return NIL; return NIL;
} }

View File

@ -139,7 +139,7 @@
} }
#define MatchGrouping(capture, matcher) \ #define MatchGrouping(capture, matcher) \
{ \ { \
if (!IsA(pathToMatch, AggPath)) \ if (!IsA(pathToMatch, AggPath)) \
{ \ { \
MatchFailed; \ MatchFailed; \
@ -163,6 +163,7 @@
\ \
PushStack(pathToMatch); \ PushStack(pathToMatch); \
pathToMatch = ((DistributedUnionPath *) pathToMatch)->worker_path; \ pathToMatch = ((DistributedUnionPath *) pathToMatch)->worker_path; \
matcher; \
PopStack(pathToMatch); \ PopStack(pathToMatch); \
DoCapture(capture, DistributedUnionPath *, pathToMatch); \ DoCapture(capture, DistributedUnionPath *, pathToMatch); \
} }