Search in sources :

Example 1 with UnionPlanNode

use of org.voltdb.plannodes.UnionPlanNode in project voltdb by VoltDB.

the class TestUnion method testUnion.

public void testUnion() {
    AbstractPlanNode pn = compile("select A from T1 UNION select B from T2 UNION select C from T3");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    UnionPlanNode unionPN = (UnionPlanNode) pn.getChild(0);
    assertTrue(unionPN.getUnionType() == ParsedUnionStmt.UnionType.UNION);
    assertTrue(unionPN.getChildCount() == 3);
    pn = compile("(select A from T1 UNION select B from T2) UNION select C from T3");
    unionPN = (UnionPlanNode) pn.getChild(0);
    assertTrue(unionPN.getUnionType() == ParsedUnionStmt.UnionType.UNION);
    assertTrue(unionPN.getChildCount() == 3);
    pn = compile("select A from T1 UNION (select B from T2 UNION select C from T3)");
    unionPN = (UnionPlanNode) pn.getChild(0);
    assertTrue(unionPN.getUnionType() == ParsedUnionStmt.UnionType.UNION);
    assertTrue(unionPN.getChildCount() == 3);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) UnionPlanNode(org.voltdb.plannodes.UnionPlanNode)

Example 2 with UnionPlanNode

use of org.voltdb.plannodes.UnionPlanNode in project voltdb by VoltDB.

the class TestPlansSubQueries method testUnions.

public void testUnions() {
    AbstractPlanNode pn;
    pn = compile("select A, C FROM (SELECT A, C FROM R1 UNION SELECT A, C FROM R2 UNION SELECT A, C FROM R3) T1 order by A ");
    pn = pn.getChild(0);
    assertTrue(pn instanceof ProjectionPlanNode);
    pn = pn.getChild(0);
    assertTrue(pn instanceof OrderByPlanNode);
    pn = pn.getChild(0);
    checkSeqScan(pn, "T1", "A", "C");
    AbstractPlanNode upn = pn.getChild(0);
    assertTrue(upn instanceof UnionPlanNode);
    pn = upn.getChild(0);
    checkSeqScan(pn, "R1", "A", "C");
    pn = upn.getChild(1);
    checkSeqScan(pn, "R2", "A", "C");
    pn = upn.getChild(2);
    checkSeqScan(pn, "R3", "A", "C");
    String message = "This query is not plannable.  It has a subquery which needs cross-partition access.";
    failToCompile("select * FROM " + "(SELECT A, COUNT(*) FROM P1 GROUP BY A " + "UNION " + "SELECT A, COUNT(*) FROM R2 GROUP BY A) T1 , P2 where T1.A = P2.A ", message);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) UnionPlanNode(org.voltdb.plannodes.UnionPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 3 with UnionPlanNode

use of org.voltdb.plannodes.UnionPlanNode in project voltdb by VoltDB.

the class TestUnion method testIntersect.

public void testIntersect() {
    AbstractPlanNode pn = compile("select A from T1 INTERSECT select B from T2 INTERSECT select C from T3");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    UnionPlanNode unionPN = (UnionPlanNode) pn.getChild(0);
    assertTrue(unionPN.getUnionType() == ParsedUnionStmt.UnionType.INTERSECT);
    assertTrue(unionPN.getChildCount() == 3);
    pn = compile("(select A from T1 INTERSECT select B from T2) INTERSECT select C from T3");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    unionPN = (UnionPlanNode) pn.getChild(0);
    assertTrue(unionPN.getUnionType() == ParsedUnionStmt.UnionType.INTERSECT);
    assertTrue(unionPN.getChildCount() == 3);
    pn = compile("select A from T1 INTERSECT (select B from T2 INTERSECT select C from T3)");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    unionPN = (UnionPlanNode) pn.getChild(0);
    assertTrue(unionPN.getUnionType() == ParsedUnionStmt.UnionType.INTERSECT);
    assertTrue(unionPN.getChildCount() == 3);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) UnionPlanNode(org.voltdb.plannodes.UnionPlanNode)

Example 4 with UnionPlanNode

use of org.voltdb.plannodes.UnionPlanNode in project voltdb by VoltDB.

the class TestUnion method testSelfUnion.

public void testSelfUnion() {
    AbstractPlanNode pn = compile("select B from T2 UNION select B from T2");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    pn = pn.getChild(0);
    assertTrue(pn.getChildCount() == 2);
    assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
    assertTrue(pn.getChild(1) instanceof SeqScanPlanNode);
    // The same table/alias is repeated twice in the union but in the different selects
    pn = compile("select A1.B from T2 A1, T2 A2 WHERE A1.B = A2.B UNION select B from T2 A1");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    pn = pn.getChild(0);
    assertTrue(pn.getChildCount() == 2);
    assertTrue(pn.getChild(0) instanceof ProjectionPlanNode);
    assertTrue(pn.getChild(0).getChild(0) instanceof NestLoopPlanNode);
    assertTrue(pn.getChild(1) instanceof SeqScanPlanNode);
    // BOTH sides are single-partitioned  for the same partition
    pn = compile("select F from T1 WHERE T1.A = 2 UNION select F from T1 WHERE T1.A = 2");
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    // If BOTH sides are single-partitioned, but for different partitions,
    // it would theoretically be possible to satisfy
    // the query with a 2-fragment plan IFF the coordinator fragment could be forced to
    // execute on one of the designated single partitions.
    // At this point, coordinator designation is only supported for single-fragment plans.
    failToCompile("select DESC from T1 WHERE A = 1 UNION select DESC from T1 WHERE A = 2");
    // If both sides are multi-partitioned, there is no facility for pushing down the
    // union processing below the send/receive, so each child of the union requires
    // its own send/receive so the plan ends up as an unsupported 3-fragment plan.
    failToCompile("select DESC from T1 UNION select DESC from T1");
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) UnionPlanNode(org.voltdb.plannodes.UnionPlanNode) NestLoopPlanNode(org.voltdb.plannodes.NestLoopPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 5 with UnionPlanNode

use of org.voltdb.plannodes.UnionPlanNode in project voltdb by VoltDB.

the class TestUnion method testUnionOrderByLimitParams.

public void testUnionOrderByLimitParams() {
    AbstractPlanNode pn = compile("select C from T3 where C = ? UNION select B from T2 order by C limit ? offset ?");
    String[] columnNames = { "C" };
    pn = pn.getChild(0);
    int[] idxs = { 0 };
    checkOrderByNode(pn, columnNames, idxs);
    assertTrue(pn.getChild(0) instanceof UnionPlanNode);
    pn = pn.getInlinePlanNode(PlanNodeType.LIMIT);
    assert (pn instanceof LimitPlanNode);
    assertTrue(pn.toExplainPlanString().contains("LIMIT with parameter"));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) UnionPlanNode(org.voltdb.plannodes.UnionPlanNode) LimitPlanNode(org.voltdb.plannodes.LimitPlanNode)

Aggregations

AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)14 UnionPlanNode (org.voltdb.plannodes.UnionPlanNode)14 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)3 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)3 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)2 ArrayList (java.util.ArrayList)1 Constraint (org.voltdb.catalog.Constraint)1 AbstractExpression (org.voltdb.expressions.AbstractExpression)1 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)1 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)1