Avoid recursion when processing simple lists of AND'ed or OR'ed clauses.
Tom Lane <tgl@sss.pgh.pa.us>
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
Files
| Path | Change | +/− |
|---|---|---|
| contrib/postgres_fdw/deparse.c | modified | +0 −3 |
| src/backend/nodes/nodeFuncs.c | modified | +8 −0 |
| src/backend/nodes/outfuncs.c | modified | +0 −9 |
| src/backend/optimizer/prep/prepjointree.c | modified | +3 −3 |
| src/backend/optimizer/prep/prepqual.c | modified | +6 −7 |
| src/backend/optimizer/util/clauses.c | modified | +9 −6 |
| src/backend/parser/gram.y | modified | +75 −35 |
| src/backend/parser/parse_clause.c | modified | +10 −11 |
| src/backend/parser/parse_expr.c | modified | +41 −57 |
| src/include/nodes/parsenodes.h | modified | +0 −3 |
| src/include/nodes/primnodes.h | modified | +2 −6 |
| src/test/regress/expected/rules.out | modified | +1 −1 |