Search in sources :

Example 26 with OrderByPlanNode

use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.

the class InlineOrderByIntoMergeReceive method recursivelyApply.

@Override
protected AbstractPlanNode recursivelyApply(AbstractPlanNode planNode) {
    assert (planNode != null);
    // side effects.
    if (m_parsedStmt.topmostParentStatementIsDML()) {
        // Do not apply the optimization.
        return planNode;
    }
    Queue<AbstractPlanNode> children = new LinkedList<>();
    children.add(planNode);
    while (!children.isEmpty()) {
        AbstractPlanNode plan = children.remove();
        PlanNodeType nodeType = plan.getPlanNodeType();
        if (PlanNodeType.RECEIVE == nodeType) {
            // continue. We are after the coordinator ORDER BY or WINDOWFUNCTION node.
            return planNode;
        }
        if (PlanNodeType.ORDERBY == nodeType) {
            assert (plan instanceof OrderByPlanNode);
            AbstractPlanNode newPlan = applyOptimization((OrderByPlanNode) plan);
            //     the new plan node.
            if (newPlan != plan) {
                // Only one coordinator ORDER BY node is possible
                if (plan == planNode) {
                    return newPlan;
                } else {
                    // Do not apply the optimization.
                    return planNode;
                }
            }
        } else if (PlanNodeType.WINDOWFUNCTION == nodeType) {
            assert (plan instanceof WindowFunctionPlanNode);
            AbstractPlanNode newPlan = applyOptimization((WindowFunctionPlanNode) plan);
            // See above for why this is the way it is.
            if (newPlan != plan) {
                return newPlan;
            } else {
                return planNode;
            }
        }
        for (int i = 0; i < plan.getChildCount(); i++) {
            children.add(plan.getChild(i));
        }
    }
    // Do not apply the optimization.
    return planNode;
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) WindowFunctionPlanNode(org.voltdb.plannodes.WindowFunctionPlanNode) LinkedList(java.util.LinkedList)

Example 27 with OrderByPlanNode

use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method testEdgeComplexRelatedCases.

