Search in sources :

Example 16 with NodeSchema

use of org.voltdb.plannodes.NodeSchema 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 17 with NodeSchema

use of org.voltdb.plannodes.NodeSchema 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 18 with NodeSchema

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

the class ParsedSelectStmt method processDistinct.

private VoltXMLElement processDistinct(VoltXMLElement displayElement, VoltXMLElement groupbyElement, VoltXMLElement havingElement) {
    // process DISTINCT clause
    if (!m_distinct) {
        return groupbyElement;
    }
    // DISTINCT without GROUP BY
    if (groupbyElement == null || groupbyElement.children.isEmpty()) {
        // Tricky: rewrote DISTINCT without GROUP BY with GROUP BY clause
        if (!m_hasAggregateExpression) {
            // attribute "id" is the only one that differs from a real
            // GROUP BY query
            groupbyElement = displayElement.duplicate();
        }
        // When it is table aggregate, it's also safe to drop DISTINCT.
        m_distinct = false;
        return groupbyElement;
    }
    // DISTINCT with GROUP BY
    m_distinctGroupByColumns = new ArrayList<>();
    m_distinctProjectSchema = new NodeSchema();
    // Iterate the Display columns
    for (ParsedColInfo col : m_displayColumns) {
        TupleValueExpression tve = new TupleValueExpression(col.tableName, col.tableAlias, col.columnName, col.alias, col.index, col.differentiator);
        tve.setTypeSizeAndInBytes(col.asSchemaColumn());
        ParsedColInfo pcol = new ParsedColInfo();
        pcol.tableName = col.tableName;
        pcol.tableAlias = col.tableAlias;
        pcol.columnName = col.columnName;
        pcol.alias = col.alias;
        pcol.expression = tve;
        m_distinctGroupByColumns.add(pcol);
        m_distinctProjectSchema.addColumn(col.tableName, col.tableAlias, col.columnName, col.alias, tve, col.differentiator);
    }
    return groupbyElement;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) NodeSchema(org.voltdb.plannodes.NodeSchema)

Example 19 with NodeSchema

use of org.voltdb.plannodes.NodeSchema 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 20 with NodeSchema

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

the class TestPlansScalarSubQueries method testSelectCorrelatedScalarWithGroupby.

public void testSelectCorrelatedScalarWithGroupby() {
    String sql = "select franchise_id, count(*) as stores_in_category_AdHoc, " + " (select category from store_types where type_id = stores.type_id) as store_category " + "from stores group by franchise_id, type_id;";
    AbstractPlanNode pn = compile(sql);
    pn = pn.getChild(0);
    assertTrue(pn instanceof ProjectionPlanNode);
    NodeSchema schema = pn.getOutputSchema();
    assertEquals(3, schema.size());
    SchemaColumn col = schema.getColumns().get(2);
    assertTrue(col != null);
    assertEquals("STORE_CATEGORY", col.getColumnName());
    assertTrue(col.getExpression() instanceof ScalarValueExpression);
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) ScalarValueExpression(org.voltdb.expressions.ScalarValueExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Aggregations

NodeSchema (org.voltdb.plannodes.NodeSchema)21 SchemaColumn (org.voltdb.plannodes.SchemaColumn)15 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)14 AbstractExpression (org.voltdb.expressions.AbstractExpression)13 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)9 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)8 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)8 Table (org.voltdb.catalog.Table)4 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)4 HashMap (java.util.HashMap)3 Column (org.voltdb.catalog.Column)3 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)3 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)3 SendPlanNode (org.voltdb.plannodes.SendPlanNode)3 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)3 Constraint (org.voltdb.catalog.Constraint)2 AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)2 ScalarValueExpression (org.voltdb.expressions.ScalarValueExpression)2 TupleAddressExpression (org.voltdb.expressions.TupleAddressExpression)2 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)2