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 1llBJ2-0007om-8t for pgsql-performance@arkaria.postgresql.org; Mon, 24 May 2021 14:11:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1llBJ1-0007Qh-9R for pgsql-performance@arkaria.postgresql.org; Mon, 24 May 2021 14:11:43 +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 1llBJ1-0007QZ-1g for pgsql-performance@lists.postgresql.org; Mon, 24 May 2021 14:11:43 +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 1llBIz-0001ju-4Q for pgsql-performance@postgresql.org; Mon, 24 May 2021 14:11:42 +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 14OEBdIW885509; Mon, 24 May 2021 10:11:39 -0400 From: Tom Lane To: Philip Lykke Carlsen cc: pgsql-performance@postgresql.org Subject: Re: Optimising outer joins in the presence of non-nullable references In-reply-to: References: Comments: In-reply-to Philip Lykke Carlsen message dated "Mon, 24 May 2021 14:10:24 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <885507.1621865499.1@sss.pgh.pa.us> Date: Mon, 24 May 2021 10:11:39 -0400 Message-ID: <885508.1621865499@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Philip Lykke Carlsen writes: > My question then is, shouldn't the inner and outer join queries be > semantically equivalent when the columns we are joining on are > non-nullable foreign keys? Maybe, but no such knowledge is built into the planner. > Is there some corner case I'm not considering? I'm a little suspicious whether it's actually a safe assumption to make, in view of the fact that enforcement of FKs is delayed till end-of-statement or even end-of-transaction. Thus, the relationship isn't necessarily valid at every instant. > Would it be a good addition to postgres if it could detect this and > produce a plan that exploits the indices? Maybe. Aside from semantic correctness issues, the big question would be whether the detection could be made cheap enough to not be a drag on the 99.99% of cases where it's not helpful. regards, tom lane