Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 14662650070 for ; Sat, 9 Aug 2008 17:58:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 07805-05 for ; Sat, 9 Aug 2008 17:57:57 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E5B3664FFE8 for ; Sat, 9 Aug 2008 17:57:59 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m79KvwRV011225; Sat, 9 Aug 2008 16:57:58 -0400 (EDT) To: Miernik cc: pgsql-performance@postgresql.org Subject: Re: why query plan for the inner SELECT of WHERE x IN is wrong, but when run the inner query alone is OK? In-reply-to: <20080809203435.7227.0.NOFFLE@turbacz.local> References: <20080809203435.7227.0.NOFFLE@turbacz.local> Comments: In-reply-to Miernik message dated "Sat, 09 Aug 2008 22:34:35 +0200" Date: Sat, 09 Aug 2008 16:57:58 -0400 Message-ID: <11224.1218315478@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/87 X-Sequence-Number: 30968 Miernik 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