Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TJTDr-0000ck-Iw for pgsql-bugs@postgresql.org; Wed, 03 Oct 2012 17:59:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TJTDo-00027n-F7 for pgsql-bugs@postgresql.org; Wed, 03 Oct 2012 17:59:03 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q93Hwxit018048; Wed, 3 Oct 2012 13:58:59 -0400 (EDT) From: Tom Lane To: l1t@tom.com cc: pgsql-bugs@postgresql.org, ringerc@ringerc.id.au Subject: Re: =?gb2312?B?UkU6UmU6IEJVRyAjNzU1NiBhZGRpdGlvbiBpbmZv?= In-reply-to: <506B9573.000017.14453@cnapp22> References: <506B9573.000017.14453@cnapp22> Comments: In-reply-to l1t@tom.com message dated "Wed, 03 Oct 2012 09:31:31 +0800" Date: Wed, 03 Oct 2012 13:58:59 -0400 Message-ID: <18047.1349287139@sss.pgh.pa.us> X-Pg-Spam-Score: -4.0 (----) X-Archive-Number: 201210/28 X-Sequence-Number: 34328 l1t@tom.com writes: > I think the id columns of table a and b are not null, so the query of "not in" and "not exists" are equal,they should use similar plans. NOT IN and NOT EXISTS are *not* equivalent. Per SQL standard, NOT IN has different (and usually not very desirable) behavior with NULL values. The spec-mandated behavior makes it a lot harder to optimize nicely --- and since you usually don't want what it does anyway, we haven't tried hard. regards, tom lane