diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-06-16 15:55:05 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-06-16 15:55:30 -0400 |
commit | 2146f13408cdb85c738364fe8f7965209e08c6be (patch) | |
tree | 9c5989a33d072788a51411dd7ee1bedb14f2280d /src/include | |
parent | ac608fe758455804f26179ea7c556e7752e453e8 (diff) | |
download | postgresql-2146f13408cdb85c738364fe8f7965209e08c6be.tar.gz postgresql-2146f13408cdb85c738364fe8f7965209e08c6be.zip |
Avoid recursion when processing simple lists of AND'ed or OR'ed clauses.
Since most of the system thinks AND and OR are N-argument expressions
anyway, let's have the grammar generate a representation of that form when
dealing with input like "x AND y AND z AND ...", rather than generating
a deeply-nested binary tree that just has to be flattened later by the
planner. This avoids stack overflow in parse analysis when dealing with
queries having more than a few thousand such clauses; and in any case it
removes some rather unsightly inconsistencies, since some parts of parse
analysis were generating N-argument ANDs/ORs already.
It's still possible to get a stack overflow with weirdly parenthesized
input, such as "x AND (y AND (z AND ( ... )))", but such cases are not
mainstream usage. The maximum depth of parenthesization is already
limited by Bison's stack in such cases, anyway, so that the limit is
probably fairly platform-independent.
Patch originally by Gurjeet Singh, heavily revised by me
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/nodes/parsenodes.h | 3 | ||||
-rw-r--r-- | src/include/nodes/primnodes.h | 8 |
2 files changed, 2 insertions, 9 deletions
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 7e560a19a3b..9a68c87d0ae 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -225,9 +225,6 @@ typedef struct ParamRef typedef enum A_Expr_Kind { AEXPR_OP, /* normal operator */ - AEXPR_AND, /* booleans - name field is unused */ - AEXPR_OR, - AEXPR_NOT, AEXPR_OP_ANY, /* scalar op ANY (array) */ AEXPR_OP_ALL, /* scalar op ALL (array) */ AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */ diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 4f03ef9232a..db8e87f0d08 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -458,12 +458,8 @@ typedef struct ScalarArrayOpExpr * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT * * Notice the arguments are given as a List. For NOT, of course the list - * must always have exactly one element. For AND and OR, the executor can - * handle any number of arguments. The parser generally treats AND and OR - * as binary and so it typically only produces two-element lists, but the - * optimizer will flatten trees of AND and OR nodes to produce longer lists - * when possible. There are also a few special cases where more arguments - * can appear before optimization. + * must always have exactly one element. For AND and OR, there can be two + * or more arguments. */ typedef enum BoolExprType { |