On Sun, 15 Nov 2026 at 17:15, shihao zhong <[email protected]> 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: v2-0001-Fix-issue-with-Incremental-Sort-when-boundedness-.patch
Description: Binary data

Reply via email to