• Tom Lane's avatar
    Avoid recursion while processing ELSIF lists in plpgsql. · 051d1ba7
    Tom Lane authored
    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.
    051d1ba7
pl_funcs.c 32.2 KB