Re: BUG #15592: Memory overuse with subquery containing unnest() and set operations (11.x regression)

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-bugs@lists.postgresql.org, amdmi3@amdmi3.ru
Date: 2019-01-14T16:57:55Z
Lists: pgsql-bugs
I wrote:
> Andres Freund <andres@anarazel.de> writes:
>> Think I know where the problem is - let me have a coffee and check? I think I might have a good lying around...

> I had just determined that the extra context was added by bf6c614a2,

The short answer here is that this addition to BuildTupleHashTable:

	hashtable->exprcontext = CreateExprContext(parent->state);

allocates memory that is not freed by freeing the hashtable's tablecxt,
breaking the API for grouping hashtables.

Why does a hashtable need its own exprcontext now when it didn't before?

			regards, tom lane


Commits

  1. Plug leak in BuildTupleHashTable by creating ExprContext in correct context.

  2. simplehash: Add support for resetting a hashtable's contents.