use of org.voltdb.plannodes.NestLoopPlanNode in project voltdb by VoltDB.
the class TestJoinOrder method testInnerOuterJoinOrder.
public void testInnerOuterJoinOrder() {
AbstractPlanNode pn;
pn = compileSPWithJoinOrder("select * FROM T1, T2, T3 LEFT JOIN T4 ON T3.C = T4.D LEFT JOIN T5 ON T3.C = T5.E, T6,T7", "T2, T1, T3, T4, T5, T7, T6");
AbstractPlanNode n = pn.getChild(0).getChild(0);
String[] joinOrder = { "T2", "T1", "T3", "T4", "T5", "T7", "T6" };
for (int i = 6; i > 0; i--) {
assertTrue(n instanceof NestLoopPlanNode);
assertTrue(n.getChild(1) instanceof SeqScanPlanNode);
SeqScanPlanNode s = (SeqScanPlanNode) n.getChild(1);
if (i == 1) {
assertTrue(n.getChild(0) instanceof SeqScanPlanNode);
assertTrue(joinOrder[i - 1].equals(((SeqScanPlanNode) n.getChild(0)).getTargetTableName()));
} else {
assertTrue(n.getChild(0) instanceof NestLoopPlanNode);
n = n.getChild(0);
}
assertTrue(joinOrder[i].equals(s.getTargetTableName()));
}
try {
compileWithInvalidJoinOrder("select * FROM T1, T2, T3 LEFT JOIN T4 ON T3.C = T4.D LEFT JOIN T5 ON T3.C = T5.E, T6,T7", "T2, T6, T3, T4, T5, T7, T1");
fail();
} catch (Exception ex) {
assertTrue("The specified join order is invalid for the given query".equals(ex.getMessage()));
}
try {
compileWithInvalidJoinOrder("select * FROM T1, T2, T3 LEFT JOIN T4 ON T3.C = T4.D LEFT JOIN T5 ON T3.C = T5.E, T6,T7", "T1, T2, T4, T3, T5, T7, T6");
fail();
} catch (Exception ex) {
assertTrue("The specified join order is invalid for the given query".equals(ex.getMessage()));
}
try {
compileWithInvalidJoinOrder("select * FROM T1, T2, T3 LEFT JOIN T4 ON T3.C = T4.D LEFT JOIN T5 ON T3.C = T5.E, T6,T7", "T1, T2, T3, T4, T5, T7");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" does not contain the correct number of elements") != -1);
}
try {
compileWithInvalidJoinOrder("select * FROM T1, T2, T3 LEFT JOIN T4 ON T3.C = T4.D LEFT JOIN T5 ON T3.C = T5.E, T6,T7", "T1, T2, T3, T4, T5, T7, T6, T8");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" does not contain the correct number of elements") != -1);
}
}
use of org.voltdb.plannodes.NestLoopPlanNode in project voltdb by VoltDB.
the class TestJoinOrder method testBasicJoinOrder.
public void testBasicJoinOrder() {
AbstractPlanNode pn = compileSPWithJoinOrder("select * FROM T1, T2, T3, T4, T5, T6, T7", "T7,T6,T5,T4,T3,T2,T1");
AbstractPlanNode n = pn.getChild(0).getChild(0);
for (int ii = 1; ii <= 7; ii++) {
if (ii == 6) {
assertTrue(((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii)) || ((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii + 1)));
assertTrue(((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii)) || ((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii + 1)));
break;
} else {
NestLoopPlanNode node = (NestLoopPlanNode) n;
assertTrue(((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii)));
n = node.getChild(0);
}
}
pn = compileSPWithJoinOrder("select * FROM T1, T2, T3, T4, T5, T6, T7", "T1,T2,T3,T4,T5,T6,T7");
n = pn.getChild(0).getChild(0);
for (int ii = 7; ii > 0; ii--) {
if (ii == 2) {
assertTrue(((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii)) || ((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii - 1)));
assertTrue(((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii)) || ((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii - 1)));
break;
} else {
NestLoopPlanNode node = (NestLoopPlanNode) n;
assertTrue(((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii)));
n = node.getChild(0);
}
}
pn = compileSPWithJoinOrder("select * from T1, T2 where A=B", " T1 , T2 ");
//* enable to debug */ System.out.println(pn.toExplainPlanString());
n = pn.getChild(0).getChild(0);
assertEquals("T1", ((SeqScanPlanNode) n.getChild(0)).getTargetTableName());
assertEquals("T2", ((SeqScanPlanNode) n.getChild(1)).getTargetTableName());
pn = compileSPWithJoinOrder("select * from T1, T2 where A=B", " T2,T1 ");
n = pn.getChild(0).getChild(0);
assertEquals("T2", ((SeqScanPlanNode) n.getChild(0)).getTargetTableName());
assertEquals("T1", ((SeqScanPlanNode) n.getChild(1)).getTargetTableName());
// Don't mind a trailing comma -- even when followed by space.
pn = compileSPWithJoinOrder("select * from T1, T2 where A=B", "T2,T1, ");
n = pn.getChild(0).getChild(0);
assertEquals("T2", ((SeqScanPlanNode) n.getChild(0)).getTargetTableName());
assertEquals("T1", ((SeqScanPlanNode) n.getChild(1)).getTargetTableName());
pn = compileSPWithJoinOrder("select * from T1, T2 where A=B", "T1,T2,");
n = pn.getChild(0).getChild(0);
assertEquals("T1", ((SeqScanPlanNode) n.getChild(0)).getTargetTableName());
assertEquals("T2", ((SeqScanPlanNode) n.getChild(1)).getTargetTableName());
try {
// Wants alias "T2", not bogus "Z"
compileWithInvalidJoinOrder("select * from T1, T2 where A=B", "T1,Z");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" doesn't exist ") != -1);
}
try {
// Wants comma, not semicolon -- does not parse the correct number of symbols.
// The parser may give a smarter message in the future.
compileWithInvalidJoinOrder("select * from T1, T2 where A=B", "T1;T2");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" does not contain the correct number of elements") != -1);
}
try {
// Wants comma, not double comma -- does not parse the correct number of symbols.
// The parser may give a smarter message in the future.
compileWithInvalidJoinOrder("select * from T1, T2 where A=B", "T1,,T2");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" does not contain the correct number of elements") != -1);
}
try {
// Does not want leading comma -- does not parse the correct number of symbols.
// The parser may give a smarter message in the future.
compileWithInvalidJoinOrder("select * from T1, T2 where A=B", ",T1,T2");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" does not contain the correct number of elements") != -1);
}
try {
// Does not want leading comma after whitespace
// -- does not parse the correct number of symbols.
// The parser may give a smarter message in the future.
compileWithInvalidJoinOrder("select * from T1, T2 where A=B", " ,T1,T2");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf(" does not contain the correct number of elements") != -1);
}
}
use of org.voltdb.plannodes.NestLoopPlanNode in project voltdb by VoltDB.
the class TestJoinOrder method checkJoinOrder.
private void checkJoinOrder(String sql, int... exceptions) {
AbstractPlanNode pn, n;
pn = compile(sql);
n = pn.getChild(0).getChild(0);
//* enable to debug */ System.out.println(pn.toExplainPlanString());
// starts from T7
HashSet<Integer> mySets = new HashSet<>();
for (int i : exceptions) {
mySets.add(Integer.valueOf(i));
}
for (int ii = 7; ii > 0; ii--) {
if (ii == 2) {
assertTrue(((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii)) || ((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii - 1)));
assertTrue(((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii)) || ((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii - 1)));
break;
} else {
NestLoopPlanNode node = (NestLoopPlanNode) n;
if (mySets.contains(Integer.valueOf(ii))) {
assertTrue(((SeqScanPlanNode) n.getChild(0)).getTargetTableName().endsWith(Integer.toString(ii)));
n = node.getChild(1);
} else {
// starts from T6 on child 1 because of the invalid join
assertTrue(((SeqScanPlanNode) n.getChild(1)).getTargetTableName().endsWith(Integer.toString(ii)));
n = node.getChild(0);
}
}
}
}
Aggregations