Search in sources :

Example 6 with SelectSubqueryExpression

use of org.voltdb.expressions.SelectSubqueryExpression in project voltdb by VoltDB.

the class PlanAssembler method getBestCostPlanForExpressionSubQueries.

/**
     * Generate best cost plans for each Subquery expression from the list
     * @param subqueryExprs - list of subquery expressions
     * @return true if a best plan was generated for each subquery, false otherwise
     */
private boolean getBestCostPlanForExpressionSubQueries(Set<AbstractExpression> subqueryExprs) {
    int nextPlanId = m_planSelector.m_planId;
    for (AbstractExpression expr : subqueryExprs) {
        assert (expr instanceof SelectSubqueryExpression);
        if (!(expr instanceof SelectSubqueryExpression)) {
            // DEAD CODE?
            continue;
        }
        SelectSubqueryExpression subqueryExpr = (SelectSubqueryExpression) expr;
        StmtSubqueryScan subqueryScan = subqueryExpr.getSubqueryScan();
        nextPlanId = planForParsedSubquery(subqueryScan, nextPlanId);
        CompiledPlan bestPlan = subqueryScan.getBestCostPlan();
        if (bestPlan == null) {
            return false;
        }
        subqueryExpr.setSubqueryNode(bestPlan.rootPlanGraph);
        // multiple times during the parent statement execution.
        if (bestPlan.rootPlanGraph.hasAnyNodeOfType(PlanNodeType.SEND)) {
            // fail the whole plan
            m_recentErrorMsg = IN_EXISTS_SCALAR_ERROR_MESSAGE;
            return false;
        }
    }
    // need to reset plan id for the entire SQL
    m_planSelector.m_planId = nextPlanId;
    return true;
}
Also used : StmtSubqueryScan(org.voltdb.planner.parseinfo.StmtSubqueryScan) AbstractExpression(org.voltdb.expressions.AbstractExpression) SelectSubqueryExpression(org.voltdb.expressions.SelectSubqueryExpression) Constraint(org.voltdb.catalog.Constraint)

Example 7 with SelectSubqueryExpression

use of org.voltdb.expressions.SelectSubqueryExpression in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testSelectCorrelatedScalarInGroupbyClause.

public void testSelectCorrelatedScalarInGroupbyClause() {
    String sql = "select franchise_id, count(*) as stores_in_category_AdHoc " + " from stores group by franchise_id, (select category from store_types where type_id = stores.type_id);";
    AbstractPlanNode pn = compile(sql);
    pn = pn.getChild(0);
    assertTrue(pn instanceof ProjectionPlanNode);
    NodeSchema schema = pn.getOutputSchema();
    assertEquals(2, schema.size());
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
    HashAggregatePlanNode aggNode = (HashAggregatePlanNode) pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
    assertEquals(2, aggNode.getGroupByExpressionsSize());
    AbstractExpression tveExpr = aggNode.getGroupByExpressions().get(0);
    assertTrue(tveExpr instanceof TupleValueExpression);
    AbstractExpression gbExpr = aggNode.getGroupByExpressions().get(1);
    assertTrue(gbExpr instanceof ScalarValueExpression);
    assertTrue(gbExpr.getLeft() instanceof SelectSubqueryExpression);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) ScalarValueExpression(org.voltdb.expressions.ScalarValueExpression) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) SelectSubqueryExpression(org.voltdb.expressions.SelectSubqueryExpression) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Aggregations

SelectSubqueryExpression (org.voltdb.expressions.SelectSubqueryExpression)7 AbstractExpression (org.voltdb.expressions.AbstractExpression)5 StmtSubqueryScan (org.voltdb.planner.parseinfo.StmtSubqueryScan)4 ComparisonExpression (org.voltdb.expressions.ComparisonExpression)2 ExpressionType (org.voltdb.types.ExpressionType)2 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)1 Constraint (org.voltdb.catalog.Constraint)1 ConjunctionExpression (org.voltdb.expressions.ConjunctionExpression)1 OperatorExpression (org.voltdb.expressions.OperatorExpression)1 ScalarValueExpression (org.voltdb.expressions.ScalarValueExpression)1 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)1 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)1 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)1 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)1 NodeSchema (org.voltdb.plannodes.NodeSchema)1 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)1