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 1o7NRd-0003iT-Gi for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 20:40:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7NRb-0000Rd-J8 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 20:40:51 +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 1o7NRb-0000Qu-9s for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 20:40:51 +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 1o7NRX-0007q9-AR for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 20:40:50 +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 261Kejpg089527; Fri, 1 Jul 2022 16:40:45 -0400 From: Tom Lane To: "Finnerty, Jim" cc: "pgsql-hackers@lists.postgresql.org" Subject: Re: Making Vars outer-join aware In-reply-to: References: <830269.1656693747@sss.pgh.pa.us> Comments: In-reply-to "Finnerty, Jim" message dated "Fri, 01 Jul 2022 20:19:48 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <89525.1656708045.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 01 Jul 2022 16:40:45 -0400 Message-ID: <89526.1656708045@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Finnerty, Jim" writes: > Given that views are represented in a parsed representation, does an= ything need to happen to the Vars inside a view when that view is outer-jo= ined to? = No. The markings only refer to what is in the same Query tree as the Var itself. Subquery flattening during planning does deal with this: if we pull up a subquery (possibly inserted from a view) that was underneath an outer join, the nullingrel marks on the upper-level Vars referring to subquery outputs will get merged into what is pulled up, either by unioning the varnullingrel bitmaps if what is pulled up is just a Var, or if what is pulled up isn't a Var, by wrapping it in a PlaceHolderVar that carries the old outer Var's markings. We had essentially this same behavior with PlaceHolderVars before, but I think this way makes it a lot more principled and intelligible (and I suspect there are now cases where we manage to avoid inserting unnecessary PlaceHolderVars that the old code couldn't avoid). > If an outer join is converted to an inner join, must this informatio= n get propagated to all the affected Vars, potentially across query block = levels? Yes. The code is there in the patch to run around and remove nullingrel bits from affected Vars. One thing that doesn't happen (and didn't before, so this is not a regression) is that if we strength-reduce a FULL JOIN USING to an outer or plain join, it'd be nice if the "COALESCE" hack we represent the merged USING column with could be replaced with the same lower-relation Var that the parser would have used if the join weren't FULL to begin with. Without that, we're leaving optimization opportunities on the table. I'm hesitant to try to do that though as long as the COALESCE structures look exactly like something a user could write. It'd be safer if we used some bespoke node structure for this purpose ... but nobody's bothered to invent that. regards, tom lane