pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: armando.miraglia@stud-inf.unibz.it
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6698: sub-query with join producing out of memory in where clause
Date: Thu, 21 Jun 2012 15:32:56 -0400
Message-ID: <567.1340307176@sss.pgh.pa.us> (raw)
In-Reply-To: <4FE072E7.2010000@enterprisedb.com>
References: <E1Sgmoz-0002gU-No@wrigleys.postgresql.org>
	<4FE072E7.2010000@enterprisedb.com>

Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
> This test case can be further reduced into:

> explain analyze
> SELECT * FROM generate_series(1,100000) i
> WHERE (SELECT array(select repeat('a', 10000) || i) u1) is not null;

> We're leaking the array constructed on each row, in ExecSetParamPlan(). 
> At line 1000 in nodeSubplan.c, we create a new array and store it as the 
> value of the PARAM_EXEC parameter. But it's never free'd. The old value 
> of the parameter is simply overwritten.

> I'm not sure what the correct fix is. I suppose we could pfree() the old 
> value before overwriting it, but I'm not sure if that's safe, or if 
> there might still be references to the old value somewhere in the executor.

I think it should be safe to pfree the prior value at this point.  If
you compare the code for scalar subplan results, a few lines above here,
pass-by-ref param values are references into node->curTuple which gets
summarily freed on the next cycle.  So if anybody is keeping a pointer
around then it would already be failing for non-ARRAY cases, and we've
not seen any such reports.  I think we can handle array results the same
way as curTuple, ie, keep a link in the node's state.  (I thought first
about trying to pfree the prior contents of prm->value itself, but I'm
less sure that that is safe --- if memory serves, the same ParamExecData
slot can sometimes be used for multiple purposes.)

Will give it a try ...

			regards, tom lane



view thread (4+ messages)

Message-ID: <567.1340307176@sss.pgh.pa.us>
Permalink:  ../567.1340307176@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/567.1340307176@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, heikki.linnakangas@enterprisedb.com, armando.miraglia@stud-inf.unibz.it
  Subject: Re: BUG #6698: sub-query with join producing out of memory in where clause
  In-Reply-To: <567.1340307176@sss.pgh.pa.us>
  References: <E1Sgmoz-0002gU-No@wrigleys.postgresql.org> <4FE072E7.2010000@enterprisedb.com> <567.1340307176@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox