@Test
public void shouldOptimizePlanForQueryUsingTableWithAliasAndOrderByClause() {

    node = optimize("SELECT X.c11 AS c1 FROM t1 AS X WHERE X.c11 = 'x' AND X.c12 = 'y' ORDER BY X.c11, X.c12 DESC");
    // Create the expected plan ...
    PlanNode sort = new PlanNode(Type.SORT, selector("X"));
    sort.setProperty(Property.SORT_ORDER_BY, orderings(ascending("X", "c11"), descending("X", "c12")));
    PlanNode leftAccess = new PlanNode(Type.ACCESS, sort, selector("X"));
    PlanNode leftProject = new PlanNode(Type.PROJECT, leftAccess, selector("X"));
    leftProject.setProperty(Property.PROJECT_COLUMNS, columns(column("X", "c11", "c1"), column("X", "c12")));
    PlanNode leftSelect1 = new PlanNode(Type.SELECT, leftProject, selector("X"));
    leftSelect1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("X"), "c11"),
                                                                     Operator.EQUAL_TO, new Literal("x")));
    PlanNode leftSelect2 = new PlanNode(Type.SELECT, leftSelect1, selector("X"));
    leftSelect2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("X"), "c12"),
                                                                     Operator.EQUAL_TO, new Literal("y")));
    PlanNode leftSource = new PlanNode(Type.SOURCE, leftSelect2, selector("X"));
    leftSource.setProperty(Property.SOURCE_NAME, selector("t1"));
    leftSource.setProperty(Property.SOURCE_ALIAS, selector("X"));
    leftSource.setProperty(Property.SOURCE_COLUMNS, context.getSchemata().getTable(selector("t1")).getColumns());
    // Compare the expected and actual plan ...
    assertPlanMatches(sort);
}