Search in sources :

Example 31 with AbstractScanPlanNode

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

the class PlanAssembler method getNextUpdatePlan.

private CompiledPlan getNextUpdatePlan() {
    assert (m_subAssembler != null);
    AbstractPlanNode subSelectRoot = m_subAssembler.nextPlan();
    if (subSelectRoot == null) {
        return null;
    }
    if (disableNestedLoopIndexJoinForInComparison(subSelectRoot, m_parsedUpdate)) {
        // simply jumps ahead to the next plan (if any).
        return getNextUpdatePlan();
    }
    UpdatePlanNode updateNode = new UpdatePlanNode();
    // It was not in Mike A's original branch.
    assert (m_parsedUpdate.m_tableList.size() == 1);
    Table targetTable = m_parsedUpdate.m_tableList.get(0);
    updateNode.setTargetTableName(targetTable.getTypeName());
    // set this to false until proven otherwise
    updateNode.setUpdateIndexes(false);
    TupleAddressExpression tae = new TupleAddressExpression();
    NodeSchema proj_schema = new NodeSchema();
    // This planner-generated column is magic.
    proj_schema.addColumn(AbstractParsedStmt.TEMP_TABLE_NAME, AbstractParsedStmt.TEMP_TABLE_NAME, "tuple_address", "tuple_address", tae);
    // get the set of columns affected by indexes
    Set<String> affectedColumns = getIndexedColumnSetForTable(targetTable);
    // to avoid any false schema/column matches with the actual table.
    for (Entry<Column, AbstractExpression> colEntry : m_parsedUpdate.columns.entrySet()) {
        Column col = colEntry.getKey();
        String colName = col.getTypeName();
        AbstractExpression expr = colEntry.getValue();
        expr.setInBytes(colEntry.getKey().getInbytes());
        proj_schema.addColumn(AbstractParsedStmt.TEMP_TABLE_NAME, AbstractParsedStmt.TEMP_TABLE_NAME, colName, colName, expr);
        // check if this column is an indexed column
        if (affectedColumns.contains(colName)) {
            updateNode.setUpdateIndexes(true);
        }
    }
    ProjectionPlanNode projectionNode = new ProjectionPlanNode(proj_schema);
    // in order to simply cull the columns from the persistent table.
    assert (subSelectRoot instanceof AbstractScanPlanNode);
    subSelectRoot.addInlinePlanNode(projectionNode);
    // connect the nodes to build the graph
    updateNode.addAndLinkChild(subSelectRoot);
    CompiledPlan retval = new CompiledPlan();
    retval.setReadOnly(false);
    if (targetTable.getIsreplicated()) {
        retval.replicatedTableDML = true;
    }
    //FIXME: This assumption was only safe when we didn't support updates
    // w/ possibly non-deterministic subqueries.
    // Is there some way to integrate a "subquery determinism" check here?
    // because we didn't support updates with limits, either.
    // Since the update cannot be inherently non-deterministic, there is
    // no message, and the last parameter is null.
    retval.statementGuaranteesDeterminism(false, true, null);
    if (m_partitioning.wasSpecifiedAsSingle() || m_partitioning.isInferredSingle()) {
        retval.rootPlanGraph = updateNode;
        return retval;
    }
    // Send the local result counts to the coordinator.
    // Add a compensating sum of modified tuple counts or a limit 1
    // AND a send on top of the union-like receive node.
    boolean isReplicated = targetTable.getIsreplicated();
    retval.rootPlanGraph = addCoordinatorToDMLNode(updateNode, isReplicated);
    return retval;
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) TupleAddressExpression(org.voltdb.expressions.TupleAddressExpression) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) Table(org.voltdb.catalog.Table) AbstractExpression(org.voltdb.expressions.AbstractExpression) Column(org.voltdb.catalog.Column) SchemaColumn(org.voltdb.plannodes.SchemaColumn) UpdatePlanNode(org.voltdb.plannodes.UpdatePlanNode) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 32 with AbstractScanPlanNode

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

the class TestPlansJoin method testJoinOrders.

