Skip site navigation (1) Skip section navigation (2)

Re: Query only slow on first run

From: Kevin Kempter <kevin(at)kevinkempterllc(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query only slow on first run
Date: 2007-11-27 16:57:07
Message-ID: 200711270957.07818.kevin@kevinkempterllc.com (view raw or flat)
Thread:
Lists: pgsql-performance
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

In response to

pgsql-performance by date

Next:From: Tom LaneDate: 2007-11-27 17:26:08
Subject: Re: Query only slow on first run
Previous:From: Andrew SullivanDate: 2007-11-27 16:55:43
Subject: Re: Query only slow on first run

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group