Richard Guo <guofenglinux@gmail.com> writes: > On Sun, Apr 5, 2020 at 4:38 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: >> There is already something in equivclass.c that would almost do what >> we want here: exprs_known_equal() would tell us whether the partkeys >> can be found in the same eclass, without having to generate data >> structures along the way. The current implementation is not watertight >> because it doesn't check opclass semantics, but that consideration >> can be bolted on readily enough. So that leads me to something like >> the attached.
> I have some concern about we only check non-nullable partexprs. Is it > possible that two nullable partexprs come from the same EC? I tried to > give an example but failed.
Currently the EC infrastructure doesn't really cope with outer join equijoins. They are not treated as producing true equivalences, so I think that the case you're worried about can't occur (which is why I didn't code for it). I have hopes of being able to incorporate outer joins into the EC logic in a less squishy way in the future, by making the representation of Vars distinguish explicitly between value-before-outer-join and value-after-outer-join, after which we could make bulletproof assertions about what is equal to what, even with outer joins in the mix. If that works out it might produce a cleaner answer in this area too.
This is very appealing. Do we have ongoing discussions/threads about this idea?
(I did experiment with removing all the rest of have_partkey_equi_join() and having it *only* ask exprs_known_equal() about equivalences, which is more or less what I'm envisioning here. That caused some of the existing regression tests to fail, so there's something that the idea isn't covering. I didn't dig any further at the time, and in particular failed to check whether the problems were specifically about outer joins, which'd be unsurprising given the above.)
I think it would not work for outer joins if we only check exprs_known_equal() for equivalences. If the equi-join conditions involving pairs of matching partition keys are outer join quals mentioning nonnullable side rels, they would not exist in any EC according to the current EC infrastructure. So we still have to look