Skip site navigation (1) Skip section navigation (2)

pgsql: Avoid recursion while processing ELSIF lists in plpgsql.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid recursion while processing ELSIF lists in plpgsql.
Date: 2011-10-27 19:22:05
Message-ID: E1RJVWf-00062T-PD@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: 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

Next:From: Heikki LinnakangasDate: 2011-10-27 19:47:48
Subject: pgsql: Fix the number of lwlocks needed by the "fast path" lockpatch.
Previous:From: Tom LaneDate: 2011-10-27 17:51:19
Subject: pgsql: Add simple script to check for right recursion in Bisongrammars

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group