Re: Memory leak in incremental sort re-scan
James Coleman <jtc331@gmail.com>
From: James Coleman <jtc331@gmail.com>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Laurenz Albe <laurenz.albe@cybertec.at>, pgsql-hackers@lists.postgresql.org
Date: 2023-06-21T18:54:13Z
Lists: pgsql-hackers
Attachments
- v2-0001-Fix-memory-leak-in-incremental-sort-rescan.patch (application/octet-stream) patch v2-0001
On Thu, Jun 15, 2023 at 6:35 PM Tomas Vondra <tomas.vondra@enterprisedb.com> wrote: > > > > On 6/15/23 22:36, Tom Lane wrote: > > Tomas Vondra <tomas.vondra@enterprisedb.com> 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. > > > > OK, will do. 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
Commits
-
Fix memory leak in Incremental Sort rescans
- 3ce761d5cafe 13.12 landed
- c1affa38c73b 14.9 landed
- 0c5fe4ff6b2b 15.4 landed
- 9ae7b5d1f3ad 16.0 landed
- 98640f960eb9 17.0 landed