pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: Andy Colson <andy@squeakycode.net>
Cc: Ryan Murphy <ryanfmurphy@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP
Date: Sun, 28 Jan 2018 12:22:03 -0700
Message-ID: <EAE90B70-970D-491A-A82A-971E50A1DF5D@gmail.com> (raw)
In-Reply-To: <e011c9de-4239-0205-3c6e-94b60d20a057@squeakycode.net>
References: <CAHeEsBd5LJfHDkawj9VHfhbtMkrQ-npFw8pyVg2T7mv4=7nkzw@mail.gmail.com>
	<CAKFQuwbu-cO8kC6LhFXmuPYMH+3UNXBHNT0YHOV6L6v-RvYxdQ@mail.gmail.com>
	<CAHeEsBfRXy15hQVUi_3BP=6mjr46pc+SDwvxpGn5So3_wheZJQ@mail.gmail.com>
	<e011c9de-4239-0205-3c6e-94b60d20a057@squeakycode.net>

 “On commit drop” is generally good practice for several reasons: if your function is called in a loop, or the create statement is in a loop or you want to call your function more than once in a given session (with out explicitly dropping your temp table).
The commit in question is the function btw. 

> On Jan 28, 2018, at 8:53 AM, Andy Colson <andy@squeakycode.net> wrote:
> 
>> On 01/28/2018 08:46 AM, Ryan Murphy wrote:
>>    I believe the main, and maybe only, concern is the bloating of the system catalog tables since you are constantly adding and removing records.  Yes, they will be vacuumed but vacuuming and bloat on catalog tables slows every single query down to some, degree since every query has to lookup its objects is those catalogs.  Though caching probably alleviates some of that
>> Yes, that's exactly the concern I heard, thanks for reminding me.
>> If I want to e.g. temporarily store a "setof records" or a "table" result in a variable as part of a calculation in a plpgsql function, do I have any other option than CREATE TEMPORARY TABLE?  It didn't seem to work when I DECLAREd a variable of type "setof table_name" or "setof table_name%rowtype", and then SELECT INTO it.
> 
> You may not need temp tables at all.  You can use subselects, derived tables, and cte's:
> 
> select sum(a+b) as total
> from (
>   select a, b+1
>   from detail
> ) as tmpx;
> 
> 
> This does the same thing as a temp table, with no temp table.
> 
> -Andy
> 




view thread (7+ messages)  latest in thread

Message-ID: <EAE90B70-970D-491A-A82A-971E50A1DF5D@gmail.com>
Permalink:  ../EAE90B70-970D-491A-A82A-971E50A1DF5D@gmail.com/
Also on:    postgresql.org/message-id/EAE90B70-970D-491A-A82A-971E50A1DF5D@gmail.com

 · 

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-general@postgresql.org
  Cc: robjsargent@gmail.com, andy@squeakycode.net, ryanfmurphy@gmail.com, david.g.johnston@gmail.com
  Subject: Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP
  In-Reply-To: <EAE90B70-970D-491A-A82A-971E50A1DF5D@gmail.com>
  References: <CAHeEsBd5LJfHDkawj9VHfhbtMkrQ-npFw8pyVg2T7mv4=7nkzw@mail.gmail.com> <CAKFQuwbu-cO8kC6LhFXmuPYMH+3UNXBHNT0YHOV6L6v-RvYxdQ@mail.gmail.com> <CAHeEsBfRXy15hQVUi_3BP=6mjr46pc+SDwvxpGn5So3_wheZJQ@mail.gmail.com> <e011c9de-4239-0205-3c6e-94b60d20a057@squeakycode.net> <EAE90B70-970D-491A-A82A-971E50A1DF5D@gmail.com>

* 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