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

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, amdmi3(at)amdmi3(dot)ru
Subject: Re: BUG #15592: Memory overuse with subquery containing unnest() and set operations (11.x regression)
Date: 2019-01-14 18:04:23
Message-ID: 20190114180423.ywhdg2iagzvh43we@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

On 2019-01-14 11:57:55 -0500, Tom Lane wrote:
> I wrote:
> > Andres Freund <andres(at)anarazel(dot)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,
> > which at this point has accumulated a pretty serious collection of
> > bugs, judging by subsequent mentions in the commit log.

Hm, there was one bug related to this before? Fixing up test failures in
sepgsql (which I can't run locally) just after commit doesn't really
count.

> > 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?

Because the comparison is now done via ExprState machinery than manual
fmgr invocations. I'd discussed a patch solving this a few weeks ago
with Andrew Gierth, but got stuck with the fact that essentially all
fixes entail either an API or an ABI break - but I think we gotta do
that anyway.

For performance reasons the API really should be changed so we don't
allocate/deallocate the entire hashtable on each round - I've prototyped
a fix that only resets it and there's noticable performance gains. But
that's not something we can easily do in the back branches.

Let me rebase and cleanup my patches, it's probably easier to discuss
with them in front of us.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2019-01-14 22:28:38 Re: BUG #15592: Memory overuse with subquery containing unnest() and set operations (11.x regression)
Previous Message Stephen Frost 2019-01-14 17:57:31 Re: BUG #15591: pg_receivewal does not honor replication slots