hi.
Here is the latest patch (v6),
I've made the following changes.
* disallow original Query->resultRelation participate in SJE.
for SELECT, nothing is changed. for UPDATE/DELETE/MERGE
we can do:
EXPLAIN (COSTS OFF)
UPDATE sj sq SET b = sq.b + sz.a FROM (select s1.* from sj s1 join sj
s2 on s1.a = s2.a) as sz
WHERE sz.a = sq.a;
here, only "(select s1.* from sj s1 join sj s2 on s1.a = s2.a)" can
apply to SJE.
but for now we cannot apply SJE to
EXPLAIN (COSTS OFF)
UPDATE sj sq SET b = sq.b + sz.a FROM sj as sz WHERE sz.a = sq.a;
so the EPQ abnormality issue[1] won't happen.
* add a new function: ChangeVarNodesExtended for
address concerns in [2]
* cosmetic refactor remove_self_join_rel, match_unique_clauses,
split_selfjoin_quals functions.
changing some "foreach" to "foreach_node"
* refactor comments above (remove_self_joins_one_group ->> match_unique_clauses)
I am not 100% sure they are correct.
[1] https://postgr.es/m/flat/CAPpHfduM6X82ExT0r9UzFLJ12wOYPvRw5vT2Htq0gAPBgHhKeQ%40mail.gmail.com
[2] https://postgr.es/m/flat/CAPpHfdvBddujLDhf7TQP-djeKoG5oyFBEoLSGRsjHfGrcNFkDg%40mail.gmail.com