Re: Redundant sub query triggers slow nested loop left join - Mailing list pgsql-performance

From Tom Lane
Subject Re: Redundant sub query triggers slow nested loop left join
Date
Msg-id 10143.1177274553@sss.pgh.pa.us
Whole thread Raw
In response to Re: Redundant sub query triggers slow nested loop left join  ("henk de wit" <henk53602@hotmail.com>)
Responses Re: Redundant sub query triggers slow nested loop left join
Re: Redundant sub query triggers slow nested loop left join
List pgsql-performance
"henk de wit" <henk53602@hotmail.com> writes:
> I understand the above looks like a complicated mess, but would you
> have any pointers of what I could possibly do next to force a better plan?

Taking a closer look, it seems the problem is the underestimation of the
number of rows resulting from this relation scan:

>                  ->  Bitmap Heap Scan on
> banners_links  (cost=11.43..954.03 rows=2 width=73) (actual
> time=0.128..1.069 rows=359 loops=1)
>                        Recheck Cond: (merchant_id = 5631)
>                        Filter: ((status)::text = '0'::text)
>                        ->  Bitmap Index Scan on
> banners_links_merchant_id_idx  (cost=0.00..11.43 rows=424 width=0) (actual
> time=0.089..0.089 rows=424 loops=1)
>                              Index Cond: (merchant_id = 5631)

You might be able to improve matters by increasing the statistics target
for this table.  I have a bad feeling though that the problem may be
lack of cross-column statistics --- the thing is evidently assuming
that only about 1 in 200 rows have status = '0', which might be accurate
as a global average but not for this particular merchant.  What exactly
is the relationship between status and merchant_id, anyway?

            regards, tom lane

pgsql-performance by date:

Previous
From: "henk de wit"
Date:
Subject: Re: Redundant sub query triggers slow nested loop left join
Next
From: "henk de wit"
Date:
Subject: Re: Redundant sub query triggers slow nested loop left join