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

pgsql: Fix plpgsql's handling of "simple" expression evaluation.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix plpgsql's handling of "simple" expression evaluation.
Date: 2010-10-28 17:03:55
Message-ID: E1PBVtL-0007vL-68@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
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.

Branch
------
REL8_2_STABLE

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=2487e8d8c8ca0014d9c02de16d0bdce62da64ad7

Modified Files
--------------
src/pl/plpgsql/src/pl_exec.c          |   20 +++++++++++++-
src/pl/plpgsql/src/plpgsql.h          |    7 +++--
src/test/regress/expected/plpgsql.out |   47 +++++++++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql      |   42 +++++++++++++++++++++++++++++
4 files changed, 112 insertions(+), 4 deletions(-)

pgsql-committers by date

Next:From: Tom LaneDate: 2010-10-28 17:29:32
Subject: pgsql: Save a few cycles in plpgsql simple-expression initialization.
Previous:From: Tom LaneDate: 2010-10-28 17:03:54
Subject: pgsql: Fix plpgsql's handling of "simple" expression evaluation.

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