Re: strange query plan with LIMIT

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: anthony(dot)shipman(at)symstream(dot)com
Cc: pgsql-performance(at)postgresql(dot)org, Claudio Freire <klaussfreire(at)gmail(dot)com>
Subject: Re: strange query plan with LIMIT
Date: 2011-06-08 09:58:04
Message-ID: BANLkTi=iPiHELpnikeNM070+qyZVyiqbbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello

2011/6/8 <anthony(dot)shipman(at)symstream(dot)com>:
> On Wednesday 08 June 2011 18:39, Pavel Stehule wrote:
>> if you use FOR statement, there should be a problem in using a
>> implicit cursor - try to set a GUC cursor_tuple_fraction to 1.0.
> Alas this is mammoth replicator, equivalent to PG 8.3 and it doesn't have that
> parameter.

It should be a part of problem - resp. combination with bad statistic.
Maybe you should to rewrite your code to

DECLARE int i = 0;

FOR x IN EXECUTE '....'
LOOP
RETURN NEXT ...
i := i + 1;
EXIT WHEN i > limitvar
END LOOP

Regards

Pavel Stehule

> --
> Anthony Shipman                 | It's caches all the way
> Anthony(dot)Shipman(at)symstream(dot)com   | down.
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message tv 2011-06-08 11:08:10 Re: Set of related slow queries
Previous Message tv 2011-06-08 09:47:43 Re: strange query plan with LIMIT