Re: wrong query result due to wang plan - Mailing list pgsql-hackers

From Richard Guo
Subject Re: wrong query result due to wang plan
Date
Msg-id CAMbWs48rtnkepkgyvMzj3Cmuo9BcR3xNM2mpwdGHfO7AV-Azhg@mail.gmail.com
Whole thread Raw
In response to Re: wrong query result due to wang plan  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: wrong query result due to wang plan
List pgsql-hackers

On Mon, Feb 20, 2023 at 3:01 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
We still have to fix process_implied_equality though, and in that
context we do have all the SpecialJoinInfos, so the strip-the-outer-joins
fix seems to work.  See attached.
 
Yeah, process_implied_equality is also broken for variable-free clause.
I failed to notice that :-(.  I'm looking at the strip-the-outer-joins
codes.  At first I wondered why it only removes JOIN_LEFT outer joins
from below a JoinDomain's relids.  After a second thought I think it's
no problem here since only left outer joins have chance to commute with
joins outside the JoinDomain.

I'm thinking that maybe we can do the strip-the-outer-joins work only
when it's not the top JoinDomain.  When we are in the top JoinDomain, it
seems to me that it's safe to push the qual to the top of the tree.

-    /* eval at join domain level */
-    relids = bms_copy(qualscope);
+    /* eval at join domain's safe level */
+    if (!bms_equal(qualscope,
+                   ((JoinDomain *) linitial(root->join_domains))->jd_relids))
+        relids = get_join_domain_min_rels(root, qualscope);
+    else
+        relids = bms_copy(qualscope);

Thanks
Richard

pgsql-hackers by date:

Previous
From: e.indrupskaya@postgrespro.ru
Date:
Subject: Re: SQL/JSON revisited
Next
From: David Rowley
Date:
Subject: Re: Introduce list_reverse() to make lcons() usage less inefficient