use of org.voltdb.plannodes.UpdatePlanNode 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;
}
use of org.voltdb.plannodes.UpdatePlanNode 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);
}
Aggregations