Re: Memory deallocation after calling cast function

Lists: pgsql-hackers
From: Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Memory deallocation after calling cast function
Date: 2014-06-03 08:51:06
Message-ID: CAFUsPDZQLHKetjY2iG0MZK9R2oK72xcYVpARWoxc49Z6jLUgBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi

I have problem with memory deallocation. look at the following queries

1- create table test01(a) as select generate_series(1,100000000)::int8 ;

2- create table test02(a) as select generate_series(1,100000000) ;

In execution of first query, memory usage increase rapidly until the
transaction comes to end and deallocate all the memory which allocated with
palloc.
I have wondered why all the memory deallocated at the end, so the cast is
removed and query executed again. memory usage was not the same. It was
grow very slow.

I need help to find the right point to deallocate the memory,
Any idea will be appreciated.

Soroosh Sardari


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Memory deallocation after calling cast function
Date: 2014-06-03 19:59:45
Message-ID: 21238.1401825585@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com> writes:
> I have problem with memory deallocation. look at the following queries

> 1- create table test01(a) as select generate_series(1,100000000)::int8 ;

Do it as, eg,

create table test01(a) as select g::int8 from generate_series(1,100000000) g;

SRFs in the SELECT targetlist tend to leak memory; this is not easily
fixable, and nobody is likely to try hard considering the feature's on
the edge of deprecation anyhow.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Memory deallocation after calling cast function
Date: 2014-06-17 15:32:37
Message-ID: 20140617153237.GD3666@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 3, 2014 at 03:59:45PM -0400, Tom Lane wrote:
> Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com> writes:
> > I have problem with memory deallocation. look at the following queries
>
> > 1- create table test01(a) as select generate_series(1,100000000)::int8 ;
>
> Do it as, eg,
>
> create table test01(a) as select g::int8 from generate_series(1,100000000) g;
>
> SRFs in the SELECT targetlist tend to leak memory; this is not easily
> fixable, and nobody is likely to try hard considering the feature's on
> the edge of deprecation anyhow.

Uh, what is replacing SRFs? CTEs?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +


From: Abhijit Menon-Sen <ams(at)2ndquadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Memory deallocation after calling cast function
Date: 2014-06-17 15:39:25
Message-ID: 20140617153924.GV5162@toroid.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

At 2014-06-17 11:32:37 -0400, bruce(at)momjian(dot)us wrote:
>
> > SRFs in the SELECT targetlist tend to leak memory; this is not easily
> > fixable, and nobody is likely to try hard considering the feature's on
> > the edge of deprecation anyhow.
>
> Uh, what is replacing SRFs? CTEs?

I don't think Tom was referring to SRFs in general, only putting them
directly into the targetlist of a SELECT.

-- Abhijit


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Abhijit Menon-Sen <ams(at)2ndquadrant(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Memory deallocation after calling cast function
Date: 2014-06-17 15:42:41
Message-ID: 20140617154241.GD6836@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2014-06-17 21:09:25 +0530, Abhijit Menon-Sen wrote:
> At 2014-06-17 11:32:37 -0400, bruce(at)momjian(dot)us wrote:
> >
> > > SRFs in the SELECT targetlist tend to leak memory; this is not easily
> > > fixable, and nobody is likely to try hard considering the feature's on
> > > the edge of deprecation anyhow.
> >
> > Uh, what is replacing SRFs? CTEs?
>
> I don't think Tom was referring to SRFs in general, only putting them
> directly into the targetlist of a SELECT.

And the primary reason for using SRFs in the targetlist has gone away
due to LATERAL. It's now possible to pass data from tables to a SRF,
that previously wasn't possibly unless you'd used a SRF in the targetlist.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Abhijit Menon-Sen <ams(at)2ndquadrant(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Soroosh Sardari <soroosh(dot)sardari(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Memory deallocation after calling cast function
Date: 2014-06-17 16:21:35
Message-ID: 2461.1403022095@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> On 2014-06-17 21:09:25 +0530, Abhijit Menon-Sen wrote:
>> At 2014-06-17 11:32:37 -0400, bruce(at)momjian(dot)us wrote:
>>> Uh, what is replacing SRFs? CTEs?

>> I don't think Tom was referring to SRFs in general, only putting them
>> directly into the targetlist of a SELECT.

> And the primary reason for using SRFs in the targetlist has gone away
> due to LATERAL.

Exactly. LATERAL does what you usually want from a SRF in the
targetlist, and it doesn't have bizarre semantics when you use more than
one.

regards, tom lane