public void testEdgeComplexRelatedCases() {
    List<AbstractPlanNode> pns;
    pns = compileToFragments("select PKEY+A1 from T1 Order by PKEY+A1");
    AbstractPlanNode p = pns.get(0).getChild(0);
    assertTrue(p instanceof ProjectionPlanNode);
    assertTrue(p.getChild(0) instanceof OrderByPlanNode);
    assertTrue(p.getChild(0).getChild(0) instanceof ReceivePlanNode);
    p = pns.get(1).getChild(0);
    assertTrue(p instanceof AbstractScanPlanNode);
    // Useless order by clause.
    pns = compileToFragments("SELECT count(*)  FROM P1 order by PKEY");
    p = pns.get(0).getChild(0);
    assertTrue(p instanceof AggregatePlanNode);
    assertTrue(p.getChild(0) instanceof ReceivePlanNode);
    p = pns.get(1).getChild(0);
    assertTrue(p instanceof AbstractScanPlanNode);
    pns = compileToFragments("SELECT A1, count(*) as tag FROM P1 group by A1 order by tag, A1 limit 1");
    p = pns.get(0).getChild(0);
    // ENG-5066: now Limit is pushed under Projection
    // Limit is also inlined with Orderby node
    assertTrue(p instanceof ProjectionPlanNode);
    p = p.getChild(0);
    assertTrue(p instanceof OrderByPlanNode);
    assertNotNull(p.getInlinePlanNode(PlanNodeType.LIMIT));
    assertTrue(p.getChild(0) instanceof AggregatePlanNode);
    p = pns.get(1).getChild(0);
    // inline aggregate
    assertTrue(p instanceof AbstractScanPlanNode);
    assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
    pns = compileToFragments("SELECT F_D1, count(*) as tag FROM RF group by F_D1 order by tag");
    p = pns.get(0).getChild(0);
    //* enable to debug */ System.out.println("DEBUG: " + p.toExplainPlanString());
    assertTrue(p instanceof ProjectionPlanNode);
    p = p.getChild(0);
    assertTrue(p instanceof OrderByPlanNode);
    p = p.getChild(0);
    assertTrue(p instanceof IndexScanPlanNode);
    assertNotNull(p.getInlinePlanNode(PlanNodeType.AGGREGATE));
    pns = compileToFragments("SELECT F_D1, count(*) FROM RF group by F_D1 order by 2");
    p = pns.get(0).getChild(0);
    //* enable to debug */ System.out.println("DEBUG: " + p.toExplainPlanString());
    assertTrue(p instanceof ProjectionPlanNode);
    p = p.getChild(0);
    assertTrue(p instanceof OrderByPlanNode);
    p = p.getChild(0);
    assertTrue(p instanceof IndexScanPlanNode);
    assertNotNull(p.getInlinePlanNode(PlanNodeType.AGGREGATE));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ReceivePlanNode(org.voltdb.plannodes.ReceivePlanNode) AbstractReceivePlanNode(org.voltdb.plannodes.AbstractReceivePlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 28 with OrderByPlanNode

use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method checkHasComplexAgg.

private void checkHasComplexAgg(List<AbstractPlanNode> pns, boolean projectPushdown) {
    assertTrue(pns.size() > 0);
    boolean isDistributed = pns.size() > 1 ? true : false;
    if (projectPushdown) {
        assertTrue(isDistributed);
    }
    AbstractPlanNode p = pns.get(0).getChild(0);
    if (p instanceof LimitPlanNode) {
        p = p.getChild(0);
    }
    if (p instanceof OrderByPlanNode) {
        p = p.getChild(0);
    }
    if (!projectPushdown) {
        assertTrue(p instanceof ProjectionPlanNode);
    }
    while (p.getChildCount() > 0) {
        p = p.getChild(0);
        assertFalse(p instanceof ProjectionPlanNode);
    }
    if (isDistributed) {
        p = pns.get(1).getChild(0);
        int projectCount = 0;
        while (p.getChildCount() > 0) {
            p = p.getChild(0);
            if (p instanceof ProjectionPlanNode) {
                projectCount++;
                assertTrue(projectPushdown);
            }
        }
        if (projectPushdown) {
            assertEquals(1, projectCount);
        }
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) LimitPlanNode(org.voltdb.plannodes.LimitPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 29 with OrderByPlanNode

use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method testComplexAggwithDistinct.

public void testComplexAggwithDistinct() {
    List<AbstractPlanNode> pns;
    pns = compileToFragments("SELECT A1, sum(A1), sum(distinct A1)+11 FROM P1 GROUP BY A1 ORDER BY A1");
    checkHasComplexAgg(pns);
    // Test aggregation node not push down with distinct
    AbstractPlanNode p = pns.get(0).getChild(0);
    assertTrue(p instanceof OrderByPlanNode);
    assertTrue(p.getChild(0) instanceof ProjectionPlanNode);
    assertTrue(p.getChild(0).getChild(0) instanceof AggregatePlanNode);
    p = pns.get(1).getChild(0);
    assertTrue(p instanceof AbstractScanPlanNode);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 30 with OrderByPlanNode

use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.

the class TestIndexReverseScan method checkForwardScan.

private void checkForwardScan(String indexName, IndexLookupType lookupType, int searchKeys, int endKeys, int predicates, SortDirectionType sortType, boolean needOrderby) {
    AbstractPlanNode pn = compile(sql);
    System.out.println(pn.toExplainPlanString());
    assertTrue(pn instanceof SendPlanNode);
    pn = pn.getChild(0);
    if (needOrderby) {
        assertTrue(pn instanceof ProjectionPlanNode);
        pn = pn.getChild(0);
        assertTrue(pn instanceof OrderByPlanNode);
        pn = pn.getChild(0);
    }
    assertTrue(pn instanceof IndexScanPlanNode);
    IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
    assertTrue(ispn.getTargetIndexName().contains(indexName));
    assertEquals(lookupType, ispn.getLookupType());
    assertEquals(searchKeys, ispn.getSearchKeyExpressions().size());
    assertEquals(endKeys, ExpressionUtil.uncombinePredicate(ispn.getEndExpression()).size());
    assertEquals(predicates, ExpressionUtil.uncombinePredicate(ispn.getPredicate()).size());
    assertEquals(0, ExpressionUtil.uncombinePredicate(ispn.getInitialExpression()).size());
    assertEquals(sortType, ispn.getSortDirection());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) SendPlanNode(org.voltdb.plannodes.SendPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Aggregations

OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)32 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)29 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)25 SendPlanNode (org.voltdb.plannodes.SendPlanNode)9 AbstractExpression (org.voltdb.expressions.AbstractExpression)8 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)8 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)8 MergeReceivePlanNode (org.voltdb.plannodes.MergeReceivePlanNode)8 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)6 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)6 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)6 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)5 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)5 WindowFunctionPlanNode (org.voltdb.plannodes.WindowFunctionPlanNode)5 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)4 SchemaColumn (org.voltdb.plannodes.SchemaColumn)4 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)3 NodeSchema (org.voltdb.plannodes.NodeSchema)3 UnionPlanNode (org.voltdb.plannodes.UnionPlanNode)2 SortDirectionType (org.voltdb.types.SortDirectionType)2