Re: [PATCH] Fix memory leak in memoize for numeric key
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Orlov Aleksej <al.orlov@cft.ru>
Cc: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2023-10-03T08:51:31Z
Lists: pgsql-hackers
Attachments
- fix_memoize_memory_leak_v2.patch (application/octet-stream) patch v2
On Tue, 3 Oct 2023 at 19:38, Orlov Aleksej <al.orlov@cft.ru> wrote: > I found a query which consumes a lot of memory and triggers OOM killer. > Memory leak occurs in memoize node for numeric key. Thanks for the analysis and the patch. > I've attached memoize_memory_leak_numeric_key.patch to address this. Yeah, this is a bug for sure. Looking at ExecHashGetHashValue() for example purposes, I see it's quite careful to call ResetExprContext(econtext) at the top of the function to reset the tuple context. I think the patch might need to go a bit further and also adjust MemoizeHash_equal(). In non-binary mode, we just call ExecQualAndReset() which evaluates the join condition and resets the context. The binary mode code does not do this, so I think we should expand on what you've done and adjust that code too. I've done that in the attached patch. David
Commits
-
Fix memory leak in Memoize code
- e4b95b9b02b2 14.10 landed
- 689af6db6c76 15.5 landed
- 31b2b2d72d9c 16.1 landed
- 0b053e78b599 17.0 landed