use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansInExistsSubQueries method testExistsSimplification.
public void testExistsSimplification() {
AbstractPlanNode pn;
AbstractJoinPlanNode jpn;
// LIMIT is 0 EXISTS => FALSE
pn = compile("select a from r1 where exists " + " (select a, c from r2 limit 0) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyCVEPredicate(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), false);
// LIMIT is 0 EXISTS => FALSE
pn = compile("select a from r1 where exists " + " (select count(*) from r2 limit 0) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyCVEPredicate(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), false);
//EXISTS => TRUE, join predicate is TRUE or EXPR = > TRUE and dropped
pn = compile("select r1.a from r1 join r2 on (exists " + " (select max(a) from r2) or r2.a > 0)");
assertTrue(pn.getChild(0).getChild(0) instanceof AbstractJoinPlanNode);
jpn = (AbstractJoinPlanNode) pn.getChild(0).getChild(0);
assertTrue(jpn.getWherePredicate() == null);
//EXISTS => FALSE, join predicate is retained
pn = compile("select r1.a from r1 join r2 on exists " + " (select max(a) from r2 offset 1) ");
assertTrue(pn.getChild(0).getChild(0) instanceof NestLoopPlanNode);
jpn = (NestLoopPlanNode) pn.getChild(0).getChild(0);
verifyCVEPredicate(jpn.getJoinPredicate(), false);
// table-agg-without-having-groupby OFFSET > 0 => FALSE
pn = compile("select a from r1 where exists " + " (select count(*) from r2 offset 1) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyCVEPredicate(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), false);
// table-agg-without-having-groupby => TRUE
pn = compile("select a from r1 where exists " + " (select max(a) from r2) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
assertTrue(((SeqScanPlanNode) pn.getChild(0)).getPredicate() == null);
// table-agg-without-having-groupby by limit is a parameter => EXISTS
pn = compile("select a from r1 where exists " + " (select max(a) from r2 limit ?) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
AbstractExpression pred = ((SeqScanPlanNode) pn.getChild(0)).getPredicate();
assertNotNull(pred);
assertEquals(ExpressionType.OPERATOR_EXISTS, pred.getExpressionType());
// Subquery => select 1 from r2 limit 1 offset 2
pn = compile("select a from r1 where exists " + " (select a, c from r2 order by a offset 2) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyTrivialSchemaLimitOffset(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), 1, 2);
// User's limit ?
// Subquery => EXISTS (select 1 from r2 limit ?)
pn = compile("select a from r1 where exists " + " (select a, c from r2 order by a limit ?) ");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyTrivialSchemaLimitOffset(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), -1, 0);
// Subquery subquery-without-having with group by and no limit
// => select a, max(c) from r2 group by a limit 1
pn = compile("select a from r1 where exists " + " (select a, max(c) from r2 group by a order by max(c))");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyAggregateSubquery(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), 2, 1, false);
// Subquery subquery-without-having with group by and offset 3 => subquery-without-having with group by and offset 3
pn = compile("select a from r1 where exists " + " (select a, max(c) from r2 group by a order by max(c) offset 2)");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
verifyAggregateSubquery(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), 2, 1, false);
// Subquery subquery-with-having with group by => subquery-with-having with group by
pn = compile("select a from r1 where exists " + " (select a, max(c) from r2 group by a having max(c) > 2 order by max(c))");
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
// weakened for now around the unification of the input column to the HAVING clause:
verifyAggregateSubquery(((SeqScanPlanNode) pn.getChild(0)).getPredicate(), 2, 1, true);
//verifyAggregateSubquery(((SeqScanPlanNode)pn.getChild(0)).getPredicate(), 3, 1, true);
}
use of org.voltdb.plannodes.AbstractPlanNode 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.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansLimit method checkInlineLimitWithOrderby.
private void checkInlineLimitWithOrderby(List<AbstractPlanNode> pns, boolean pushdown) {
AbstractPlanNode p;
p = pns.get(0).getChild(0);
assertTrue(p instanceof ProjectionPlanNode);
p = p.getChild(0);
if (p instanceof MergeReceivePlanNode) {
assertNotNull(p.getInlinePlanNode(PlanNodeType.ORDERBY));
AbstractPlanNode aggr = AggregatePlanNode.getInlineAggregationNode(p);
if (aggr != null) {
assertNotNull(aggr.getInlinePlanNode(PlanNodeType.LIMIT));
}
} else {
assertTrue(p instanceof OrderByPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.LIMIT));
}
if (pushdown) {
assertEquals(2, pns.size());
p = pns.get(1).getChild(0);
assertTrue(p instanceof OrderByPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.LIMIT));
} else if (pns.size() == 2) {
p = pns.get(1).getChild(0);
assertFalse(p.toExplainPlanString().toLowerCase().contains("limit"));
}
}
use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansOrderBy method validateAggregatedMergeReceive.
private void validateAggregatedMergeReceive(AbstractPlanNode pn, boolean hasSerialAggr, boolean hasPartialAggr, boolean hasProj, boolean hasLimit) {
assertEquals(PlanNodeType.MERGERECEIVE, pn.getPlanNodeType());
MergeReceivePlanNode rpn = (MergeReceivePlanNode) pn;
assertNotNull(rpn.getInlinePlanNode(PlanNodeType.ORDERBY));
assertEquals(hasSerialAggr, rpn.getInlinePlanNode(PlanNodeType.AGGREGATE) != null);
assertEquals(hasPartialAggr, rpn.getInlinePlanNode(PlanNodeType.PARTIALAGGREGATE) != null);
assertEquals(hasProj, rpn.getInlinePlanNode(PlanNodeType.PROJECTION) != null);
if (hasSerialAggr || hasPartialAggr) {
AbstractPlanNode aggrNode = (hasSerialAggr) ? rpn.getInlinePlanNode(PlanNodeType.AGGREGATE) : rpn.getInlinePlanNode(PlanNodeType.PARTIALAGGREGATE);
assertEquals(hasLimit, aggrNode.getInlinePlanNode(PlanNodeType.LIMIT) != null);
} else {
assertEquals(hasLimit, rpn.getInlinePlanNode(PlanNodeType.LIMIT) != null);
}
}
use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansOrderBy method validateMergeReceive.
private void validateMergeReceive(String sql, boolean hasLimit, int[] sortColumnIdx) {
List<AbstractPlanNode> frags = compileToFragments(sql);
assertEquals(2, frags.size());
AbstractPlanNode pn = frags.get(0).getChild(0).getChild(0);
validateMergeReceive(pn, hasLimit, sortColumnIdx);
}
Aggregations