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@lists.postgresql.org
Subject: pgsql: Fix intra-query memory leak when a SRF returns zero rows.
Date: Sat, 28 Oct 2023 18:05:16 +0000
Message-ID: <E1qwngS-002nnM-5z@gemulon.postgresql.org> (raw)

Fix intra-query memory leak when a SRF returns zero rows.

When looping around after finding that the set-returning function
returned zero rows for the current input tuple, ExecProjectSet
neglected to reset either of the two memory contexts it's
responsible for cleaning out.  Typically this wouldn't cause much
problem, because once the SRF does return at least one row, the
contexts would get reset on the next call.  However, if the SRF
returns no rows for many input tuples in succession, quite a lot
of memory could be transiently consumed.

To fix, make sure we reset both contexts while looping around.

Per bug #18172 from Sergei Kornilov.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18172-9b8c5fc1d676ded3@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5d7515d7d1168a66a34aed7b9f2c9f4e2660e863

Modified Files
--------------
src/backend/executor/nodeProjectSet.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1qwngS-002nnM-5z@gemulon.postgresql.org>
Permalink:  ../E1qwngS-002nnM-5z@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1qwngS-002nnM-5z@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix intra-query memory leak when a SRF returns zero rows.
  In-Reply-To: <E1qwngS-002nnM-5z@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