Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efpHO-0000nN-24 for pgsql-general@arkaria.postgresql.org; Sun, 28 Jan 2018 15:54:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efpHL-0002dN-K0 for pgsql-general@arkaria.postgresql.org; Sun, 28 Jan 2018 15:53:59 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1efpHL-0002dD-03 for pgsql-general@lists.postgresql.org; Sun, 28 Jan 2018 15:53:59 +0000 Received: from squeakycode.net ([96.126.114.205]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efpHI-0004Ut-7k for pgsql-general@postgresql.org; Sun, 28 Jan 2018 15:53:57 +0000 Received: from [IPv6:2604:2d80:c02c:8776:2ad2:44ff:fe4b:d322] (unknown [IPv6:2604:2d80:c02c:8776:2ad2:44ff:fe4b:d322]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: andy) by squeakycode.net (Postfix) with ESMTPSA id 2EEAC227AF; Sun, 28 Jan 2018 09:53:54 -0600 (CST) Subject: Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP To: Ryan Murphy , "David G. Johnston" Cc: "pgsql-general@postgresql.org" References: From: Andy Colson Message-ID: Date: Sun, 28 Jan 2018 09:53:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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