Re: why query plan for the inner SELECT of WHERE x IN is wrong, but when run the inner query alone is OK? - Mailing list pgsql-performance

From Tom Lane
Subject Re: why query plan for the inner SELECT of WHERE x IN is wrong, but when run the inner query alone is OK?
Date
Msg-id 11224.1218315478@sss.pgh.pa.us
Whole thread Raw
In response to why query plan for the inner SELECT of WHERE x IN is wrong, but when run the inner query alone is OK?  (Miernik <public@public.miernik.name>)
List pgsql-performance
Miernik <public@public.miernik.name> writes:
> miernik=> EXPLAIN UPDATE cnts SET p0 = FALSE WHERE uid IN (SELECT uid FROM alog WHERE pid = 3452654 AND o = 1);
>                                           QUERY PLAN
> -----------------------------------------------------------------------------------------------
>  Nested Loop IN Join  (cost=0.00..3317.34 rows=1 width=44)
>    ->  Seq Scan on cnts  (cost=0.00..36.00 rows=2000 width=44)
>    ->  Index Scan using alog_uid_idx on alog  (cost=0.00..296.95 rows=1 width=4)
>          Index Cond: ((alog.uid)::integer = (cnts.uid)::integer)
>          Filter: ((alog.pid = 3452654::numeric) AND (alog.o = 1::numeric))
> (5 rows)

> But if I give him only the inner part, it makes reasonable assumptions
> and runs OK:

What's the results for

explain select * from cnts, alog where alog.uid = cnts.uid

?

If necessary, turn off enable_hashjoin and enable_mergejoin so we can
see a comparable plan.  I'm suspecting it thinks the condition on
uid is more selective than the one on the other index.

            regards, tom lane

pgsql-performance by date:

Previous
From: Miernik
Date:
Subject: why query plan for the inner SELECT of WHERE x IN is wrong, but when run the inner query alone is OK?
Next
From: Miernik
Date:
Subject: Re: why query plan for the inner SELECT of WHERE x IN is wrong, but when run the inner query alone is OK?