pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Kempter <kevin@kevinkempterllc.com>
To: pgsql-performance@postgresql.org
Subject: Re: Query only slow on first run
Date: Tue, 27 Nov 2007 09:57:07 -0700
Message-ID: <200711270957.07818.kevin@kevinkempterllc.com> (raw)
In-Reply-To: <fihgt1$1mmh$1@news.hub.org>
References: <fihgt1$1mmh$1@news.hub.org>

On Tuesday 27 November 2007 09:33:36 cluster wrote:
> I have a query that takes about 7000 ms in average to complete the first
> time it runs. Subsequent runs complete in only 50 ms. That is more than
> a factor 100 faster! How can I make the query perform good in the first
> run too?
>
> Query and output from both first and second run of Explain Analyze is
> pasted here:
>
> http://rafb.net/p/yrKyoA17.html
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match


The query is faster the second run because the data pages were pulled into the 
buffer pool during the first run. I would suggest using the explain plan from 
the first run and test your changes on a recently started instance (or at 
least on an instance where enough activity has transpired to effectively 
rotate the buffer pages).

/Kevin



view thread (24+ messages)  latest in thread

Message-ID: <200711270957.07818.kevin@kevinkempterllc.com>
Permalink:  ../200711270957.07818.kevin@kevinkempterllc.com/
Also on:    postgresql.org/message-id/200711270957.07818.kevin@kevinkempterllc.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: kevin@kevinkempterllc.com
  Subject: Re: Query only slow on first run
  In-Reply-To: <200711270957.07818.kevin@kevinkempterllc.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