Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X4d7O-0001Bd-Ve for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Jul 2014 21:40:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X4d7O-0001BL-G4 for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Jul 2014 21:40:06 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4d7N-000196-1X for pgsql-bugs@postgresql.org; Tue, 08 Jul 2014 21:40:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4d7J-0004sq-Vp for pgsql-bugs@postgresql.org; Tue, 08 Jul 2014 21:40:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s68Le0vu002518; Tue, 8 Jul 2014 17:40:00 -0400 From: Tom Lane To: Moshe Jacobson cc: pgsql-bugs@postgresql.org, Robert Mowlavi , Chris Autry Subject: Re: LEFT JOINs not optimized away when not needed In-reply-to: References: <8401.1404832771@sss.pgh.pa.us> <30516.1404848833@sss.pgh.pa.us> <709.1404852028@sss.pgh.pa.us> Comments: In-reply-to Moshe Jacobson message dated "Tue, 08 Jul 2014 16:44:39 -0400" Date: Tue, 08 Jul 2014 17:40:00 -0400 Message-ID: <2517.1404855600@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Moshe Jacobson writes: > On Tue, Jul 8, 2014 at 4:40 PM, Tom Lane wrote: >> No. There is nothing about GROUP BY in the join removal logic. > OK. Thank you. Is this something that would make sense to add? Dunno. I don't recall any previous requests for such a thing, so I'd not be inclined to add it unless it can be done very cheaply (in terms of both code and runtime). However, it seems like that might possibly be the case, if someone wanted to pursue making a patch. The existing logic to check for "no references above the join" would serve fine to exclude grouping by the inner relation, so it might only be necessary to check that the query has GROUP BY/DISTINCT at all (and, I guess, no aggregates or window functions). Or possibly I'm missing something. > More importantly, do you have any suggestions on how we can improve the > speed of our views when only a couple of columns are selected from them? Well, I'd stay away from twenty-seven-way joins if I were you :-(. That's a recipe for pain. Perhaps denormalizing your schema a bit would help there. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs