Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2A5w-000740-GA for pgsql-performance@arkaria.postgresql.org; Tue, 18 Sep 2018 07:06:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2A5u-0008QU-5V for pgsql-performance@arkaria.postgresql.org; Tue, 18 Sep 2018 07:06:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2A5t-0008QN-B4 for pgsql-performance@lists.postgresql.org; Tue, 18 Sep 2018 07:06:45 +0000 Received: from mx1.riseup.net ([198.252.153.129]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2A5p-00023m-IA for pgsql-performance@lists.postgresql.org; Tue, 18 Sep 2018 07:06:43 +0000 Received: from cotinga.riseup.net (cotinga-pn.riseup.net [10.0.1.164]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 0D6EB1A0144 for ; Tue, 18 Sep 2018 00:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1537254400; bh=hh9gWx52snLF42IJERtReGM36ayCcuOcc8XsGMUxNv8=; h=Date:From:To:Subject:From; b=XpsvlxbPvAn/Wmiat0seU1pDfFGssQiij8e0au+07AR/UQ5jt2+iYeOpiupKEvzC4 VAyXd5YI9M6WN0hJ0T38dbFTX8/0Rp55zXH3NR1e5d4oBfPl9yqgqpaDDk7gpM7lFu uw0j0AVzgnHgXT4HIh9KE7FpV5AFDA5Sh/IPxW34= X-Riseup-User-ID: 21A4E2BB3828B1E445F40C80760C6474C7AF105E088492AE7C20D7B26DE675A1 Received: from [127.0.0.1] (localhost [127.0.0.1]) by cotinga.riseup.net with ESMTPSA id 513BA8E7E7 for ; Tue, 18 Sep 2018 00:06:39 -0700 (PDT) Date: Tue, 18 Sep 2018 09:06:36 +0200 From: Nicolas Paris To: pgsql-performance@lists.postgresql.org Subject: LEFT JOIN LATERAL optimisation at plan time Message-ID: <20180918070636.tp243ftlwpzrfrsd@riseup.net> Mail-Followup-To: pgsql-performance@lists.postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Priority: normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, For a traditional LEFT JOIN, in case the SELECT does not mention a field from a joined table being unique , the planner removes the join. Eg: SELECT a, b --,c FROM table1 LEFT JOIN (select a, c from table2 group by a) joined USING (a) However this behavior is not the same for LATERAL JOINS SELECT a, b --,c FROM table1 LEFT JOIN LATERAL (select a, c from table2 where table1.a = table2.a group by a) joined ON TRUE In this case, the planner still consider the joined table. My guess is it could remove it . Any thought ? -- nicolas