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 1ssrHn-00BSMe-9e for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2024 22:12:03 +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 1ssrHm-00FlyW-KU for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2024 22:12:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ssrHm-00FlvI-BL for pgsql-bugs@lists.postgresql.org; Mon, 23 Sep 2024 22:12:02 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ssrHi-000jPa-Cu for pgsql-bugs@lists.postgresql.org; Mon, 23 Sep 2024 22:12:01 +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 48NMBtR83239685; Mon, 23 Sep 2024 18:11:55 -0400 From: Tom Lane To: Richard Guo cc: David Rowley , gourlaouen.mikael@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18627: Regression (15 -> 16) - Join removal not performed when join condition spans multiple tables In-reply-to: References: <18627-44f950eb6a8416c2@postgresql.org> <2899426.1727024160@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Mon, 23 Sep 2024 15:55:59 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3239683.1727129515.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 23 Sep 2024 18:11:55 -0400 Message-ID: <3239684.1727129515@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Mon, Sep 23, 2024 at 12:56 AM Tom Lane wrote: >> That's ugly for sure, and it would only revert to the status >> quo ante. But I'm not seeing a better way right now. > It seems to me that this approach basically reverts the changes in > 8538519db. I'm afraid this would re-introduce the bug fixed by that > commit. Ugh, you're probably right. I'm taking a second look at the idea of regenerating the attr_needed values altogether. It doesn't look that bad, especially if we cheat to the extent of preserving the existing "relation 0" bits (that is, tlist and HAVING references). That's fine since we could never remove a rel that supplies Vars used in those places. Then we basically have to reconstruct surviving references from * EquivalenceClasses * joinclauses (available from the rels' joinlists) * lateral references (available from the rels' lateral_vars lists) * surviving placeholders (much like fix_placeholder_input_needed_levels) The need to again call pull_var_clause on these clauses is mildly annoying but I think it won't be that bad runtime-wise. Slightly more annoying is that a joinclause mentioning N relations would be visited N times. Perhaps we could de-duplicate using rinfo serial numbers? While I've not written any code yet, it seems like this route would lead to a bigger patch than we'd want to back-patch into v16 or v17. So that's not great; but on the other hand it took a year for anyone to notice this regression, so maybe we can get away with not fixing it in those branches. regards, tom lane