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);
}
}
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());
}
}
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());
}
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());
}
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));
}
Aggregations