select * from t1, lateral (select * from t2 inner join t3 on t1.a = 1 inner join (t4 right join t5 on true) on true) as sub;
There is something wrong about postponing quals. We are supposed to postpone quals only from children to their parent nodes. But here in deconstruct_distribute we scan all the jointree nodes in depth-first traversal order and any quals postponed by left children may be checked against right children. If the right subtree is an outer join as in this example, the assertion would be triggered.
To fix this issue, I'm considering that we can add two types of info in JoinTreeItem for each jointree node, one is the jointree's children, and one is the list of quals that need to be postponed at this join level. Thus in deconstruct_distribute we can process the quals postponed by children.
Attach a draft patch (with no tests, no comments, no formats yet) to show what I'm thinking.