pgsql: Avoid recursion when processing simple lists of AND'ed or OR'ed - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid recursion when processing simple lists of AND'ed or OR'ed
Date
Msg-id E1Wwd0W-00074H-UW@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/2146f13408cdb85c738364fe8f7965209e08c6be

Modified Files
--------------
contrib/postgres_fdw/deparse.c            |    3 -
src/backend/nodes/nodeFuncs.c             |    8 +++
src/backend/nodes/outfuncs.c              |    9 ---
src/backend/optimizer/prep/prepjointree.c |    6 +-
src/backend/optimizer/prep/prepqual.c     |   13 ++--
src/backend/optimizer/util/clauses.c      |   15 ++--
src/backend/parser/gram.y                 |  110 ++++++++++++++++++++---------
src/backend/parser/parse_clause.c         |   21 +++---
src/backend/parser/parse_expr.c           |   98 +++++++++++--------------
src/include/nodes/parsenodes.h            |    3 -
src/include/nodes/primnodes.h             |    8 +--
src/test/regress/expected/rules.out       |    2 +-
12 files changed, 155 insertions(+), 141 deletions(-)


pgsql-committers by date:

Previous
From: Bruce Momjian
Date:
Subject: pgsql: Use type pgsocket for Windows pipe emulation socket calls
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Revert accidental change of WAL_DEBUG default.