Re: Query only slow on first run - Mailing list pgsql-performance

From Kevin Kempter
Subject Re: Query only slow on first run
Date
Msg-id 200711270957.07818.kevin@kevinkempterllc.com
Whole thread Raw
In response to Query only slow on first run  (cluster <skrald@amossen.dk>)
List 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

pgsql-performance by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Query only slow on first run
Next
From: Tom Lane
Date:
Subject: Re: Query only slow on first run