Search in sources :

Example 31 with ProjectionPlanNode

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

the class TestWindowedFunctions method validateQueryWithSubquery.

/**
     * Validate that each similar windowed query in testRankWithSubqueries
     * produces a similar plan
     * @param windowedQuery a variant of a test query of a known basic format
     **/
private void validateQueryWithSubquery(String windowedQuery, boolean waiveAliasMatch) {
    AbstractPlanNode node = compile(windowedQuery);
    // Dissect the plan.
    assertTrue(node instanceof SendPlanNode);
    AbstractPlanNode projectionPlanNode = node.getChild(0);
    assertTrue(projectionPlanNode instanceof ProjectionPlanNode);
    AbstractPlanNode partitionByPlanNode = projectionPlanNode.getChild(0);
    assertTrue(partitionByPlanNode instanceof WindowFunctionPlanNode);
    AbstractPlanNode orderByPlanNode = partitionByPlanNode.getChild(0);
    assertTrue(orderByPlanNode instanceof OrderByPlanNode);
    NodeSchema input_schema = orderByPlanNode.getOutputSchema();
    AbstractPlanNode scanNode = orderByPlanNode.getChild(0);
    assertTrue(scanNode instanceof NestLoopPlanNode);
    NodeSchema schema = partitionByPlanNode.getOutputSchema();
    SchemaColumn column = schema.getColumns().get(0);
    assertEquals("ARANK", column.getColumnAlias());
    validateTVEs(input_schema, (WindowFunctionPlanNode) partitionByPlanNode, waiveAliasMatch);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) SendPlanNode(org.voltdb.plannodes.SendPlanNode) WindowFunctionPlanNode(org.voltdb.plannodes.WindowFunctionPlanNode) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NestLoopPlanNode(org.voltdb.plannodes.NestLoopPlanNode) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 32 with ProjectionPlanNode

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

the class TestUnion method testSubqueryUnionWithParamENG7783.

public void testSubqueryUnionWithParamENG7783() {
    AbstractPlanNode pn = compile("SELECT B, ABS( B - ? ) AS distance FROM ( " + "( SELECT B FROM T2 WHERE B >=? ORDER BY B LIMIT ? " + ") UNION ALL ( " + "SELECT B FROM T2 WHERE B < ? ORDER BY B DESC LIMIT ? ) " + ") AS n ORDER BY distance LIMIT ?;");
    assertTrue(pn.getChild(0) instanceof ProjectionPlanNode);
    assertTrue(pn.getChild(0).getChild(0) instanceof OrderByPlanNode);
    assertTrue(pn.getChild(0).getChild(0).getChild(0) instanceof SeqScanPlanNode);
    assertTrue(pn.getChild(0).getChild(0).getChild(0).getChild(0) instanceof UnionPlanNode);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) UnionPlanNode(org.voltdb.plannodes.UnionPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 33 with ProjectionPlanNode

use of org.voltdb.plannodes.ProjectionPlanNode 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)

Example 34 with ProjectionPlanNode

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

the class PlanAssembler method addProjection.

/**
     * Given a relatively complete plan-sub-graph, apply a trivial projection
     * (filter) to it. If the root node can embed the projection do so. If not,
     * add a new projection node.
     *
     * @param rootNode
     *            The root of the plan-sub-graph to add the projection to.
     * @return The new root of the plan-sub-graph (might be the same as the
     *         input).
     */
private AbstractPlanNode addProjection(AbstractPlanNode rootNode) {
    assert (m_parsedSelect != null);
    assert (m_parsedSelect.m_displayColumns != null);
    // Build the output schema for the projection based on the display columns
    NodeSchema proj_schema = m_parsedSelect.getFinalProjectionSchema();
    for (SchemaColumn col : proj_schema.getColumns()) {
        // Adjust the differentiator fields of TVEs, since they need to
        // reflect the inlined projection node in scan nodes.
        AbstractExpression colExpr = col.getExpression();
        Collection<TupleValueExpression> allTves = ExpressionUtil.getTupleValueExpressions(colExpr);
        for (TupleValueExpression tve : allTves) {
            if (!tve.needsDifferentiation()) {
                // so we just ignore it here.
                continue;
            }
            rootNode.adjustDifferentiatorField(tve);
        }
    }
    ProjectionPlanNode projectionNode = new ProjectionPlanNode();
    projectionNode.setOutputSchemaWithoutClone(proj_schema);
    // projection node inline.
    if (rootNode instanceof AbstractScanPlanNode) {
        rootNode.addInlinePlanNode(projectionNode);
        return rootNode;
    }
    projectionNode.addAndLinkChild(rootNode);
    return projectionNode;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 35 with ProjectionPlanNode

use of org.voltdb.plannodes.ProjectionPlanNode 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)

Aggregations

ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)51 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)48 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)25 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)17 SendPlanNode (org.voltdb.plannodes.SendPlanNode)16 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)14 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)14 MergeReceivePlanNode (org.voltdb.plannodes.MergeReceivePlanNode)13 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)13 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)13 AbstractExpression (org.voltdb.expressions.AbstractExpression)10 NodeSchema (org.voltdb.plannodes.NodeSchema)9 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)9 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)8 SchemaColumn (org.voltdb.plannodes.SchemaColumn)7 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)5 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)5 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)4 NestLoopIndexPlanNode (org.voltdb.plannodes.NestLoopIndexPlanNode)4 Table (org.voltdb.catalog.Table)3