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: Use Generation memory contexts to store tuples in sorts
Date: Mon, 04 Apr 2022 10:53:35 +0000
Message-ID: <E1nbKL0-000GnS-OR@gemulon.postgresql.org> (raw)

Use Generation memory contexts to store tuples in sorts

The general usage pattern when we store tuples in tuplesort.c is that
we store a series of tuples one by one then either perform a sort or spill
them to disk.  In the common case, there is no pfreeing of already stored
tuples.  For the common case since we do not individually pfree tuples, we
have very little need for aset.c memory allocation behavior which
maintains freelists and always rounds allocation sizes up to the next
power of 2 size.

Here we conditionally use generation.c contexts for storing tuples in
tuplesort.c when the sort will never be bounded.  Unfortunately, the
memory context to store tuples is already created by the time any calls
would be made to tuplesort_set_bound(), so here we add a new sort option
that allows callers to specify if they're going to need a bounded sort or
not.  We'll use a standard aset.c allocator when this sort option is not
set.

Extension authors must ensure that the TUPLESORT_ALLOWBOUNDED flag is
used when calling tuplesort_begin_* for any sorts that make a call to
tuplesort_set_bound().

Author: David Rowley
Reviewed-by: Andy Fan
Discussion: https://postgr.es/m/CAApHDvoH4ASzsAOyHcxkuY01Qf++8JJ0paw+03dk+W25tQEcNQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/40af10b571bdabbab06839d090083c9f9c2091d2

Modified Files
--------------
src/backend/executor/nodeIncrementalSort.c |  4 +++-
src/backend/executor/nodeSort.c            |  2 ++
src/backend/utils/sort/tuplesort.c         | 20 ++++++++++++++++----
src/include/utils/tuplesort.h              |  3 +++
4 files changed, 24 insertions(+), 5 deletions(-)



Message-ID: <E1nbKL0-000GnS-OR@gemulon.postgresql.org>
Permalink:  ../E1nbKL0-000GnS-OR@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nbKL0-000GnS-OR@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: Use Generation memory contexts to store tuples in sorts
  In-Reply-To: <E1nbKL0-000GnS-OR@gemulon.postgresql.org>
  References: <E1nbKL0-000GnS-OR@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