List<String> varNames = new ArrayList<String>(subqueriesByVariableName.keySet());
Collections.sort(varNames);
Collections.reverse(varNames);
for (String varName : varNames) {
Subquery subquery = subqueriesByVariableName.get(varName);
// Plan out the subquery ...
PlanNode subqueryNode = createPlan(context, subquery.getQuery());
setSubqueryVariableName(subqueryNode, varName);
// Create a DEPENDENT_QUERY node, with the subquery on the LHS (so it is executed first) ...
PlanNode depQuery = new PlanNode(Type.DEPENDENT_QUERY);
depQuery.addChildren(subqueryNode, plan);