Search in sources :

Example 1 with AbstractSubqueryExpression

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

the class NestLoopIndexPlanNode method generateOutputSchema.

@Override
public void generateOutputSchema(Database db) {
    // Important safety tip regarding this inlined
    // index scan and ITS inlined projection:
    // That projection is currently only used/usable as
    // a means to narrow the set of columns from the
    // indexscan's target table that make it into the
    // rest of the plan.  the expressions that are
    // given to the projection are currently not ever used
    IndexScanPlanNode inlineScan = (IndexScanPlanNode) m_inlineNodes.get(PlanNodeType.INDEXSCAN);
    assert (inlineScan != null);
    inlineScan.generateOutputSchema(db);
    assert (m_children.size() == 1);
    m_children.get(0).generateOutputSchema(db);
    // Join the schema together to form the output schema
    // The child subplan's output is the outer table
    // The inlined node's output is the inner table.
    //
    // Note that the inner table's contribution to the join_tuple doesn't include
    // all the columns from the inner table---just the ones needed as determined by
    // the inlined scan's own inlined projection, as described above.
    m_outputSchemaPreInlineAgg = m_children.get(0).getOutputSchema().join(inlineScan.getOutputSchema()).copyAndReplaceWithTVE();
    m_hasSignificantOutputSchema = true;
    generateRealOutputSchema(db);
    // Generate the output schema for subqueries
    Collection<AbstractExpression> subqueryExpressions = findAllSubquerySubexpressions();
    for (AbstractExpression subqueryExpression : subqueryExpressions) {
        assert (subqueryExpression instanceof AbstractSubqueryExpression);
        ((AbstractSubqueryExpression) subqueryExpression).generateOutputSchema(db);
    }
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression)

Example 2 with AbstractSubqueryExpression

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

the class PlanNodeTree method extractSubqueries.

/**
     * Traverse down the plan extracting all the subquery plans. The potential places where
     * the subqueries could be found are:
     *  - NestLoopInPlan
     *  - AbstractScanPlanNode predicate
     *  - AbstractJoinPlanNode predicates
     *  - IndexScan search keys and predicates
     *  - IndexJoin inline inner scan
     *  - Aggregate post-predicate(HAVING clause)
     *  - Projection, output schema (scalar subquery)
     * @param node
     * @throws Exception
     */
private void extractSubqueries(AbstractPlanNode node) throws Exception {
    assert (node != null);
    Collection<AbstractExpression> subexprs = node.findAllSubquerySubexpressions();
    for (AbstractExpression nextexpr : subexprs) {
        assert (nextexpr instanceof AbstractSubqueryExpression);
        AbstractSubqueryExpression subqueryExpr = (AbstractSubqueryExpression) nextexpr;
        int stmtId = subqueryExpr.getSubqueryId();
        List<AbstractPlanNode> planNodes = new ArrayList<AbstractPlanNode>();
        assert (!m_planNodesListMap.containsKey(stmtId));
        m_planNodesListMap.put(stmtId, planNodes);
        constructTree(planNodes, subqueryExpr.getSubqueryNode());
    }
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression) ArrayList(java.util.ArrayList)

Example 3 with AbstractSubqueryExpression

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

the class TestPlansInExistsSubQueries method testInAggregated.

public void testInAggregated() {
    AbstractPlanNode pn = compile("select a, sum(c) as sc1 from r1 where (a, c) in " + "( SELECT a, count(c) as sc2 " + "from  r1  GROUP BY a ORDER BY a DESC) GROUP BY A;");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractExpression e = ((AbstractScanPlanNode) pn).getPredicate();
    assertEquals(ExpressionType.OPERATOR_EXISTS, e.getExpressionType());
    AbstractSubqueryExpression subExpr = (AbstractSubqueryExpression) e.getLeft();
    AbstractPlanNode sn = subExpr.getSubqueryNode();
    // Added LIMIT 1
    assertTrue(sn instanceof LimitPlanNode);
    assertEquals(1, ((LimitPlanNode) sn).getLimit());
    sn = sn.getChild(0);
    assertTrue(sn instanceof SeqScanPlanNode);
    AggregatePlanNode aggNode = AggregatePlanNode.getInlineAggregationNode(sn);
    assertNotNull(aggNode.getPostPredicate());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression) LimitPlanNode(org.voltdb.plannodes.LimitPlanNode)

Example 4 with AbstractSubqueryExpression

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

the class TestPlansInExistsSubQueries method testInToExist.

public void testInToExist() {
    AbstractPlanNode pn = compile("select r2.c from r2 where r2.a in (select c from r1)");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractScanPlanNode spl = (AbstractScanPlanNode) pn;
    // Check param indexes
    AbstractExpression e = spl.getPredicate();
    assertEquals(ExpressionType.OPERATOR_EXISTS, e.getExpressionType());
    AbstractSubqueryExpression subExpr = (AbstractSubqueryExpression) e.getLeft();
    assertEquals(1, subExpr.getArgs().size());
    assertEquals(1, subExpr.getParameterIdxList().size());
    assertEquals(Integer.valueOf(0), subExpr.getParameterIdxList().get(0));
    AbstractExpression tve = subExpr.getArgs().get(0);
    assertTrue(tve instanceof TupleValueExpression);
    assertEquals("R2", ((TupleValueExpression) tve).getTableName());
    assertEquals("A", ((TupleValueExpression) tve).getColumnName());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression)

Example 5 with AbstractSubqueryExpression

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

the class TestPlansScalarSubQueries method testSelectCorrelatedScalar.

public void testSelectCorrelatedScalar() {
    AbstractPlanNode pn = compile("select r2.c, (select d from r1 where r1.c = r2.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();
    List<Integer> params = subqueryExpr.getParameterIdxList();
    assertEquals(1, params.size());
    assertEquals(new Integer(0), params.get(0));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) 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