Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X4bMI-00035G-P2 for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Jul 2014 19:47:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X4bMG-0003j2-Rp for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Jul 2014 19:47:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4bMF-0003iv-Ui for pgsql-bugs@postgresql.org; Tue, 08 Jul 2014 19:47:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4bMC-0003bw-OF for pgsql-bugs@postgresql.org; Tue, 08 Jul 2014 19:47:18 +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 s68JlDHM030517; Tue, 8 Jul 2014 15:47:13 -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> Comments: In-reply-to Moshe Jacobson message dated "Tue, 08 Jul 2014 14:33:14 -0400" Date: Tue, 08 Jul 2014 15:47:13 -0400 Message-ID: <30516.1404848833@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 11:19 AM, Tom Lane wrote: >> What's your setting of join_collapse_limit, and if it's less than >> 27, does raising it fix this query? > We raised it to 30 and restarted postgres but the query plan still touched > all of the tables. All of the tables? Your upthread EXPLAIN result (which I duplicated here) shows it touching only nine of the 27 tables. AFAICS, the eight un-removed joins are either joining to non-unique keys, or can't be removed because their tables are needed to provide joining columns for un-removable joins. My thought that join_collapse_limit might matter was incorrect -- I was thinking that remove_useless_joins() was invoked on subproblems, but actually it considers the whole jointree. This is borne out by experimentation; changing it doesn't change the set of removed joins in this example. (Which is a good thing because you really didn't want to run with a collapse_limit as high as 30.) So it looks to me like it's operating as intended. 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