Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id EDA25635D8C for ; Wed, 1 Apr 2009 15:42:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 04366-02-2 for ; Wed, 1 Apr 2009 15:42:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jimbo.globalnet.hr (jimbo.bnet.hr [213.149.32.23]) by mail.postgresql.org (Postfix) with ESMTP id 4A0EA635373 for ; Wed, 1 Apr 2009 15:42:02 -0300 (ADT) Received: from mail.globalnet.hr (cartman.globalnet.hr [213.149.32.10]) by jimbo.globalnet.hr (Postfix) with ESMTP id CE8862D807B for ; Wed, 1 Apr 2009 20:41:52 +0200 (CEST) Received: (qmail 12884 invoked from network); 1 Apr 2009 18:41:52 -0000 X-Mail-Scanner: Scanned by qSheff-II-2.1-r2 (http://www.enderunix.org/qsheff/) Received: from dh207-116-254.xnet.hr (HELO [88.207.116.254]) ([88.207.116.254]) (envelope-sender ) by 0 (qmail-ldap-1.03) with SMTP for ; 1 Apr 2009 18:41:51 -0000 Message-ID: <49D3B56D.9050802@zg.htnet.hr> Date: Wed, 01 Apr 2009 20:41:49 +0200 From: Rikard Pavelic User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: self join revisited References: <49D3969F.4030701@zg.htnet.hr> <7884.1238606350@sss.pgh.pa.us> In-Reply-To: <7884.1238606350@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200904/26 X-Sequence-Number: 33393 Tom Lane wrote: > Rikard Pavelic writes: > >> It would be great if Postgres could rewrite this query >> > > AFAICS those queries are not going to produce the same results, > so Postgres would be 100% incorrect to rewrite it like that for you. > > (If they do produce the same results, it would depend on a bunch > of assumptions you have not stated.) > > regards, tom lane > Can I try again? :) How hard would it be to teach the planner about preserving uniqueness of relations in subqueries? And using that information to remove unnecessary self joins on unique sets? I can try to rewrite some queries to test it on real data for how much gain it would provide. Regards, Rikard