Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B238BB5DBCC for ; Tue, 14 Jun 2011 17:21:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 45013-02 for ; Tue, 14 Jun 2011 20:21:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 3D7E1B5D803 for ; Tue, 14 Jun 2011 17:21:38 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QWa7F-0001hN-0z for pgsql-performance@postgresql.org; Tue, 14 Jun 2011 22:21:37 +0200 Received: from p5dc4fff0.dip.t-dialin.net ([93.196.255.240]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 14 Jun 2011 22:21:37 +0200 Received: from shortcutter by p5dc4fff0.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 14 Jun 2011 22:21:37 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: Robert Klemme Subject: Re: need to repeat the same condition on joined tables in order to choose the proper plan Date: Tue, 14 Jun 2011 22:21:17 +0200 Lines: 33 Message-ID: References: <676.1308068945@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p5dc4fff0.dip.t-dialin.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: <676.1308068945@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_RP_MATCHES_RCVD=-0.01, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201106/134 X-Sequence-Number: 44067 On 14.06.2011 18:29, Tom Lane wrote: > Svetlin Manavski writes: >> I am really surprised to see that the planner needs me to explicitly specify >> the same condition twice like this: > >> SD.detectorid = SS.detectorid >> and SD.sessionid = SS.id >> and SD.detectorid = 1 >> and SD.sessionid>= 1001000000000::INT8 and SD.sessionid<= >> 2001000000000::INT8 >> and SS.detectorid = 1 >> and SS.id>= 1001000000000::INT8 and SS.id<= 2001000000000::INT8 > > The planner does infer implied equalities, eg, given A = B and B = C > it will figure out that A = C. What you are asking is for it to derive > inequalities, eg infer A< C from A = B and B< C. That would be > considerably more work for considerably less reward, since the sort of > situation where this is helpful doesn't come up very often. On balance > I don't believe it's a good thing for us to do: I think it would make > PG slower on average because on most queries it would just waste time > looking for this sort of situation. > > (In this example, the SS.detectorid = 1 clause is in fact unnecessary, > since the planner will infer it from SD.detectorid = SS.detectorid and > SD.detectorid = 1. But it won't infer the range conditions on SS.id > from the range conditions on SD.sessionid or vice versa.) Is that the same for IN? Would it help in this particular case to use a and SS.id in (select ... where ... > and ... < ...) or with a CTE? Kind regards robert