]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix plpgsql's handling of "simple" expression evaluation.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 28 Oct 2010 17:01:23 +0000 (13:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 28 Oct 2010 17:01:23 +0000 (13:01 -0400)
commit2487e8d8c8ca0014d9c02de16d0bdce62da64ad7
treee9970a0300d74a2a50da6e3a9bfded4879ae5bf7
parent49b5aba40e0b0adb1caaea81c88dd0e54a7d3890
Fix plpgsql's handling of "simple" expression evaluation.

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.
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/plpgsql.h
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql