Search in sources :

Example 21 with AbstractScanPlanNode

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

the class TestPlansScalarSubQueries method testWhereGreaterRow.

public void testWhereGreaterRow() {
    AbstractPlanNode pn = compile("select r5.c from r5 where (a,c) > (select r1.a, r1.c from r1);");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractExpression pred = ((AbstractScanPlanNode) pn).getPredicate();
    assertEquals(ExpressionType.COMPARE_GREATERTHAN, pred.getExpressionType());
    assertEquals(ExpressionType.ROW_SUBQUERY, pred.getLeft().getExpressionType());
    assertEquals(ExpressionType.SELECT_SUBQUERY, pred.getRight().getExpressionType());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression)

Example 22 with AbstractScanPlanNode

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

the class TestPushDownAggregates method checkPushedDown.

private void checkPushedDown(List<AbstractPlanNode> pn, boolean isAggInlined, ExpressionType[] aggTypes, ExpressionType[] pushDownTypes, boolean hasProjectionNode) {
    // Aggregate push down check has to run on two fragments
    assertTrue(pn.size() == 2);
    AbstractPlanNode p = pn.get(0).getChild(0);
    ;
    if (hasProjectionNode) {
        // Complex aggregation or optimized AVG
        assertTrue(p instanceof ProjectionPlanNode);
        p = p.getChild(0);
    }
    assertTrue(p instanceof AggregatePlanNode);
    String fragmentString = p.toJSONString();
    ExpressionType[] topTypes = (pushDownTypes != null) ? pushDownTypes : aggTypes;
    for (ExpressionType type : topTypes) {
        assertTrue(fragmentString.contains("\"AGGREGATE_TYPE\":\"" + type.toString() + "\""));
    }
    // Check the pushed down aggregation
    p = pn.get(1).getChild(0);
    if (pushDownTypes == null) {
        assertTrue(p instanceof AbstractScanPlanNode);
        return;
    }
    if (isAggInlined) {
        // See ENG-6131
        if (p instanceof TableCountPlanNode) {
            return;
        }
        assertTrue(p instanceof AbstractScanPlanNode);
        assertTrue(p.getInlinePlanNode(PlanNodeType.AGGREGATE) != null || p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE) != null);
        if (p.getInlinePlanNode(PlanNodeType.AGGREGATE) != null) {
            p = p.getInlinePlanNode(PlanNodeType.AGGREGATE);
        } else {
            p = p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
        }
    } else {
        assertTrue(p instanceof AggregatePlanNode);
    }
    fragmentString = p.toJSONString();
    for (ExpressionType type : aggTypes) {
        assertTrue(fragmentString.contains("\"AGGREGATE_TYPE\":\"" + type.toString() + "\""));
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) ExpressionType(org.voltdb.types.ExpressionType) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode) TableCountPlanNode(org.voltdb.plannodes.TableCountPlanNode)

Example 23 with AbstractScanPlanNode

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

the class TestPushDownAggregates method testAggregatesOnDistinctPKey.

