Re: Query with limit goes from few ms to hours

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Kevin Grittner <kgrittn(at)mail(dot)com>
Cc: henk de wit <henk53602(at)hotmail(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Query with limit goes from few ms to hours
Date: 2012-10-23 20:08:15
Message-ID: 5086F92F.50406@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 10/23/2012 11:33 AM, Kevin Grittner wrote:
> henk de wit wrote:
>
>> Well, what do you know! That did work indeed. Immediately after the
>> ANALYZE on that parent table (taking only a few seconds) a fast
>> plan was created and the query executed in ms again. Silly me, I
>> should have tried that earlier.
> Of course, if your autovacuum settings are aggressive enough, you
> should gernerally not need to run ANALYZE explicitly. You should
> double-check that autovacuum is turned on and configured at least as
> aggressively as the default settings, or you will probably get little
> surprises like this when you least expect them.
>
>
The exception I'd make to Kevin's good advice is for cases when a
process makes substantial statistics-altering changes to your data (bulk
insert/delete/update) immediately followed by a query against the
updated table(s). In those cases there is a good possibility that the
statistics will not have been automatically updated before the
subsequent query is planned so an explicit ANALYZE between the update
and the query can be of value.

Cheers,
Steve

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Böckler Andreas 2012-10-24 15:41:07 Query-Planer from 6seconds TO DAYS
Previous Message Kevin Grittner 2012-10-23 18:33:16 Re: Query with limit goes from few ms to hours