mirror of https://github.com/citusdata/citus.git
rework the capture logic
parent
766ed2ad33
commit
2b4072ebe8
|
@ -776,34 +776,39 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
|
||||||
IfPathMatch(
|
IfPathMatch(
|
||||||
originalPath,
|
originalPath,
|
||||||
MatchJoin(
|
MatchJoin(
|
||||||
|
NoCapture,
|
||||||
JOIN_INNER,
|
JOIN_INNER,
|
||||||
/* match on join restriction info */
|
/* match on join restriction info */
|
||||||
MatchJoinRestrictions(
|
MatchJoinRestrictions(
|
||||||
|
NoCapture,
|
||||||
MatchExprNamedOperation(
|
MatchExprNamedOperation(
|
||||||
|
NoCapture,
|
||||||
geometry_overlaps,
|
geometry_overlaps,
|
||||||
MatchVar(),
|
MatchVar(NoCapture),
|
||||||
MatchExprNamedFunction(
|
MatchExprNamedFunction(
|
||||||
|
NoCapture,
|
||||||
st_expand,
|
st_expand,
|
||||||
MatchVar(),
|
MatchVar(NoCapture),
|
||||||
CaptureMatch(
|
MatchConst(
|
||||||
&match.stdwithinDistanceConst,
|
&match.stdwithinDistanceConst,
|
||||||
MatchConst(MatchConstType(FLOAT8OID)))))),
|
MatchConstType(FLOAT8OID))))),
|
||||||
/* match inner path in join */
|
/* match inner path in join */
|
||||||
SkipReadthrough(CaptureMatch(
|
SkipReadThrough(
|
||||||
|
NoCapture,
|
||||||
|
MatchGrouping(
|
||||||
&match.innerGrouping,
|
&match.innerGrouping,
|
||||||
MatchGrouping(CaptureMatch(
|
MatchDistributedUnion(
|
||||||
&match.innerDistUnion,
|
&match.innerDistUnion,
|
||||||
MatchDistributedUnion(CaptureMatch(
|
MatchGeoScan(
|
||||||
&match.innerPath,
|
&match.innerPath)))),
|
||||||
MatchGeoScan)))))),
|
|
||||||
/* match outer path in join */
|
/* match outer path in join */
|
||||||
SkipReadthrough(CaptureMatch(
|
SkipReadThrough(
|
||||||
|
NoCapture,
|
||||||
|
MatchGrouping(
|
||||||
&match.outerGrouping,
|
&match.outerGrouping,
|
||||||
MatchGrouping(CaptureMatch(
|
MatchDistributedUnion(&match.outerDistUnion,
|
||||||
&match.outerDistUnion,
|
MatchGeoScan(
|
||||||
MatchDistributedUnion(CaptureMatch(
|
&match.outerPath))))))
|
||||||
&match.outerPath,
|
|
||||||
MatchGeoScan))))))))
|
|
||||||
{
|
{
|
||||||
/* have a match on the geo join pattern, all fields are stored in `match` */
|
/* have a match on the geo join pattern, all fields are stored in `match` */
|
||||||
ereport(DEBUG1, (errmsg("my custom code %p: %f",
|
ereport(DEBUG1, (errmsg("my custom code %p: %f",
|
||||||
|
|
|
@ -35,13 +35,6 @@
|
||||||
#define MatchAny { }
|
#define MatchAny { }
|
||||||
#define MatchFailed { break; }
|
#define MatchFailed { break; }
|
||||||
|
|
||||||
#define CaptureMatch(capture, matcher) \
|
|
||||||
matcher; \
|
|
||||||
if (capture) \
|
|
||||||
{ \
|
|
||||||
*(capture) = (typeof(*(capture))) lastMatch; \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define MakeStack(type, stackName, value) \
|
#define MakeStack(type, stackName, value) \
|
||||||
type *stackName = (type *) value; \
|
type *stackName = (type *) value; \
|
||||||
|
@ -62,8 +55,17 @@ if (capture) \
|
||||||
#define VerifyStack(stackName) \
|
#define VerifyStack(stackName) \
|
||||||
Assert(list_length(stackName##Stack) == 0)
|
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); \
|
PushStack(pathToMatch); \
|
||||||
\
|
\
|
||||||
|
@ -95,10 +97,10 @@ if (capture) \
|
||||||
\
|
\
|
||||||
matcher; \
|
matcher; \
|
||||||
PopStack(pathToMatch); \
|
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"))); \
|
ereport(DEBUG1, (errmsg("initiate join matcher"))); \
|
||||||
{ \
|
{ \
|
||||||
|
@ -140,10 +142,10 @@ if (capture) \
|
||||||
\
|
\
|
||||||
PopStack(pathToMatch); \
|
PopStack(pathToMatch); \
|
||||||
conditionMatcher; \
|
conditionMatcher; \
|
||||||
lastMatch = pathToMatch; \
|
DoCapture(capture, JoinPath *, pathToMatch); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MatchGrouping(matcher) \
|
#define MatchGrouping(capture, matcher) \
|
||||||
{ \
|
{ \
|
||||||
if (!IsA(pathToMatch, AggPath)) \
|
if (!IsA(pathToMatch, AggPath)) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -156,10 +158,10 @@ if (capture) \
|
||||||
matcher;\
|
matcher;\
|
||||||
\
|
\
|
||||||
PopStack(pathToMatch); \
|
PopStack(pathToMatch); \
|
||||||
lastMatch = pathToMatch; \
|
DoCapture(capture, AggPath *, pathToMatch); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MatchDistributedUnion(matcher) \
|
#define MatchDistributedUnion(capture, matcher) \
|
||||||
{ \
|
{ \
|
||||||
if (!IsDistributedUnion(pathToMatch, false, NULL)) \
|
if (!IsDistributedUnion(pathToMatch, false, NULL)) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -169,10 +171,10 @@ if (capture) \
|
||||||
PushStack(pathToMatch); \
|
PushStack(pathToMatch); \
|
||||||
pathToMatch = ((DistributedUnionPath *) pathToMatch)->worker_path; \
|
pathToMatch = ((DistributedUnionPath *) pathToMatch)->worker_path; \
|
||||||
PopStack(pathToMatch); \
|
PopStack(pathToMatch); \
|
||||||
lastMatch = pathToMatch; \
|
DoCapture(capture, DistributedUnionPath *, pathToMatch); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MatchGeoScan \
|
#define MatchGeoScan(capture) \
|
||||||
{ \
|
{ \
|
||||||
if (!IsA(pathToMatch, CustomPath)) \
|
if (!IsA(pathToMatch, CustomPath)) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -184,7 +186,7 @@ if (capture) \
|
||||||
MatchFailed; \
|
MatchFailed; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
lastMatch = pathToMatch; \
|
DoCapture(capture, GeoScanPath *, pathToMatch); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IfPathMatch(path, matcher) \
|
#define IfPathMatch(path, matcher) \
|
||||||
|
@ -192,8 +194,7 @@ bool matched = false; \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
MakeStack(Path, pathToMatch, path); \
|
MakeStack(Path, pathToMatch, path); \
|
||||||
void *lastMatch = NULL; \
|
InitializeCapture; \
|
||||||
(void) lastMatch; \
|
|
||||||
\
|
\
|
||||||
ereport(DEBUG1, (errmsg("initiate matcher DSL"))); \
|
ereport(DEBUG1, (errmsg("initiate matcher DSL"))); \
|
||||||
matcher; \
|
matcher; \
|
||||||
|
@ -207,7 +208,7 @@ while (false); \
|
||||||
if (matched)
|
if (matched)
|
||||||
|
|
||||||
|
|
||||||
#define MatchJoinRestrictions(matcher) \
|
#define MatchJoinRestrictions(capture, matcher) \
|
||||||
{ \
|
{ \
|
||||||
Assert(IsA(pathToMatch, NestPath) \
|
Assert(IsA(pathToMatch, NestPath) \
|
||||||
|| IsA(pathToMatch, MergePath) \
|
|| IsA(pathToMatch, MergePath) \
|
||||||
|
@ -224,7 +225,7 @@ if (matched)
|
||||||
\
|
\
|
||||||
restrictionMatched = true; \
|
restrictionMatched = true; \
|
||||||
VerifyStack(clause); \
|
VerifyStack(clause); \
|
||||||
lastMatch = restrictInfo; \
|
DoCapture(capture, RestrictInfo *, restrictInfo); \
|
||||||
} while(false); \
|
} while(false); \
|
||||||
if (restrictionMatched) \
|
if (restrictionMatched) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -243,11 +244,10 @@ if (matched)
|
||||||
{ \
|
{ \
|
||||||
clause = (Expr *) list_nth(((FuncExpr *) PeekStack(clause))->args, index); \
|
clause = (Expr *) list_nth(((FuncExpr *) PeekStack(clause))->args, index); \
|
||||||
matcher; \
|
matcher; \
|
||||||
lastMatch = clause; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MatchExprNamedFunction(name, ...) \
|
#define MatchExprNamedFunction(capture, name, ...) \
|
||||||
{ \
|
{ \
|
||||||
if (!IsA(clause, FuncExpr)) \
|
if (!IsA(clause, FuncExpr)) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -271,7 +271,7 @@ if (matched)
|
||||||
PushStack(clause); \
|
PushStack(clause); \
|
||||||
FOR_EACH(InternalFunctionDispatch, __VA_ARGS__); \
|
FOR_EACH(InternalFunctionDispatch, __VA_ARGS__); \
|
||||||
PopStack(clause); \
|
PopStack(clause); \
|
||||||
lastMatch = clause; \
|
DoCapture(capture, FuncExpr *, clause); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,11 +279,10 @@ if (matched)
|
||||||
{ \
|
{ \
|
||||||
clause = (Expr *) list_nth(((OpExpr *) PeekStack(clause))->args, index); \
|
clause = (Expr *) list_nth(((OpExpr *) PeekStack(clause))->args, index); \
|
||||||
matcher; \
|
matcher; \
|
||||||
lastMatch = clause; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MatchExprNamedOperation(name, ...) \
|
#define MatchExprNamedOperation(capture, name, ...) \
|
||||||
{ \
|
{ \
|
||||||
if (!IsA(clause, OpExpr)) \
|
if (!IsA(clause, OpExpr)) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -307,18 +306,18 @@ if (matched)
|
||||||
PushStack(clause); \
|
PushStack(clause); \
|
||||||
FOR_EACH(InternalOperationDispatch, __VA_ARGS__); \
|
FOR_EACH(InternalOperationDispatch, __VA_ARGS__); \
|
||||||
PopStack(clause); \
|
PopStack(clause); \
|
||||||
lastMatch = clause; \
|
DoCapture(capture, OpExpr *, clause); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MatchVar(...) \
|
#define MatchVar(capture, ...) \
|
||||||
{ \
|
{ \
|
||||||
if (!IsA(clause, Var)) \
|
if (!IsA(clause, Var)) \
|
||||||
{ \
|
{ \
|
||||||
MatchFailed; \
|
MatchFailed; \
|
||||||
} \
|
} \
|
||||||
__VA_ARGS__; \
|
__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)) \
|
if (!IsA(clause, Const)) \
|
||||||
{ \
|
{ \
|
||||||
MatchFailed; \
|
MatchFailed; \
|
||||||
} \
|
} \
|
||||||
__VA_ARGS__; \
|
__VA_ARGS__; \
|
||||||
lastMatch = clause; \
|
DoCapture(capture, Const *, clause); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue