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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-performance by date

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