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 1q1q8I-0002ZE-SV for pgsql-hackers@arkaria.postgresql.org; Wed, 24 May 2023 15:10:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q1q8G-0000mu-7p for pgsql-hackers@arkaria.postgresql.org; Wed, 24 May 2023 15:10:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1q8F-0000mk-UT for pgsql-hackers@lists.postgresql.org; Wed, 24 May 2023 15:10:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q1q87-001tMn-Qs for pgsql-hackers@postgresql.org; Wed, 24 May 2023 15:10:31 +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 34OFALNG1132179; Wed, 24 May 2023 11:10:21 -0400 From: Tom Lane To: Richard Guo cc: PostgreSQL-development Subject: Re: Wrong results due to missing quals In-reply-to: References: Comments: In-reply-to Richard Guo message dated "Wed, 24 May 2023 19:19:16 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1132177.1684941021.1@sss.pgh.pa.us> Date: Wed, 24 May 2023 11:10:21 -0400 Message-ID: <1132178.1684941021@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > So the qual 't2.a = t5.a' is missing. Ugh. > I looked into it and found that both clones of this joinqual are > rejected by clause_is_computable_at, because their required_relids do > not include the outer join of t2/(t3/t4), and meanwhile include nullable > rels of this outer join. > I think the root cause is that, as Tom pointed out in [1], we're not > maintaining required_relids very accurately. In b9c755a2, we make > clause_is_computable_at test required_relids for clone clauses. I think > this is how this issue sneaks in. Yeah. I'm starting to think that b9c755a2 took the wrong approach. Really, required_relids is about making sure that a qual isn't evaluated "too low", before all necessary joins have been formed. But clause_is_computable_at is charged with making sure we don't evaluate it "too high", after some incompatible join has been formed. There's no really good reason to suppose that required_relids can serve both purposes, even if it were computed perfectly accurately (and what is perfect, anyway?). So right now I'm playing with the idea of reverting the change in clause_is_computable_at and seeing how else we can fix the previous bug. Don't have anything to show yet, but one thought is that maybe deconstruct_distribute_oj_quals needs to set up clause_relids for clone clauses differently. Another idea is that maybe we need another RestrictInfo field that's directly a set of OJ relids that this clause can't be applied above. That'd reduce clause_is_computable_at to basically a bms_intersect test which would be nice speed-wise. The space consumption could be annoying, but I'm thinking that we might only have to populate the field in clone clauses, which would alleviate that issue. regards, tom lane