rework the capture logic

moonshot/custom-path
Nils Dijk 2021-01-21 13:27:37 +01:00
parent 766ed2ad33
commit 2b4072ebe8
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
2 changed files with 53 additions and 49 deletions

View File

@ -776,34 +776,39 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
IfPathMatch(
originalPath,
MatchJoin(
NoCapture,
JOIN_INNER,
/* match on join restriction info */
MatchJoinRestrictions(
NoCapture,
MatchExprNamedOperation(
NoCapture,
geometry_overlaps,
MatchVar(),
MatchVar(NoCapture),
MatchExprNamedFunction(
NoCapture,
st_expand,
MatchVar(),
CaptureMatch(
MatchVar(NoCapture),
MatchConst(
&match.stdwithinDistanceConst,
MatchConst(MatchConstType(FLOAT8OID)))))),
MatchConstType(FLOAT8OID))))),
/* match inner path in join */
SkipReadthrough(CaptureMatch(
SkipReadThrough(
NoCapture,
MatchGrouping(
&match.innerGrouping,
MatchGrouping(CaptureMatch(
MatchDistributedUnion(
&match.innerDistUnion,
MatchDistributedUnion(CaptureMatch(
&match.innerPath,
MatchGeoScan)))))),
MatchGeoScan(
&match.innerPath)))),
/* match outer path in join */
SkipReadthrough(CaptureMatch(
SkipReadThrough(
NoCapture,
MatchGrouping(
&match.outerGrouping,
MatchGrouping(CaptureMatch(
&match.outerDistUnion,
MatchDistributedUnion(CaptureMatch(
&match.outerPath,
MatchGeoScan))))))))
MatchDistributedUnion(&match.outerDistUnion,
MatchGeoScan(
&match.outerPath))))))
{
/* have a match on the geo join pattern, all fields are stored in `match` */
ereport(DEBUG1, (errmsg("my custom code %p: %f",

View File

@ -35,13 +35,6 @@
#define MatchAny { }
#define MatchFailed { break; }
#define CaptureMatch(capture, matcher) \
matcher; \
if (capture) \
{ \
*(capture) = (typeof(*(capture))) lastMatch; \
}
#define MakeStack(type, stackName, value) \
type *stackName = (type *) value; \
@ -62,8 +55,17 @@ if (capture) \
#define VerifyStack(stackName) \
Assert(list_length(stackName##Stack) == 0)
#define InitializeCapture \
void *ignoreCaptureValue = NULL; \
(void) ignoreCaptureValue \
#define SkipReadthrough(matcher) \
#define NoCapture \
&ignoreCaptureValue
#define DoCapture(capture, type, toCapture) \
*(capture) = (type) toCapture
#define SkipReadThrough(capture, matcher) \
{ \
PushStack(pathToMatch); \
\
@ -95,10 +97,10 @@ if (capture) \
\
matcher; \
PopStack(pathToMatch); \
lastMatch = pathToMatch; \
DoCapture(capture, Path *, pathToMatch); \
}
#define MatchJoin(joinType, conditionMatcher, innerMatcher, outerMatcher) \
#define MatchJoin(capture, joinType, conditionMatcher, innerMatcher, outerMatcher) \
{ \
ereport(DEBUG1, (errmsg("initiate join matcher"))); \
{ \
@ -140,10 +142,10 @@ if (capture) \
\
PopStack(pathToMatch); \
conditionMatcher; \
lastMatch = pathToMatch; \
DoCapture(capture, JoinPath *, pathToMatch); \
}
#define MatchGrouping(matcher) \
#define MatchGrouping(capture, matcher) \
{ \
if (!IsA(pathToMatch, AggPath)) \
{ \
@ -156,10 +158,10 @@ if (capture) \
matcher;\
\
PopStack(pathToMatch); \
lastMatch = pathToMatch; \
DoCapture(capture, AggPath *, pathToMatch); \
}
#define MatchDistributedUnion(matcher) \
#define MatchDistributedUnion(capture, matcher) \
{ \
if (!IsDistributedUnion(pathToMatch, false, NULL)) \
{ \
@ -169,10 +171,10 @@ if (capture) \
PushStack(pathToMatch); \
pathToMatch = ((DistributedUnionPath *) pathToMatch)->worker_path; \
PopStack(pathToMatch); \
lastMatch = pathToMatch; \
DoCapture(capture, DistributedUnionPath *, pathToMatch); \
}
#define MatchGeoScan \
#define MatchGeoScan(capture) \
{ \
if (!IsA(pathToMatch, CustomPath)) \
{ \
@ -184,7 +186,7 @@ if (capture) \
MatchFailed; \
} \
\
lastMatch = pathToMatch; \
DoCapture(capture, GeoScanPath *, pathToMatch); \
}
#define IfPathMatch(path, matcher) \
@ -192,8 +194,7 @@ bool matched = false; \
do \
{ \
MakeStack(Path, pathToMatch, path); \
void *lastMatch = NULL; \
(void) lastMatch; \
InitializeCapture; \
\
ereport(DEBUG1, (errmsg("initiate matcher DSL"))); \
matcher; \
@ -207,7 +208,7 @@ while (false); \
if (matched)
#define MatchJoinRestrictions(matcher) \
#define MatchJoinRestrictions(capture, matcher) \
{ \
Assert(IsA(pathToMatch, NestPath) \
|| IsA(pathToMatch, MergePath) \
@ -224,7 +225,7 @@ if (matched)
\
restrictionMatched = true; \
VerifyStack(clause); \
lastMatch = restrictInfo; \
DoCapture(capture, RestrictInfo *, restrictInfo); \
} while(false); \
if (restrictionMatched) \
{ \
@ -243,11 +244,10 @@ if (matched)
{ \
clause = (Expr *) list_nth(((FuncExpr *) PeekStack(clause))->args, index); \
matcher; \
lastMatch = clause; \
}
#define MatchExprNamedFunction(name, ...) \
#define MatchExprNamedFunction(capture, name, ...) \
{ \
if (!IsA(clause, FuncExpr)) \
{ \
@ -271,7 +271,7 @@ if (matched)
PushStack(clause); \
FOR_EACH(InternalFunctionDispatch, __VA_ARGS__); \
PopStack(clause); \
lastMatch = clause; \
DoCapture(capture, FuncExpr *, clause); \
}
@ -279,11 +279,10 @@ if (matched)
{ \
clause = (Expr *) list_nth(((OpExpr *) PeekStack(clause))->args, index); \
matcher; \
lastMatch = clause; \
}
#define MatchExprNamedOperation(name, ...) \
#define MatchExprNamedOperation(capture, name, ...) \
{ \
if (!IsA(clause, OpExpr)) \
{ \
@ -307,18 +306,18 @@ if (matched)
PushStack(clause); \
FOR_EACH(InternalOperationDispatch, __VA_ARGS__); \
PopStack(clause); \
lastMatch = clause; \
DoCapture(capture, OpExpr *, clause); \
}
#define MatchVar(...) \
#define MatchVar(capture, ...) \
{ \
if (!IsA(clause, Var)) \
{ \
MatchFailed; \
} \
__VA_ARGS__; \
lastMatch = clause; \
DoCapture(capture, Var *, clause); \
}
@ -329,14 +328,14 @@ if (!(castNode(Const, clause)->consttype == constType)) \
}
#define MatchConst(...) \
#define MatchConst(capture, ...) \
{ \
if (!IsA(clause, Const)) \
{ \
MatchFailed; \
} \
__VA_ARGS__; \
lastMatch = clause; \
DoCapture(capture, Const *, clause); \
}