pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: Eliot Gable <egable+pgsql-performance@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Replacing Cursors with Temporary Tables
Date: Thu, 22 Apr 2010 10:42:42 -0400
Message-ID: <q2yb42b73151004220742gbb7ae4adyc3781cedf98e8559@mail.gmail.com> (raw)
In-Reply-To: <n2sb42b73151004220711mc2135db6heccf53ec1fb0136e@mail.gmail.com>
References: <n2ybf6923ed1004211316ib844d82bn7a63bd3292ca80a0@mail.gmail.com>
	<n2sb42b73151004220711mc2135db6heccf53ec1fb0136e@mail.gmail.com>

On Thu, Apr 22, 2010 at 10:11 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
> The timings are similar, but the array returning case:
> *)  runs in a single statement.  If this is executed from the client
> that means less round trips
> *) can be passed around as a variable between functions.  temp table
> requires re-query
> *) make some things easier/cheap such as counting the array -- you get
> to call the basically free array_upper()
> *) makes some things harder.  specifically dealing with arrays on the
> client is a pain UNLESS you expand the array w/unnest() or use
> libpqtypes
> *) can nest. you can trivially nest complicated sets w/arrays
> *) does not require explicit transaction mgmt


I neglected to mention perhaps the most important point about the array method:
*) does not rely on any temporary resources.

If you write a lot of plpsql, you will start to appreciate the
difference in execution time between planned and unplanned functions.
The first time you run a function in a database session, it has to be
parsed and planned.  The planning time in particular for large-ish
functions that touch a lot of objects can exceed the execution time of
the function.  Depending on _any_ temporary resources causes plan mgmt
issues because the database detects that a table in the old plan is
gone ('on commit drop') and has to re-plan.   If your functions are
complex/long and you are counting milliseconds, then that alone should
be enough to dump any approach that depends on temp tables.

merlin



view thread (17+ messages)  latest in thread

Message-ID: <q2yb42b73151004220742gbb7ae4adyc3781cedf98e8559@mail.gmail.com>
Permalink:  ../q2yb42b73151004220742gbb7ae4adyc3781cedf98e8559@mail.gmail.com/
Also on:    postgresql.org/message-id/q2yb42b73151004220742gbb7ae4adyc3781cedf98e8559@mail.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-performance@postgresql.org
  Cc: mmoncure@gmail.com, egable+pgsql-performance@gmail.com
  Subject: Re: Replacing Cursors with Temporary Tables
  In-Reply-To: <q2yb42b73151004220742gbb7ae4adyc3781cedf98e8559@mail.gmail.com>
  References: <n2ybf6923ed1004211316ib844d82bn7a63bd3292ca80a0@mail.gmail.com> <n2sb42b73151004220711mc2135db6heccf53ec1fb0136e@mail.gmail.com> <q2yb42b73151004220742gbb7ae4adyc3781cedf98e8559@mail.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