X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4A0D49FB1C9 for ; Thu, 13 Jul 2006 13:33:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 19375-09 for ; Thu, 13 Jul 2006 13:33:53 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31801.mail.mud.yahoo.com (web31801.mail.mud.yahoo.com [68.142.207.64]) by postgresql.org (Postfix) with SMTP id 892799FA31F for ; Thu, 13 Jul 2006 13:33:53 -0300 (ADT) Received: (qmail 65197 invoked by uid 60001); 13 Jul 2006 16:33:52 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=f5wqHtQOZEtrzJTltSp761ulu5t7C8NzqVJAetIrwwgoF+NgGxfI7rVf6m2s1T285C6zUvacCTcG6sHWDTaL+zJWKyOsdI5sjuJUFOK1eMBB/b1naW3qxGQKPSdDR2drRCRxPm07kiIXI75Svzbkt2jiHt5Cu/ZC4QoJA9i8EFE= ; Message-ID: <20060713163352.65195.qmail@web31801.mail.mud.yahoo.com> Received: from [63.203.180.122] by web31801.mail.mud.yahoo.com via HTTP; Thu, 13 Jul 2006 09:33:52 PDT Date: Thu, 13 Jul 2006 09:33:52 -0700 (PDT) From: Richard Broersma Jr Subject: Re: How to find entries missing in 2nd table? To: Aaron Bono Cc: "Exner, Peter" , SQL Postgresql List In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/203 X-Sequence-Number: 25777 > > > > SELECT controller_id FROM control > > > > WHERE controller_id NOT IN > > > > (SELECT DISTINCT controller_id FROM datapack); > > > The DISTINCT is not necessary. I have heard with Oracle that DISTINCT > > is a > > > huge performance problem. Is that true on PostgreSQL also? > > > > From my experience, it does not preform as well as the standard group by > > clause. I noticed a ~20% > > increase in query run times. > > > > So in that case this would be better: > > SELECT controller_id FROM control > WHERE controller_id NOT IN > (SELECT controller_id FROM datapack); > > or > > SELECT controller_id FROM control > WHERE controller_id NOT IN > (SELECT controller_id FROM datapack GROUP BY controller_id); Well in this case, the group by or distinct is simple not needed for the query to preform correctly. The additional group by clause in the second query could cause it to preform additional processing which "may" cause it to preform slower. Regards, Richard Broersma Jr.