Re: Incremental Sort crash on a rescan that becomes bounded

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tomas Vondra <tomas(at)vondra(dot)me>, jtc331(at)gmail(dot)com
Subject: Re: Incremental Sort crash on a rescan that becomes bounded
Date: 2026-11-16 03:27:03
Message-ID: CAApHDvpoJenKm2O2aUpLYnYV-o9cg+Zhpur3jimr+q0cA7NS6w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 15 Nov 2026 at 17:15, shihao zhong <zhong950419(at)gmail(dot)com> wrote:
> The attached patch ends the sort state on such a rescan. The second
> patch is the version for 15.

Thanks for finding and reporting this.

Is the patch an AI fix? IMO, it's a pretty inefficient way to make it
work correctly. It seems wasteful to me to have to recreate the
tuplesort just because the boundedness requirements have changed. It
looks fine to me to adjust the sortopt flags before calling
tuplesort_reset(), as that calls tuplesort_free() and that does
"MemoryContextReset(state->base.sortcontext);". The tuplecontext
context is a sub-context of sortcontext, so gets destroyed then. When
tuplesort_reset() later calls tuplesort_begin_batch(), that will
create the Bump or AllocSet context for the tuples.

I don't see an issue adding a new external function in the
backbranches. Maybe in master we could adjust the tuplesort_reset()
function to take the allowbounded parameter.

Attachment Content-Type Size
v2-0001-Fix-issue-with-Incremental-Sort-when-boundedness-.patch application/octet-stream 7.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeevan Chalke 2026-11-16 03:34:11 Re: PL/pgSQL: apply the too_many_rows extra check to EXECUTE ... INTO
Previous Message Fujii Masao 2026-11-16 02:08:16 Re: PL/pgSQL: apply the too_many_rows extra check to EXECUTE ... INTO