pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix tuplesort memory accounting for datum sorts on byref types
Date: Mon, 05 Oct 2026 12:21:46 +0000
Message-ID: <E1xDhhS-00000000PiJ-19rj@gemulon.postgresql.org> (raw)

Fix tuplesort memory accounting for datum sorts on byref types

6ed83d5fa made it so tuplesorts could use a bump.c memory allocator for
non-bounded sorts in order to save memory and increase performance.
That commit didn't get the memory accounting correct for datum sorts and
mistakenly passed 0 bytes to tuplesort_puttuple_common().  That was
correct for byval types, but failed to take into account palloc'd memory
for byref types.

Fix by using datumGetSize() when using the bump allocator and by using
GetMemoryChunkSpace() when not.

Backpatch to v17, where 6ed83d5fa was added.

Author: Mario Karuza <mkaruza.pg@icloud.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Joao Detomini <joao.detomini@enterprisedb.com>
Discussion: https://postgr.es/m/e9f9f54337cd86a982837763958518cdbf08863c.camel%40icloud.com
Backpatch-through: 17

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a2148471b0db8fb44c43d5a2933d99c82f3aa0c8

Modified Files
--------------
src/backend/utils/sort/tuplesortvariants.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)



view thread (4+ messages)  latest in thread

Message-ID: <E1xDhhS-00000000PiJ-19rj@gemulon.postgresql.org>
Permalink:  ../E1xDhhS-00000000PiJ-19rj@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xDhhS-00000000PiJ-19rj@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: drowley@postgresql.org
  Subject: Re: pgsql: Fix tuplesort memory accounting for datum sorts on byref types
  In-Reply-To: <E1xDhhS-00000000PiJ-19rj@gemulon.postgresql.org>
  References: <E1xDhhS-00000000PiJ-19rj@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