pgsql: Avoid recursion while processing ELSIF lists in plpgsql. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid recursion while processing ELSIF lists in plpgsql.
Date
Msg-id E1RJVWf-00062T-PD@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid recursion while processing ELSIF lists in plpgsql.

The original implementation of ELSIF in plpgsql converted the construct
into nested simple IF statements.  This was prone to stack overflow with
long ELSIF lists, in two different ways.  First, it's difficult to generate
the parsetree without using right-recursion in the bison grammar, and
that's prone to parser stack overflow since nothing can be reduced until
the whole list has been read.  Second, we'd recurse during execution, thus
creating an unnecessary risk of execution-time stack overflow.  Rewrite
so that the ELSIF list is represented as a flat list, scanned via iteration
not recursion, and generated through left-recursion in the grammar.
Per a gripe from Håvard Kongsgård.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/051d1ba7a02d0e8930adf228d60e8a044b9fcadb

Modified Files
--------------
src/pl/plpgsql/src/gram.y     |   52 +++++++++++++++-------------------------
src/pl/plpgsql/src/pl_exec.c  |   20 ++++++++-------
src/pl/plpgsql/src/pl_funcs.c |   32 +++++++++++++++++++-----
src/pl/plpgsql/src/plpgsql.h  |   14 ++++++++--
4 files changed, 67 insertions(+), 51 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Add simple script to check for right recursion in Bison grammars
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Fix the number of lwlocks needed by the "fast path" lock patch.