Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovgCk-0005Ro-1K for pgsql-performance@arkaria.postgresql.org; Thu, 17 Nov 2022 14:49:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ovgCi-0004Gr-V7 for pgsql-performance@arkaria.postgresql.org; Thu, 17 Nov 2022 14:49:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovgCi-0004Gi-Le for pgsql-performance@lists.postgresql.org; Thu, 17 Nov 2022 14:49:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovgCg-0007NQ-GW for pgsql-performance@lists.postgresql.org; Thu, 17 Nov 2022 14:49:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2AHEnKlT1826811; Thu, 17 Nov 2022 09:49:20 -0500 From: Tom Lane To: Stefan Fehrenbach cc: pgsql-performance@lists.postgresql.org Subject: Re: When can joins be avoided? In-reply-to: References: Comments: In-reply-to Stefan Fehrenbach message dated "Wed, 16 Nov 2022 11:39:13 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1826809.1668696560.1@sss.pgh.pa.us> Date: Thu, 17 Nov 2022 09:49:20 -0500 Message-ID: <1826810.1668696560@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Stefan Fehrenbach writes: > I'm interested in the rules that Postgres uses to avoid joins. Are > these documented somewhere? If I had to look at the source code, where > would I start? src/backend/optimizer/plan/analyzejoins.c > They don't seem to match my intuition about which joins > could be avoided. I believe only left joins to single tables can be elided ATM. It's too hard to prove uniqueness of the join key in more- complicated cases. regards, tom lane