Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Ryan Murphy <ryanfmurphy(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP
Date: 2018-01-28 14:40:01
Message-ID: CAKFQuwbu-cO8kC6LhFXmuPYMH+3UNXBHNT0YHOV6L6v-RvYxdQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sunday, January 28, 2018, Ryan Murphy <ryanfmurphy(at)gmail(dot)com> wrote:

> Hello,
>
> I heard at a PostgreSQL talk that you should not liberally create temp
> tables in the course of frequently-used functions etc, because (roughly)
> you're using up some of the same resources that you for your regular tables.
>
> Is this true? Is there an important reason not to have e.g. a plpgsql
> function that uses a temp table? What are the specific problems if I do
> this? Is the problem ameliorated if I add ON COMMIT DROP?
>

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.

The way most temp tables are used on commit drop likely has little impact
on this, but the specific usage pattern matters a great deal in answering
the question.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ryan Murphy 2018-01-28 14:46:50 Re: Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP
Previous Message Ryan Murphy 2018-01-28 13:58:09 Downsides of liberally using CREATE TEMP TABLE ... ON COMMIT DROP