postgresql/src/test
Tom Lane c7b849a896 Prevent leakage of cached plans and execution trees in plpgsql DO blocks.
plpgsql likes to cache query plans and simple-expression execution state
trees across calls.  This is a considerable win for multiple executions
of the same function.  However, it's useless for DO blocks, since by
definition those are executed only once and discarded.  Nonetheless,
we were allowing a DO block's expression execution trees to survive
until end of transaction, resulting in a significant intra-transaction
memory leak, as reported by Yeb Havinga.  Worse, if the DO block exited
with an error, the compiled form of the block's code was leaked till
end of session --- along with subsidiary plancache entries.

To fix, make DO blocks keep their expression execution trees in a private
EState that's deleted at exit from the block, and add a PG_TRY block
to plpgsql_inline_handler to make sure that memory cleanup happens
even on error exits.  Also add a regression test covering error handling
in a DO block, because my first try at this broke that.  (The test is
not meant to prove that we don't leak memory anymore, though it could
be used for that with a much larger loop count.)

Ideally we'd back-patch this into all versions supporting DO blocks;
but the patch needs to add a field to struct PLpgSQL_execstate, and that
would break ABI compatibility for third-party plugins such as the plpgsql
debugger.  Given the small number of complaints so far, fixing this in
HEAD only seems like an acceptable choice.
2013-11-15 13:52:03 -05:00
..
examples Update copyrights for 2013 2013-01-01 17:15:01 -05:00
isolation Fix buffer overrun in isolation test program. 2013-11-15 08:27:42 -06:00
locale Run newly-configured perltidy script on Perl files. 2012-07-04 21:47:49 -04:00
mb Lots of doc corrections. 2012-04-23 22:43:09 -04:00
performance Run newly-configured perltidy script on Perl files. 2012-07-04 21:47:49 -04:00
regress Prevent leakage of cached plans and execution trees in plpgsql DO blocks. 2013-11-15 13:52:03 -05:00
thread Update copyrights for 2013 2013-01-01 17:15:01 -05:00
Makefile Add isolation test to check-world and installcheck-world 2012-03-05 20:19:20 +02:00