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 1efsWp-0006ox-0z for pgsql-general@arkaria.postgresql.org; Sun, 28 Jan 2018 19:22:11 +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 1efsWn-0006xt-Rj for pgsql-general@arkaria.postgresql.org; Sun, 28 Jan 2018 19:22:09 +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 1efsWn-0006xh-De for pgsql-general@lists.postgresql.org; Sun, 28 Jan 2018 19:22:09 +0000 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1efsWk-0000RE-UZ for pgsql-general@postgresql.org; Sun, 28 Jan 2018 19:22:08 +0000 Received: by mail-io0-x243.google.com with SMTP id c17so5376357iod.1 for ; Sun, 28 Jan 2018 11:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jkHUzIoL4MPW31RlePx5fY1h61ClG380AiRincHdmCA=; b=YpMlLcZk+2+aI+ce1ERK46RsyW4Eqvpb4IXzaBTtu8rkMT657Q4DfsmxXmC0ZRsxhu sYt0J8n+zZD6i9tPQouq641Z0zg8wlDIgtQmS0yhdpYRU0HpjsG9u50MS4QKwb5J35G5 MQ3Y8+6BDSyJg57O9UGiwe8oqXXRMT4Ls3sTPyo5K6mnHKnWFVDjpwHwjJwLWzdOuQY/ JTrmX0VdomLXyaS/tyoBLWoNyu1N7p/fh9YryRECzXcNUU7MJ3xD/lJUIG3wL0Ye0CJ/ l2q3qYbdm/iQ6ysS8ihq2KEJaWmWNGlK325xl1jxnbs1FBP4u+06pf/dcZO+q/u3QxxA Txtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jkHUzIoL4MPW31RlePx5fY1h61ClG380AiRincHdmCA=; b=XPwrB2FtCuEp8Autr1Xx3tEf5vMPDkvjmf3GcxTwZ8qc0Ebvog59o1S6Ld0y1bbYjd eEYkKwqoavD3aZFWRlV23gSaFMDr+X6OhHRBu/V39K0hlGL21/P5wu4wz3czfX5ddQmd 78bCm95QkPEJSU542NEnJFrNQadWt+LXqG8cbTRX/whS9fz1x5dFakkp3ZMm/XxzAh7u AXgyhzXIdlPcNGozUI7SdS1EjJGH1vu43rV5ALboCvbqf6XoX2Ajyxa+PN5+TmGniyz5 RX86+nzjzO3nCf3DiX1pf5VdkIXXL8PDok4qEL8PgssYiX+NurZzmB4Fm7fdawATjmub g0Sw== X-Gm-Message-State: AKwxytcPNgCKWrU5mHv6cRi+ywAsjp4hQJ0X/76bO5LiEfIJhObdLT+r aXNcn0OOxGjVnmJA8xwppWVZfMfM X-Google-Smtp-Source: AH8x227RKplcAsOJgivm9uTVyRa0Ut2gh6j9JzwCIIlhZxQ8NB0z3clIlfb6/ozoKlBCik1Dy9yNZw== X-Received: by 10.107.52.16 with SMTP id b16mr24864223ioa.103.1517167325366; Sun, 28 Jan 2018 11:22:05 -0800 (PST) Received: from [192.168.1.102] (c-98-202-193-197.hsd1.ut.comcast.net. [98.202.193.197]) by smtp.gmail.com with ESMTPSA id s70sm6430454itb.0.2018.01.28.11.22.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 11:22:04 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP From: Rob Sargent X-Mailer: iPhone Mail (15C202) In-Reply-To: Date: Sun, 28 Jan 2018 12:22:03 -0700 Cc: Ryan Murphy , "David G. Johnston" , "pgsql-general@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Andy Colson List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =E2=80=9COn commit drop=E2=80=9D is generally good practice for several rea= sons: if your function is called in a loop, or the create statement is in a l= oop or you want to call your function more than once in a given session (wit= h out explicitly dropping your temp table). The commit in question is the function btw.=20 > On Jan 28, 2018, at 8:53 AM, Andy Colson wrote: >=20 >> On 01/28/2018 08:46 AM, Ryan Murphy wrote: >> I believe the main, and maybe only, concern is the bloating of the sys= tem catalog tables since you are constantly adding and removing records. Ye= s, they will be vacuumed but vacuuming and bloat on catalog tables slows eve= ry single query down to some, degree since every query has to lookup its obj= ects 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 DE= CLAREd a variable of type "setof table_name" or "setof table_name%rowtype", a= nd then SELECT INTO it. >=20 > You may not need temp tables at all. You can use subselects, derived tabl= es, and cte's: >=20 > select sum(a+b) as total > from ( > select a, b+1 > from detail > ) as tmpx; >=20 >=20 > This does the same thing as a temp table, with no temp table. >=20 > -Andy >=20