Re: analyzing intermediate query

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: "Scott Carey" <scott(at)richrelevance(dot)com>, <pgsql-performance(at)postgresql(dot)org>, "PFC" <lists(at)peufeu(dot)com>
Subject: Re: analyzing intermediate query
Date: 2008-12-02 18:58:43
Message-ID: 772C0DC9C4A04AA4939EB50F2707A791@andrusnotebook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Scott,

>Often times, switching an inner subselect that requires a distinct to a
>group by on that column yields better results. In this case, the IN should
>be equivalent, so it probably will not help. This would look like:

SELECT dok.*
FROM dok
JOIN (SELECT dokumnr FROM temptbl GROUP BY dokumnr ) x USING(dokumnr);

Thank you. This may be great idea.
I changed my query to use GROUP BY instead of DISTINCT

>Whether that hepls depends on how big dokumnr is and where the query
>bottleneck is.

I'm wondering how this can solve the issue when there is single or few
dokumnr columns.
Planner still thinks that temptbl projection contains 1000 rows and uses seq
scan instead of using bitmap index on dok table.

I tried

SELECT dok.*
FROM dok
JOIN (SELECT dokumnr FROM temptbl GROUP BY dokumnr ANALYZE ) x
USING(dokumnr);

but got error.

> Note there are subtle differences between DISTINCT and GROUP BY with
> respect to nulls.

dokumnr is int type and is not null always.

Andrus.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Scott Carey 2008-12-02 21:21:57 Re: analyzing intermediate query
Previous Message Scott Carey 2008-12-02 17:50:03 Re: analyzing intermediate query