From 2146f13408cdb85c738364fe8f7965209e08c6be Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 16 Jun 2014 15:55:05 -0400 Subject: 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 --- src/backend/nodes/nodeFuncs.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/backend/nodes/nodeFuncs.c') diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 5a98bfbc11e..f4999c5be03 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -3047,6 +3047,14 @@ raw_expression_tree_walker(Node *node, /* operator name is deemed uninteresting */ } break; + case T_BoolExpr: + { + BoolExpr *expr = (BoolExpr *) node; + + if (walker(expr->args, context)) + return true; + } + break; case T_ColumnRef: /* we assume the fields contain nothing interesting */ break; -- cgit v1.2.3