//ENG-4980
public void testAggregatesOnDistinctPKey() {
    List<AbstractPlanNode> pn = compileToFragments("SELECT count(distinct PKEY), sum(distinct PKEY), min(distinct PKEY), max(distinct PKEY), avg(distinct PKEY)" + " FROM T1;");
    for (AbstractPlanNode apn : pn) {
        System.out.println(apn.toExplainPlanString());
    }
    checkPushedDown(pn, true, new ExpressionType[] { ExpressionType.AGGREGATE_COUNT, ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_MIN, ExpressionType.AGGREGATE_MAX, ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_COUNT }, new ExpressionType[] { ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_MIN, ExpressionType.AGGREGATE_MAX, ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_SUM }, true);
    // Test count(distinct pkey) with other compatible aggs like non-distinct aggs of other columns.
    pn = compileToFragments("SELECT count(distinct PKEY), count(A1), min(distinct PKEY), max(distinct A1), sum(A1)" + " FROM T1;");
    for (AbstractPlanNode apn : pn) {
        System.out.println(apn.toExplainPlanString());
    }
    checkPushedDown(pn, true, new ExpressionType[] { ExpressionType.AGGREGATE_COUNT, ExpressionType.AGGREGATE_COUNT, ExpressionType.AGGREGATE_MIN, ExpressionType.AGGREGATE_MAX, ExpressionType.AGGREGATE_SUM }, new ExpressionType[] { ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_SUM, ExpressionType.AGGREGATE_MIN, ExpressionType.AGGREGATE_MAX, ExpressionType.AGGREGATE_SUM });
    // Negative test case: count(distinct pkey) and count(distinct other) to show that
    // it only takes one other non-trivial distinct on another column to disable the pushdown.
    pn = compileToFragments("SELECT count(distinct PKEY), count(distinct A1) FROM T1;");
    assertTrue(pn.size() == 2);
    assertTrue(pn.get(1).getChild(0) instanceof AbstractScanPlanNode);
    AbstractScanPlanNode asp = (AbstractScanPlanNode) pn.get(1).getChild(0);
    assertTrue(asp.getInlinePlanNode(PlanNodeType.AGGREGATE) == null);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode)

Example 24 with AbstractScanPlanNode

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

the class MaterializedViewFixInfo method processScanNodeWithReAggNode.

/**
     * Find the scan node on MV table, replace it with reAggNode for join query.
     * This scan node can not be in-lined, so it should be as a child of a join node.
     * @param node
     */
public boolean processScanNodeWithReAggNode(AbstractPlanNode node, AbstractPlanNode reAggNode) {
    // MV table scan node can not be in in-lined nodes.
    for (int i = 0; i < node.getChildCount(); i++) {
        AbstractPlanNode child = node.getChild(i);
        if (child instanceof AbstractScanPlanNode) {
            AbstractScanPlanNode scanNode = (AbstractScanPlanNode) child;
            if (!scanNode.getTargetTableName().equals(getMVTableName())) {
                continue;
            }
            if (reAggNode != null) {
                // Join query case.
                node.setAndLinkChild(i, reAggNode);
            }
            // Process scan node.
            // Set up the scan plan node's scan columns. Add in-line projection node for scan node.
            scanNode.addInlinePlanNode(m_scanInlinedProjectionNode);
            m_scanNode = scanNode;
            return true;
        } else {
            boolean replaced = processScanNodeWithReAggNode(child, reAggNode);
            if (replaced) {
                return true;
            }
        }
    }
    return false;
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode)

Example 25 with AbstractScanPlanNode

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

the class testPlannerTester method testGetScanNodeList.

/// Unit test some of the techniques used by plannerTester
public void testGetScanNodeList() {
    AbstractPlanNode pn = null;
    pn = compile("select * from l where lname=? and b=0 order by id asc limit ?;");
    ArrayList<AbstractScanPlanNode> collected = pn.getScanNodeList();
    System.out.println(collected);
    System.out.println(collected.size());
    for (AbstractPlanNode n : collected) {
        System.out.println(n.toExplainPlanString());
    }
    assertTrue(collected.size() == 1);
    JSONObject j;
    try {
        j = new JSONObject(collected.get(0).toJSONString());
        System.out.println(j.getString("PLAN_NODE_TYPE"));
        assertTrue(j.getString("PLAN_NODE_TYPE").equalsIgnoreCase("INDEXSCAN"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException)

Aggregations

AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)48 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)46 AbstractExpression (org.voltdb.expressions.AbstractExpression)21 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)15 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)14 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)14 NodeSchema (org.voltdb.plannodes.NodeSchema)8 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)8 AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)7 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)7 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)6 SchemaColumn (org.voltdb.plannodes.SchemaColumn)6 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)5 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)4 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)4 ArrayList (java.util.ArrayList)3 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)3 AbstractJoinPlanNode (org.voltdb.plannodes.AbstractJoinPlanNode)3 PlanNodeType (org.voltdb.types.PlanNodeType)3 JSONException (org.json_voltpatches.JSONException)2