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: Remove uses of MemoryContextContains in nodeAgg.c and nodeWindow
Date: Thu, 06 Oct 2022 17:35:38 +0000
Message-ID: <E1ogUmX-001Bop-G4@gemulon.postgresql.org> (raw)

Remove uses of MemoryContextContains in nodeAgg.c and nodeWindowAgg.c.

MemoryContextContains is no longer reliable in the wake of c6e0fe1f2,
so we need to get rid of these uses.

It appears that there's no really good reason to force the result of
an aggregate's finalfn or serialfn to be allocated in the per-tuple
context.  The only other plausible case is that the result points to
or into the aggregate's transition value, and that's fine because it
will last as long as we need it to.  (This conclusion depends on the
assumption that finalfns are not allowed to scribble on the transition
value, but we've long required that.)  So we can just drop the
MemoryContextContains plus datumCopy business, although we do need
to take care to not return a read-write pointer when the transition
value is an expanded datum.

Likewise, we don't really need to force the result of a window
function to be in the output context.  In this case, the plausible
alternative is that it's pointing into the temporary tuple slot used
by WinGetFuncArgInPartition or WinGetFuncArgInFrame (since those
functions could return such a pointer, which might become the window
function's result).  That will hold still for long enough, unless
there is another window function using the same WindowObject.
I'm content to always perform a datumCopy when there's more than one
such function.

On net, these changes should provide small speed improvements as well
as removing problematic code.

Tom Lane and David Rowley

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/42b746d4c982257bf3f924176632b04dc288174b

Modified Files
--------------
src/backend/executor/nodeAgg.c       | 32 ++++++++++----------------------
src/backend/executor/nodeWindowAgg.c | 30 ++++++++++++++----------------
src/test/regress/expected/window.out | 17 +++++++++++++++++
src/test/regress/sql/window.sql      |  4 ++++
4 files changed, 45 insertions(+), 38 deletions(-)



Message-ID: <E1ogUmX-001Bop-G4@gemulon.postgresql.org>
Permalink:  ../E1ogUmX-001Bop-G4@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ogUmX-001Bop-G4@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: Remove uses of MemoryContextContains in nodeAgg.c and nodeWindow
  In-Reply-To: <E1ogUmX-001Bop-G4@gemulon.postgresql.org>
  References: <E1ogUmX-001Bop-G4@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