• Tom Lane's avatar
    Fix plpgsql's handling of "simple" expression evaluation. · 8ce22dd4
    Tom Lane authored
    In general, expression execution state trees aren't re-entrantly usable,
    since functions can store private state information in them.
    For efficiency reasons, plpgsql tries to cache and reuse state trees for
    "simple" expressions.  It can get away with that most of the time, but it
    can fail if the state tree is dirty from a previous failed execution (as
    in an example from Alvaro) or is being used recursively (as noted by me).
    
    Fix by tracking whether a state tree is in use, and falling back to the
    "non-simple" code path if so.  This results in a pretty considerable speed
    hit when the non-simple path is taken, but the available alternatives seem
    even more unpleasant because they add overhead in the simple path.  Per
    idea from Heikki.
    
    Back-patch to all supported branches.
    8ce22dd4
pl_exec.c 145 KB