Subject: Re: Memory leak in incremental sort re-scan

From: Tom Lane <[email-masked]>
Date: Thu, 15 Jun 2023 16:36:33 -0400

Tomas Vondra <[email-masked]> writes:
> On 6/15/23 22:11, Tom Lane wrote:
>> I see zero leakage in that example after applying the attached quick
>> hack.  (It might be better to make the check in the caller, or to just
>> move the call to ExecInitIncrementalSort.)

> Thanks for looking. Are you planning to work on this and push the fix,
> or do you want me to finish this up?

I'm happy to let you take it -- got lots of other stuff on my plate.

			regards, tom lane

---

From: Tomas Vondra <[email-masked]>
Date: Fri, 16 Jun 2023 00:34:54 +0200

> I'm happy to let you take it -- got lots of other stuff on my plate.

OK, will do.

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

---

From: James Coleman <[email-masked]>
Date: Wed, 21 Jun 2023 14:54:13 -0400

> > I'm happy to let you take it -- got lots of other stuff on my plate.

I think the attached is enough to fix it -- rather than nulling out
the sort states in rescan, we can reset them (as the comment says),
but not set them to null (we also have the same mistake with
presorted_keys). That avoids unnecessary recreation of the sort
states, but it also fixes the problem Tom noted as well: the call to
preparePresortedCols() is already guarded by a test on fullsort_state
being NULL, so with this change we also won't unnecessarily redo that
work.

Regards,
James Coleman

---

From: Laurenz Albe <[email-masked]>
Date: Thu, 29 Jun 2023 13:49:54 +0200

> > I'm happy to let you take it -- got lots of other stuff on my plate.

It would be cool if we could get that into the next minor release in August.

Yours,
Laurenz Albe

---

From: Tomas Vondra <[email-masked]>
Date: Sun, 2 Jul 2023 20:13:41 +0200

> It would be cool if we could get that into the next minor release in August.

FWIW I've pushed the fix prepared by James a couple days ago. Thanks for
the report!

regards

---

From: Laurenz Albe <[email-masked]>
Date: Sun, 02 Jul 2023 21:52:40 +0200

> FWIW I've pushed the fix prepared by James a couple days ago. Thanks for

Thanks, and sorry for being pushy.

Yours,
Laurenz Albe