pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix plpgsql to reinitialize record variables at block re-entry.
Date: Sat, 09 Dec 2017 17:03:17 +0000
Message-ID: <E1eNiWz-0002M7-M8@gemulon.postgresql.org> (raw)

Fix plpgsql to reinitialize record variables at block re-entry.

If one exits and re-enters a DECLARE ... BEGIN ... END block within a
single execution of a plpgsql function, perhaps due to a surrounding loop,
the declared variables are supposed to get re-initialized to null (or
whatever their initializer is).  But this failed to happen for variables
of type "record", because while exec_stmt_block() expected such variables
to be included in the block's initvarnos list, plpgsql_add_initdatums()
only adds DTYPE_VAR variables to that list.  This bug appears to have
been there since the aboriginal addition of plpgsql to our tree.

Fix by teaching plpgsql_add_initdatums() to include DTYPE_REC variables
as well.  (We don't need to consider other DTYPEs because they don't
represent separately-stored values.)  I failed to resist the temptation
to make some nearby cosmetic adjustments, too.

No back-patch, because there have not been field complaints, and it
seems possible that somewhere out there someone has code depending
on the incorrect behavior.  In any case this change would have no
impact on correctly-written code.

Discussion: https://postgr.es/m/22994.1512800671@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/390d58135b22bc25229b524a60f69682182201d8

Modified Files
--------------
src/pl/plpgsql/src/pl_comp.c          | 12 +++++++++---
src/pl/plpgsql/src/pl_exec.c          | 20 +++++++++-----------
src/pl/plpgsql/src/plpgsql.h          |  4 ++--
src/test/regress/expected/plpgsql.out | 27 +++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql      | 21 +++++++++++++++++++++
5 files changed, 68 insertions(+), 16 deletions(-)



Message-ID: <E1eNiWz-0002M7-M8@gemulon.postgresql.org>
Permalink:  ../E1eNiWz-0002M7-M8@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1eNiWz-0002M7-M8@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix plpgsql to reinitialize record variables at block re-entry.
  In-Reply-To: <E1eNiWz-0002M7-M8@gemulon.postgresql.org>
  References: <E1eNiWz-0002M7-M8@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox