pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Pedro França <pedro.franca@golsat.com.br>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Getting an optimal plan on the first execution of a pl/pgsql function
Date: Mon, 14 Dec 2015 15:41:57 -0500
Message-ID: <5607.1450125717@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbavm1XnbX1dS=8R6vrpUbnAo6HraqCg_UD2+v3nEjaRA@mail.gmail.com>
References: <CAGWJvi0WvWqyN_z5bERX_oCWPDeiOfOLvFv_vRS4S5AHvZfV7g@mail.gmail.com>
	<CAKFQuwbavm1XnbX1dS=8R6vrpUbnAo6HraqCg_UD2+v3nEjaRA@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Mon, Dec 14, 2015 at 11:53 AM, Pedro França <pedro.franca@golsat.com.br>
> wrote:
>> When I test with EXPLAIN ANALYZE after the first execution, the query runs
>> really fast but the aplication sessions call the function only once and
>> then are terminated. I need that the first execution use the actual
>> optimized plan.

> Your problem that the performance improvement is
> seen due to caching effects.  If you throw away the cache you loose the
> improvement.

Yeah.  And it's not only the function itself, it's catalog caches and a
bunch of other stuff.  Basically, you should expect that the first few
queries executed by any PG session are going to be slower than those
executed later.  If you can't fix your application to hold sessions open
for a reasonable amount of time, use a connection pooler to do it for you
(pgpooler for instance).

			regards, tom lane


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (4+ messages)  latest in thread

Message-ID: <5607.1450125717@sss.pgh.pa.us>
Permalink:  ../5607.1450125717@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5607.1450125717@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, pedro.franca@golsat.com.br
  Subject: Re: Getting an optimal plan on the first execution of a pl/pgsql function
  In-Reply-To: <5607.1450125717@sss.pgh.pa.us>

* 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