Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suD7w-0054cu-Kd for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Sep 2024 15:43:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1suD7v-00BCcg-RB for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Sep 2024 15:43:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suD7v-00BCYq-Ib for pgsql-bugs@lists.postgresql.org; Fri, 27 Sep 2024 15:43:27 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suD7t-001L7I-4D for pgsql-bugs@lists.postgresql.org; Fri, 27 Sep 2024 15:43:26 +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 48RFhLuo491923; Fri, 27 Sep 2024 11:43:21 -0400 From: Tom Lane To: Dean Rasheed cc: Richard Guo , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18634: Wrong varnullingrels with merge ... when not matched by source In-reply-to: References: <18634-db5299c937877f2b@postgresql.org> <374420.1727390489@sss.pgh.pa.us> Comments: In-reply-to Dean Rasheed message dated "Fri, 27 Sep 2024 16:06:12 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <491921.1727451801.1@sss.pgh.pa.us> Date: Fri, 27 Sep 2024 11:43:21 -0400 Message-ID: <491922.1727451801@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dean Rasheed writes: > On Fri, 27 Sept 2024 at 13:52, Richard Guo wrote: >> I think we can check the jointype of the join between the target and >> the source relation when adding the vars in mergeJoinCondition. If it >> is JOIN_LEFT, we mark the vars that belong to source as nullable by >> this join. > Another option is to do it in transform_MERGE_to_join(). That feels > safer, because the jointree might have been modified by the time we > reach preprocess_targetlist(). Yeah, I think it's critical that these Vars be already correctly marked before we engage in all the slicing-and-dicing that prepjointree et al will do. As an example, it seems not impossible for join removal to make wrong decisions if they aren't. > Something like the attached. Could use some comments ... but actually, now I'm confused about why any of this is the right thing at all: + * Similarly, any non-target Vars in the join condition will be added to + * the targetlist by preprocess_targetlist(), and so must be marked as + * nullable by the join, for LEFT and FULL joins. Why do we need these Vars in the tlist? If they're for re-evaluating the join condition, isn't the already-nulled form of them the wrong thing? regards, tom lane