use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.
the class InlineOrderByIntoMergeReceive method recursivelyApply.
@Override
protected AbstractPlanNode recursivelyApply(AbstractPlanNode planNode) {
assert (planNode != null);
// side effects.
if (m_parsedStmt.topmostParentStatementIsDML()) {
// Do not apply the optimization.
return planNode;
}
Queue<AbstractPlanNode> children = new LinkedList<>();
children.add(planNode);
while (!children.isEmpty()) {
AbstractPlanNode plan = children.remove();
PlanNodeType nodeType = plan.getPlanNodeType();
if (PlanNodeType.RECEIVE == nodeType) {
// continue. We are after the coordinator ORDER BY or WINDOWFUNCTION node.
return planNode;
}
if (PlanNodeType.ORDERBY == nodeType) {
assert (plan instanceof OrderByPlanNode);
AbstractPlanNode newPlan = applyOptimization((OrderByPlanNode) plan);
// the new plan node.
if (newPlan != plan) {
// Only one coordinator ORDER BY node is possible
if (plan == planNode) {
return newPlan;
} else {
// Do not apply the optimization.
return planNode;
}
}
} else if (PlanNodeType.WINDOWFUNCTION == nodeType) {
assert (plan instanceof WindowFunctionPlanNode);
AbstractPlanNode newPlan = applyOptimization((WindowFunctionPlanNode) plan);
// See above for why this is the way it is.
if (newPlan != plan) {
return newPlan;
} else {
return planNode;
}
}
for (int i = 0; i < plan.getChildCount(); i++) {
children.add(plan.getChild(i));
}
}
// Do not apply the optimization.
return planNode;
}
use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method testEdgeComplexRelatedCases.
public void testEdgeComplexRelatedCases() {
List<AbstractPlanNode> pns;
pns = compileToFragments("select PKEY+A1 from T1 Order by PKEY+A1");
AbstractPlanNode p = pns.get(0).getChild(0);
assertTrue(p instanceof ProjectionPlanNode);
assertTrue(p.getChild(0) instanceof OrderByPlanNode);
assertTrue(p.getChild(0).getChild(0) instanceof ReceivePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
// Useless order by clause.
pns = compileToFragments("SELECT count(*) FROM P1 order by PKEY");
p = pns.get(0).getChild(0);
assertTrue(p instanceof AggregatePlanNode);
assertTrue(p.getChild(0) instanceof ReceivePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
pns = compileToFragments("SELECT A1, count(*) as tag FROM P1 group by A1 order by tag, A1 limit 1");
p = pns.get(0).getChild(0);
// ENG-5066: now Limit is pushed under Projection
// Limit is also inlined with Orderby node
assertTrue(p instanceof ProjectionPlanNode);
p = p.getChild(0);
assertTrue(p instanceof OrderByPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.LIMIT));
assertTrue(p.getChild(0) instanceof AggregatePlanNode);
p = pns.get(1).getChild(0);
// inline aggregate
assertTrue(p instanceof AbstractScanPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
pns = compileToFragments("SELECT F_D1, count(*) as tag FROM RF group by F_D1 order by tag");
p = pns.get(0).getChild(0);
//* enable to debug */ System.out.println("DEBUG: " + p.toExplainPlanString());
assertTrue(p instanceof ProjectionPlanNode);
p = p.getChild(0);
assertTrue(p instanceof OrderByPlanNode);
p = p.getChild(0);
assertTrue(p instanceof IndexScanPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.AGGREGATE));
pns = compileToFragments("SELECT F_D1, count(*) FROM RF group by F_D1 order by 2");
p = pns.get(0).getChild(0);
//* enable to debug */ System.out.println("DEBUG: " + p.toExplainPlanString());
assertTrue(p instanceof ProjectionPlanNode);
p = p.getChild(0);
assertTrue(p instanceof OrderByPlanNode);
p = p.getChild(0);
assertTrue(p instanceof IndexScanPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.AGGREGATE));
}
use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method checkHasComplexAgg.
private void checkHasComplexAgg(List<AbstractPlanNode> pns, boolean projectPushdown) {
assertTrue(pns.size() > 0);
boolean isDistributed = pns.size() > 1 ? true : false;
if (projectPushdown) {
assertTrue(isDistributed);
}
AbstractPlanNode p = pns.get(0).getChild(0);
if (p instanceof LimitPlanNode) {
p = p.getChild(0);
}
if (p instanceof OrderByPlanNode) {
p = p.getChild(0);
}
if (!projectPushdown) {
assertTrue(p instanceof ProjectionPlanNode);
}
while (p.getChildCount() > 0) {
p = p.getChild(0);
assertFalse(p instanceof ProjectionPlanNode);
}
if (isDistributed) {
p = pns.get(1).getChild(0);
int projectCount = 0;
while (p.getChildCount() > 0) {
p = p.getChild(0);
if (p instanceof ProjectionPlanNode) {
projectCount++;
assertTrue(projectPushdown);
}
}
if (projectPushdown) {
assertEquals(1, projectCount);
}
}
}
use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method testComplexAggwithDistinct.
public void testComplexAggwithDistinct() {
List<AbstractPlanNode> pns;
pns = compileToFragments("SELECT A1, sum(A1), sum(distinct A1)+11 FROM P1 GROUP BY A1 ORDER BY A1");
checkHasComplexAgg(pns);
// Test aggregation node not push down with distinct
AbstractPlanNode p = pns.get(0).getChild(0);
assertTrue(p instanceof OrderByPlanNode);
assertTrue(p.getChild(0) instanceof ProjectionPlanNode);
assertTrue(p.getChild(0).getChild(0) instanceof AggregatePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
}
use of org.voltdb.plannodes.OrderByPlanNode in project voltdb by VoltDB.
the class TestIndexReverseScan method checkForwardScan.
private void checkForwardScan(String indexName, IndexLookupType lookupType, int searchKeys, int endKeys, int predicates, SortDirectionType sortType, boolean needOrderby) {
AbstractPlanNode pn = compile(sql);
System.out.println(pn.toExplainPlanString());
assertTrue(pn instanceof SendPlanNode);
pn = pn.getChild(0);
if (needOrderby) {
assertTrue(pn instanceof ProjectionPlanNode);
pn = pn.getChild(0);
assertTrue(pn instanceof OrderByPlanNode);
pn = pn.getChild(0);
}
assertTrue(pn instanceof IndexScanPlanNode);
IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
assertTrue(ispn.getTargetIndexName().contains(indexName));
assertEquals(lookupType, ispn.getLookupType());
assertEquals(searchKeys, ispn.getSearchKeyExpressions().size());
assertEquals(endKeys, ExpressionUtil.uncombinePredicate(ispn.getEndExpression()).size());
assertEquals(predicates, ExpressionUtil.uncombinePredicate(ispn.getPredicate()).size());
assertEquals(0, ExpressionUtil.uncombinePredicate(ispn.getInitialExpression()).size());
assertEquals(sortType, ispn.getSortDirection());
}
Aggregations