public PlanNode execute( final QueryContext context,
PlanNode plan,
LinkedList<OptimizerRule> ruleStack ) {
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);