pgsql: Remove tuplesort_set_allowbounded() and adjust tuplesort_reset()

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Remove tuplesort_set_allowbounded() and adjust tuplesort_reset()
Date: 2026-11-18 01:28:22
Message-ID: E1xTUTF-00000000ATD-0sci@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Remove tuplesort_set_allowbounded() and adjust tuplesort_reset()

tuplesort_set_allowbounded() was added to resolve an issue where a
Tuplesortstate was created without TUPLESORT_ALLOWBOUNDED, but a later
scan of Incremental Sort requires that flag because that scan is bounded.
The new function was added in the backbranches as it's not possible to
modify the signature of tuplesort_reset() there. Since we're free to
adjust that in master, this commit gets rid of
tuplesort_set_allowbounded(), which had to be called before
tuplesort_reset(), and instead adds a new boolean parameter to
tuplesort_reset() to allow the flag to be adjusted. This is a much
cleaner API.

The fundamental difference between TUPLESORT_ALLOWBOUNDED and not having
that flag is that the tuplecontext uses an AllocSet context for bounded
sorts as the sort only needs to keep the top N tuples and pfrees any
tuples that sort below those. When no bound is required, tuplecontext
uses a Bump context, which does not support pfree(), but uses less memory
to store the same tuples.

Author: David Rowley <dgrowleyml(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAApHDvpoJenKm2O2aUpLYnYV-o9cg+Zhpur3jimr+q0cA7NS6w@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/executor/nodeIncrementalSort.c | 18 ++++++-----------
src/backend/utils/sort/tuplesort.c | 32 +++++++++++++-----------------
src/include/utils/tuplesort.h | 4 +---
3 files changed, 21 insertions(+), 33 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-11-18 02:55:50 pgsql: Don't crash on null pstate in coerce_record_to_complex().
Previous Message David Rowley 2026-11-18 01:15:31 pgsql: Fix possible crash with Incremental Sort when boundedness change