Search in sources :

Example 11 with AbstractSubqueryExpression

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

the class TestPlansInExistsSubQueries method testInToExistsComplex.

public void testInToExistsComplex() {
    AbstractPlanNode pn = compile("select * from R1 where (A,C) in (select 2, C from r2 where r2.c > r1.c group by c)");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractScanPlanNode spn = (AbstractScanPlanNode) pn;
    AbstractExpression e = spn.getPredicate();
    assertEquals(ExpressionType.OPERATOR_EXISTS, e.getExpressionType());
    AbstractSubqueryExpression subExpr = (AbstractSubqueryExpression) e.getLeft();
    assertEquals(3, subExpr.getArgs().size());
    assertEquals(3, subExpr.getParameterIdxList().size());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression)

Example 12 with AbstractSubqueryExpression

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

the class TestPlansInExistsSubQueries method verifyTrivialSchemaLimitOffset.

private void verifyTrivialSchemaLimitOffset(AbstractExpression exists, int limit, int offset) {
    assertNotNull(exists);
    assertEquals(ExpressionType.OPERATOR_EXISTS, exists.getExpressionType());
    AbstractSubqueryExpression se = (AbstractSubqueryExpression) exists.getLeft();
    AbstractPlanNode pn = se.getSubqueryNode();
    assertTrue(pn instanceof SeqScanPlanNode);
    AbstractPlanNode inline = pn.getInlinePlanNode(PlanNodeType.PROJECTION);
    assertNotNull(inline);
    inline = pn.getInlinePlanNode(PlanNodeType.LIMIT);
    assertNotNull(inline);
    assertEquals(limit, ((LimitPlanNode) inline).getLimit());
    assertEquals(offset, ((LimitPlanNode) inline).getOffset());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression)

Example 13 with AbstractSubqueryExpression

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

the class AbstractJoinPlanNode method generateOutputSchema.

@Override
public void generateOutputSchema(Database db) {
    // Assert and provide functionality for generic join
    assert (m_children.size() == 2);
    for (AbstractPlanNode child : m_children) {
        child.generateOutputSchema(db);
    }
    // Generate the output schema for subqueries
    Collection<AbstractExpression> subqueryExpressions = findAllSubquerySubexpressions();
    for (AbstractExpression expr : subqueryExpressions) {
        ((AbstractSubqueryExpression) expr).generateOutputSchema(db);
    }
    // Join the schema together to form the output schema
    m_outputSchemaPreInlineAgg = m_children.get(0).getOutputSchema().join(m_children.get(1).getOutputSchema()).copyAndReplaceWithTVE();
    m_hasSignificantOutputSchema = true;
    generateRealOutputSchema(db);
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression)

Example 14 with AbstractSubqueryExpression

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

the class AbstractPlanNode method overrideId.

public int overrideId(int newId) {
    m_id = newId++;
    // Override subqueries ids
    Collection<AbstractExpression> subqueries = findAllSubquerySubexpressions();
    for (AbstractExpression expr : subqueries) {
        assert (expr instanceof AbstractSubqueryExpression);
        AbstractSubqueryExpression subquery = (AbstractSubqueryExpression) expr;
        // overrideSubqueryNodeIds(newId) will get an NPE if the subquery
        // has not been planned, presumably the effect of hitting a bug
        // earlier in the planner. If that happens again, it MAY be useful
        // to preempt those cases here and single-step through a replay of
        // findAllSubquerySubexpressions. Determining where in the parent
        // plan this subquery expression was found MAY provide a clue
        // as to why the subquery was not planned. It has helped before.
        //REDO to debug*/ if (subquery instanceof SelectSubqueryExpression) {
        //REDO to debug*/     CompiledPlan subqueryPlan = ((SelectSubqueryExpression)subquery)
        //REDO to debug*/             .getSubqueryScan().getBestCostPlan();
        //REDO to debug*/     if (subqueryPlan == null) {
        //REDO to debug*/         findAllSubquerySubexpressions();
        //REDO to debug*/     }
        //REDO to debug*/ }
        newId = subquery.overrideSubqueryNodeIds(newId);
    }
    return newId;
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression)

Example 15 with AbstractSubqueryExpression

use of org.voltdb.expressions.AbstractSubqueryExpression 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)

Aggregations

AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)18 AbstractExpression (org.voltdb.expressions.AbstractExpression)16 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)10 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)7 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)4 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)3 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)2 NodeSchema (org.voltdb.plannodes.NodeSchema)2 SchemaColumn (org.voltdb.plannodes.SchemaColumn)2 ArrayList (java.util.ArrayList)1 JSONObject (org.json_voltpatches.JSONObject)1 Index (org.voltdb.catalog.Index)1 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)1 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)1 IndexSortablePlanNode (org.voltdb.plannodes.IndexSortablePlanNode)1 IndexUseForOrderBy (org.voltdb.plannodes.IndexUseForOrderBy)1 MaterializedScanPlanNode (org.voltdb.plannodes.MaterializedScanPlanNode)1