Search in sources :

Example 1 with DeletePlanNode

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

the class TestPlansDML method testBasicUpdateAndDelete.

public void testBasicUpdateAndDelete() {
    // select * with ON clause should return all columns from all tables
    List<AbstractPlanNode> pns;
    AbstractPlanNode pn;
    AbstractPlanNode node;
    pns = compileToFragments("UPDATE R1 SET C = 1 WHERE C = 0");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    node = pn.getChild(0).getChild(0);
    assertTrue(node instanceof ReceivePlanNode);
    pn = pns.get(1);
    node = pn.getChild(0);
    assertTrue(node instanceof UpdatePlanNode);
    pns = compileToFragments("DELETE FROM R1 WHERE C = 0");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    node = pn.getChild(0).getChild(0);
    assertTrue(node instanceof ReceivePlanNode);
    pn = pns.get(1);
    node = pn.getChild(0);
    assertTrue(node instanceof DeletePlanNode);
    pns = compileToFragments("INSERT INTO R1 VALUES (1, 2, 3)");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    node = pn.getChild(0).getChild(0);
    assertTrue(node instanceof ReceivePlanNode);
    pn = pns.get(1);
    node = pn.getChild(0);
    assertTrue(node instanceof InsertPlanNode);
    pns = compileToFragments("UPDATE P1 SET C = 1 WHERE C = 0");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    node = pn.getChild(0).getChild(0);
    assertTrue(node instanceof ReceivePlanNode);
    pn = pns.get(1);
    node = pn.getChild(0);
    assertTrue(node instanceof UpdatePlanNode);
    pns = compileToFragments("DELETE FROM P1 WHERE C = 0");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    node = pn.getChild(0).getChild(0);
    assertTrue(node instanceof ReceivePlanNode);
    pn = pns.get(1);
    node = pn.getChild(0);
    assertTrue(node instanceof DeletePlanNode);
    pns = compileToFragments("UPDATE P1 SET C = 1 WHERE A = 0");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    //n = pn.getChild(0);
    assertTrue(pn instanceof UpdatePlanNode);
    pns = compileToFragments("DELETE FROM P1 WHERE A = 0");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    //n = pn.getChild(0);
    assertTrue(pn instanceof DeletePlanNode);
    pns = compileToFragments("INSERT INTO P1 VALUES (1, 2)");
    pn = pns.get(0);
    System.out.println(pn.toExplainPlanString());
    //n = pn.getChild(0).getChild(0);
    assertTrue(pn instanceof InsertPlanNode);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) DeletePlanNode(org.voltdb.plannodes.DeletePlanNode) UpdatePlanNode(org.voltdb.plannodes.UpdatePlanNode) InsertPlanNode(org.voltdb.plannodes.InsertPlanNode) ReceivePlanNode(org.voltdb.plannodes.ReceivePlanNode)

Example 2 with DeletePlanNode

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

the class PlanAssembler method getNextDeletePlan.

private CompiledPlan getNextDeletePlan() {
    assert (m_subAssembler != null);
    // figure out which table we're deleting from
    assert (m_parsedDelete.m_tableList.size() == 1);
    Table targetTable = m_parsedDelete.m_tableList.get(0);
    AbstractPlanNode subSelectRoot = m_subAssembler.nextPlan();
    if (subSelectRoot == null) {
        return null;
    }
    // ENG-4909 Bug: currently disable NESTLOOPINDEX plan for IN
    if (disableNestedLoopIndexJoinForInComparison(subSelectRoot, m_parsedDelete)) {
        // simply jumps ahead to the next plan (if any).
        return getNextDeletePlan();
    }
    boolean isSinglePartitionPlan = m_partitioning.wasSpecifiedAsSingle() || m_partitioning.isInferredSingle();
    // generate the delete node with the right target table
    DeletePlanNode deleteNode = new DeletePlanNode();
    deleteNode.setTargetTableName(targetTable.getTypeName());
    assert (subSelectRoot instanceof AbstractScanPlanNode);
    // nodes and use a truncate delete node.
    if (deleteIsTruncate(m_parsedDelete, subSelectRoot)) {
        deleteNode.setTruncate(true);
    } else {
        // User may have specified an ORDER BY ... LIMIT clause
        if (m_parsedDelete.orderByColumns().size() > 0 && !isSinglePartitionPlan && !targetTable.getIsreplicated()) {
            throw new PlanningErrorException("DELETE statements affecting partitioned tables must " + "be able to execute on one partition " + "when ORDER BY and LIMIT or OFFSET clauses " + "are present.");
        }
        boolean needsOrderByNode = isOrderByNodeRequired(m_parsedDelete, subSelectRoot);
        AbstractExpression addressExpr = new TupleAddressExpression();
        NodeSchema proj_schema = new NodeSchema();
        // This planner-created column is magic.
        proj_schema.addColumn(AbstractParsedStmt.TEMP_TABLE_NAME, AbstractParsedStmt.TEMP_TABLE_NAME, "tuple_address", "tuple_address", addressExpr);
        if (needsOrderByNode) {
            // Projection will need to pass the sort keys to the order by node
            for (ParsedColInfo col : m_parsedDelete.orderByColumns()) {
                proj_schema.addColumn(col.asSchemaColumn());
            }
        }
        ProjectionPlanNode projectionNode = new ProjectionPlanNode(proj_schema);
        subSelectRoot.addInlinePlanNode(projectionNode);
        AbstractPlanNode root = subSelectRoot;
        if (needsOrderByNode) {
            OrderByPlanNode ob = buildOrderByPlanNode(m_parsedDelete.orderByColumns());
            ob.addAndLinkChild(root);
            root = ob;
        }
        if (m_parsedDelete.hasLimitOrOffset()) {
            assert (m_parsedDelete.orderByColumns().size() > 0);
            root.addInlinePlanNode(m_parsedDelete.limitPlanNode());
        }
        deleteNode.addAndLinkChild(root);
    }
    CompiledPlan plan = new CompiledPlan();
    plan.setReadOnly(false);
    // check non-determinism status
    // treat this as deterministic for reporting purposes:
    // delete statements produce just one row that is the
    // number of rows affected
    boolean orderIsDeterministic = true;
    boolean hasLimitOrOffset = m_parsedDelete.hasLimitOrOffset();
    // The delete statement cannot be inherently content non-deterministic.
    // So, the last parameter is always null.
    plan.statementGuaranteesDeterminism(hasLimitOrOffset, orderIsDeterministic, null);
    if (isSinglePartitionPlan) {
        plan.rootPlanGraph = deleteNode;
        return plan;
    }
    // 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();
    plan.rootPlanGraph = addCoordinatorToDMLNode(deleteNode, isReplicated);
    return plan;
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) TupleAddressExpression(org.voltdb.expressions.TupleAddressExpression) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) Table(org.voltdb.catalog.Table) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) DeletePlanNode(org.voltdb.plannodes.DeletePlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Aggregations

AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)2 DeletePlanNode (org.voltdb.plannodes.DeletePlanNode)2 Table (org.voltdb.catalog.Table)1 AbstractExpression (org.voltdb.expressions.AbstractExpression)1 TupleAddressExpression (org.voltdb.expressions.TupleAddressExpression)1 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)1 InsertPlanNode (org.voltdb.plannodes.InsertPlanNode)1 NodeSchema (org.voltdb.plannodes.NodeSchema)1 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)1 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)1 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)1 UpdatePlanNode (org.voltdb.plannodes.UpdatePlanNode)1