Re: Question about LEFT JOIN and query plan - Mailing list pgsql-performance

From Tom Lane
Subject Re: Question about LEFT JOIN and query plan
Date
Msg-id 25498.1283534083@sss.pgh.pa.us
Whole thread Raw
In response to Question about LEFT JOIN and query plan  (Kaloyan Iliev Iliev <kaloyan@digsys.bg>)
Responses Re: Question about LEFT JOIN and query plan
List pgsql-performance
Kaloyan Iliev Iliev <kaloyan@digsys.bg> writes:
> I have I query which behave strangely (according to me).
> According to the first plan PG makes absolutely unnecessary seq scan on
> tables "invoices" and "domeini" and etc.

I think you might get better results if you could get this rowcount
estimate a bit more in line with reality:

>              ->  Seq Scan on debts_desc dd  (cost=0.00..2866.52 rows=23782 width=46) (actual time=0.481..45.085
rows=1037loops=1) 
>                    Filter: (active AND (NOT paid) AND has_proform AND (NOT storned))

It's choosing to hash instead of doing (what it thinks will be) 23K
index probes into the other table.  For 1000 probes the decision
might be different.

I don't know if raising the stats target for that table will be enough
to fix it.  Most likely those four conditions are not uncorrelated.
You might need to think about revising the table's representation
so that the query condition can be simpler and thus more accurately
estimated.

            regards, tom lane

pgsql-performance by date:

Previous
From: Gerhard Wiesinger
Date:
Subject: Re: Major performance problem after upgrade from 8.3 to 8.4
Next
From: Tom Lane
Date:
Subject: Re: Major performance problem after upgrade from 8.3 to 8.4