Re: Can I force a query plan to materialise part?

From: Toby Corkindale <toby(dot)corkindale(at)strategicdata(dot)com(dot)au>
To: Ondrej Ivanič <ondrej(dot)ivanic(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>, David Johnston <polobo(at)yahoo(dot)com>
Subject: Re: Can I force a query plan to materialise part?
Date: 2012-10-02 03:28:32
Message-ID: 506A5F60.1080909@strategicdata.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/10/12 13:02, Ondrej Ivanič wrote:
> Hi,
>
> On 2 October 2012 12:33, Toby Corkindale
> <toby(dot)corkindale(at)strategicdata(dot)com(dot)au> wrote:
>> I have a query that joins two views, and takes 28 seconds to run.
>> However if I create temporary tables that contain the contents of each view,
>> and then join them, the total time is 1.3 seconds.
>
> try "offset 0" (or you can tweak statistics collector to get better estimates):
> select ... from (select * from view offset 0) as v ....
>
> http://blog.endpoint.com/2009/04/offset-0-ftw.html

Thanks, that ran in 820ms. (Same query with subselects but without the
OFFSET 0 ran in 28370ms)

David's method is also running in 820ms. I erroneously stated it was
349ms before, but that was actually how long it took to display the
results of EXPLAIN.

I wish I could work out what's wrong with the statistics that cause the
query plan to go awry.. the tables aren't actually very large and I've
played with the statistics setup previously and it seemed right..

many thanks,
Toby

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Phoenix Kiula 2012-10-02 03:29:09 Re: Again, problem with pgbouncer
Previous Message Toby Corkindale 2012-10-02 03:22:57 Re: Can I force a query plan to materialise part?