X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A0CAD475C15 for ; Thu, 17 Apr 2003 12:28:31 -0400 (EDT) Received: from email02.aon.at (WARSL401PIP7.highway.telekom.at [195.3.96.94]) by postgresql.org (Postfix) with SMTP id 3034C475C3D for ; Thu, 17 Apr 2003 12:28:22 -0400 (EDT) Received: (qmail 401110 invoked from network); 17 Apr 2003 16:24:24 -0000 Received: from m160p004.dipool.highway.telekom.at (HELO cantor) ([62.46.9.228]) (envelope-sender ) by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 17 Apr 2003 16:24:24 -0000 From: Manfred Koizar To: Jonathan Moore Cc: pgsql-performance@postgresql.org Subject: Re: dum query plan: more info. Date: Thu, 17 Apr 2003 18:24:24 +0200 Message-ID: References: <1050530569.20873.120.camel@spunge-bob> In-Reply-To: <1050530569.20873.120.camel@spunge-bob> X-Mailer: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-32.2 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_FORTE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/154 X-Sequence-Number: 1660 On 16 Apr 2003 15:02:49 -0700, Jonathan Moore wrote: >select A.left form pairs A, pairs B where A.left != B.right; > >take the DB: > >(1,2) >(2,1) >(1,5) >(4,5) >(5,2) > >[...] 4 is the only value that is on the left and only >on the left. But this is not the answer to your SQL statement. The correct answer is: left ------ 1 1 1 1 2 2 2 1 1 1 1 4 4 4 4 4 5 5 5 (19 rows) What you are looking for is more like SELECT left FROM pairs EXCEPT SELECT right FROM pairs; >This methoud is order O(n) if both colums have b-tree indexes so you >don't have to pre sort them othere wise it is O(n*log(n)) as the sort is >the greatest complexity. In eathere case it is way better then O(n^2) >for almost any n. And I'm sure it will not take O(n^2) time in Postgres. Servus Manfred