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