public void testJoinOrders() {
    String query;
    AbstractPlanNode pn;
    AbstractPlanNode node;
    AbstractScanPlanNode sn;
    // R1 is an outer node - has one filter
    query = "SELECT * FROM R2 JOIN R1 USING (C) WHERE R1.A > 0";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN);
    sn = (AbstractScanPlanNode) node;
    assertEquals("R1", sn.getTargetTableName());
    // R2 is an outer node - R2.A = 3 filter is discounter more than R1.A > 0
    query = "SELECT * FROM R1 JOIN R2 USING (C) WHERE R1.A > 0 AND R2.A = 3";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN);
    sn = (AbstractScanPlanNode) node;
    assertEquals("R2", sn.getTargetTableName());
    // R2 is an outer node - R2.A = 3 filter is discounter more than two non-EQ filters
    query = "SELECT * FROM R1 JOIN R2 USING (C) WHERE R1.A > 0 AND R1.A < 3 AND R2.A = 3";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN);
    sn = (AbstractScanPlanNode) node;
    assertEquals("R2", sn.getTargetTableName());
    // R1 is an outer node - EQ + non-EQ overweight EQ
    query = "SELECT * FROM R1 JOIN R2 USING (C) WHERE R1.A = 0 AND R1.D < 3 AND R2.A = 3";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN);
    sn = (AbstractScanPlanNode) node;
    assertEquals("R1", sn.getTargetTableName());
    for (JoinOp joinOp : JoinOp.JOIN_OPS) {
        perJoinOpTestJoinOrders(joinOp);
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode)

Example 33 with AbstractScanPlanNode

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

the class TestPlansScalarSubQueries method testSelectParameterScalar.

public void testSelectParameterScalar() {
    AbstractPlanNode pn = compile("select r2.c, (select d from r1 where r1.c = ? ) scalar from r2");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractPlanNode proj = pn.getInlinePlanNode(PlanNodeType.PROJECTION);
    NodeSchema schema = proj.getOutputSchema();
    assertEquals(2, schema.size());
    SchemaColumn col = schema.getColumns().get(1);
    assertTrue(col != null);
    assertEquals("SCALAR", col.getColumnName());
    AbstractExpression colExpr = col.getExpression();
    assertEquals(ExpressionType.VALUE_SCALAR, colExpr.getExpressionType());
    assertTrue(colExpr.getLeft() instanceof AbstractSubqueryExpression);
    AbstractSubqueryExpression subqueryExpr = (AbstractSubqueryExpression) colExpr.getLeft();
    AbstractPlanNode subquery = subqueryExpr.getSubqueryNode();
    assertEquals(PlanNodeType.SEQSCAN, subquery.getPlanNodeType());
    AbstractExpression pred = ((SeqScanPlanNode) subquery).getPredicate();
    assertEquals(ExpressionType.VALUE_PARAMETER, pred.getRight().getExpressionType());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema)

Example 34 with AbstractScanPlanNode

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

the class TestPlansScalarSubQueries method testWhereGreaterScalar.

public void testWhereGreaterScalar() {
    AbstractPlanNode pn = compile("select r2.c from r2 where (select r1.a from r1) > r2.c;");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractExpression pred = ((AbstractScanPlanNode) pn).getPredicate();
    assertEquals(ExpressionType.COMPARE_LESSTHAN, pred.getExpressionType());
    assertEquals(ExpressionType.VALUE_TUPLE, 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 35 with AbstractScanPlanNode

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

the class TestPlansScalarSubQueries method testWhereParamScalar.

public void testWhereParamScalar() {
    AbstractPlanNode pn = compile("select r2.c from r2 where r2.c = (select r1.a from r1 where r1.a = r2.c);");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractExpression pred = ((AbstractScanPlanNode) pn).getPredicate();
    assertEquals(ExpressionType.COMPARE_EQUAL, pred.getExpressionType());
    assertEquals(ExpressionType.VALUE_TUPLE, pred.getLeft().getExpressionType());
    assertEquals(ExpressionType.SELECT_SUBQUERY, pred.getRight().getExpressionType());
    assertEquals(1, pred.getRight().getArgs().size());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression)

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