Wrong results due to missing quals

2023-05-24 Thread Richard Guo
Testing with SQLancer reports a wrong results issue on master and I reduced it to the repro query below. create table t (a int, b int); explain (costs off) select * from t t1 left join (t t2 left join t t3 full join t t4 on false on false) left join t t5 on t2.a = t5.a on t2.b = 1;

Re: Wrong results due to missing quals

2023-05-24 Thread Tom Lane
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 ou

Re: Wrong results due to missing quals

2023-05-24 Thread Tom Lane
I wrote: > ... 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 a

Re: Wrong results due to missing quals

2023-05-24 Thread Richard Guo
On Thu, May 25, 2023 at 5:28 AM Tom Lane wrote: > I tried this and it seems to work all right: it fixes the example > you showed while not causing any new failures. (Doesn't address > the broken join-removal logic you showed in the other thread, > though.) > > While at it, I also changed make_re

Re: Wrong results due to missing quals

2023-05-25 Thread Tom Lane
Richard Guo writes: > The "incompatible_relids" idea is a stroke of genius. I reviewed the > patch and did not find any problem. So big +1 to the patch. Pushed, thanks for the report and the review. regards, tom lane