for (PlanNode join : plan.findAllAtOrBelow(Type.JOIN)) {
boolean swapChildren = false;
JoinCondition joinCondition = join.getProperty(Property.JOIN_CONDITION, JoinCondition.class);
if (joinCondition instanceof DescendantNodeJoinCondition) {
DescendantNodeJoinCondition condition = (DescendantNodeJoinCondition)joinCondition;
SelectorName ancestorSelector = condition.ancestorSelectorName();
// The ancestor needs to be on the left side of the join ...
swapChildren = !join.getFirstChild().getSelectors().contains(ancestorSelector);
} else if (joinCondition instanceof ChildNodeJoinCondition) {
ChildNodeJoinCondition condition = (ChildNodeJoinCondition)joinCondition;
SelectorName parentSelector = condition.parentSelectorName();