generic way of matching fields for Var/Const

moonshot/custom-path
Nils Dijk 2021-01-21 13:52:21 +01:00
parent 2b4072ebe8
commit 4362502bb5
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
2 changed files with 25 additions and 15 deletions

View File

@ -791,7 +791,7 @@ GeoOverlapJoin(PlannerInfo *root, Path *originalPath)
MatchVar(NoCapture), MatchVar(NoCapture),
MatchConst( MatchConst(
&match.stdwithinDistanceConst, &match.stdwithinDistanceConst,
MatchConstType(FLOAT8OID))))), MatchConstFields(consttype == FLOAT8OID))))),
/* match inner path in join */ /* match inner path in join */
SkipReadThrough( SkipReadThrough(
NoCapture, NoCapture,

View File

@ -14,8 +14,8 @@
#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2) #define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2)
#define CONCATENATE2(arg1, arg2) arg1##arg2 #define CONCATENATE2(arg1, arg2) arg1##arg2
#define FOR_EACH_0(what, index) (void); #define FOR_EACH_0(what, index, x) ;
#define FOR_EACH_1(what, index, x) what((index), x); #define FOR_EACH_1(what, index, x) what((index), x); FOR_EACH_0(what, index+1, __VA_ARGS__);
#define FOR_EACH_2(what, index, x, ...) what((index), x); FOR_EACH_1(what, index+1, __VA_ARGS__); #define FOR_EACH_2(what, index, x, ...) what((index), x); FOR_EACH_1(what, index+1, __VA_ARGS__);
#define FOR_EACH_3(what, index, x, ...) what((index), x); FOR_EACH_2(what, index+1, __VA_ARGS__); #define FOR_EACH_3(what, index, x, ...) what((index), x); FOR_EACH_2(what, index+1, __VA_ARGS__);
#define FOR_EACH_4(what, index, x, ...) what((index), x); FOR_EACH_3(what, index+1, __VA_ARGS__); #define FOR_EACH_4(what, index, x, ...) what((index), x); FOR_EACH_3(what, index+1, __VA_ARGS__);
@ -71,7 +71,6 @@
\ \
{ \ { \
bool skipped = true; \ bool skipped = true; \
int skipCount = 0; \
while (skipped) { \ while (skipped) { \
switch(pathToMatch->type) \ switch(pathToMatch->type) \
{ \ { \
@ -87,13 +86,8 @@
break; \ break; \
} \ } \
} \ } \
if (skipped) \
{ \
skipCount++; \
} \ } \
} \ } \
ereport(DEBUG1, (errmsg("skipped %d read through nodes", skipCount))); \
} \
\ \
matcher; \ matcher; \
PopStack(pathToMatch); \ PopStack(pathToMatch); \
@ -102,7 +96,6 @@
#define MatchJoin(capture, joinType, conditionMatcher, innerMatcher, outerMatcher) \ #define MatchJoin(capture, joinType, conditionMatcher, innerMatcher, outerMatcher) \
{ \ { \
ereport(DEBUG1, (errmsg("initiate join matcher"))); \
{ \ { \
bool m = false; \ bool m = false; \
switch (pathToMatch->type) \ switch (pathToMatch->type) \
@ -196,11 +189,9 @@ do \
MakeStack(Path, pathToMatch, path); \ MakeStack(Path, pathToMatch, path); \
InitializeCapture; \ InitializeCapture; \
\ \
ereport(DEBUG1, (errmsg("initiate matcher DSL"))); \
matcher; \ matcher; \
\ \
VerifyStack(pathToMatch); \ VerifyStack(pathToMatch); \
ereport(DEBUG1, (errmsg("pattern matched"))); \
matched = true; \ matched = true; \
break; \ break; \
} \ } \
@ -310,6 +301,19 @@ if (matched)
} }
#define MatchVarValuesInternal(index, check) \
{ \
if (!(castNode(Var, clause)->check)) \
{ \
MatchFailed; \
} \
}
#define MatchVarFields(...) \
FOR_EACH(MatchVarValuesInternal, __VA_ARGS__);
#define MatchVar(capture, ...) \ #define MatchVar(capture, ...) \
{ \ { \
if (!IsA(clause, Var)) \ if (!IsA(clause, Var)) \
@ -321,13 +325,19 @@ if (matched)
} }
#define MatchConstType(constType) \ #define MatchConstValuesInternal(index, check) \
if (!(castNode(Const, clause)->consttype == constType)) \ { \
if (!(castNode(Const, clause)->check)) \
{ \ { \
MatchFailed; \ MatchFailed; \
} \
} }
#define MatchConstFields(...) \
FOR_EACH(MatchConstValuesInternal, __VA_ARGS__);
#define MatchConst(capture, ...) \ #define MatchConst(capture, ...) \
{ \ { \
if (!IsA(clause, Const)) \ if (!IsA(clause, Const)) \