public void testScanJoinConditions() {
AbstractPlanNode pn = compile("select * FROM R1 WHERE R1.C = 0");
AbstractPlanNode n = pn.getChild(0);
assertTrue(n instanceof AbstractScanPlanNode);
AbstractScanPlanNode scan = (AbstractScanPlanNode) n;
AbstractExpression p = scan.getPredicate();
assertEquals(ExpressionType.COMPARE_EQUAL, p.getExpressionType());
pn = compile("select * FROM R1, R2 WHERE R1.A = R2.A AND R1.C > 0");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.COMPARE_EQUAL, p.getExpressionType());
n = n.getChild(0);
assertTrue(n instanceof AbstractScanPlanNode);
assertTrue(((AbstractScanPlanNode) n).getTargetTableName().equalsIgnoreCase("R1"));
p = ((AbstractScanPlanNode) n).getPredicate();
assertEquals(ExpressionType.COMPARE_GREATERTHAN, p.getExpressionType());
pn = compile("select * FROM R1, R2 WHERE R1.A = R2.A AND R1.C > R2.C");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.CONJUNCTION_AND, p.getExpressionType());
if (p.getLeft().getExpressionType() == ExpressionType.COMPARE_EQUAL) {
assertEquals(ExpressionType.COMPARE_EQUAL, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_LESSTHAN, p.getRight().getExpressionType());
} else {
assertEquals(ExpressionType.COMPARE_LESSTHAN, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getRight().getExpressionType());
}
assertNull(((AbstractScanPlanNode)n.getChild(0)).getPredicate());
assertNull(((AbstractScanPlanNode)n.getChild(1)).getPredicate());
pn = compile("select * FROM R1 JOIN R2 ON R1.A = R2.A WHERE R1.C > 0");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.COMPARE_EQUAL, p.getExpressionType());
n = n.getChild(0);
assertTrue(n instanceof AbstractScanPlanNode);
assertTrue("R1".equalsIgnoreCase(((AbstractScanPlanNode) n).getTargetTableName()));
p = ((AbstractScanPlanNode) n).getPredicate();
assertEquals(ExpressionType.COMPARE_GREATERTHAN, p.getExpressionType());
pn = compile("select * FROM R1 JOIN R2 ON R1.A = R2.A WHERE R1.C > R2.C");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.CONJUNCTION_AND, p.getExpressionType());
if (ExpressionType.COMPARE_EQUAL == p.getLeft().getExpressionType()) {
assertEquals(ExpressionType.COMPARE_EQUAL, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_LESSTHAN, p.getRight().getExpressionType());
} else {
assertEquals(ExpressionType.COMPARE_LESSTHAN, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getRight().getExpressionType());
}
assertNull(((AbstractScanPlanNode)n.getChild(0)).getPredicate());
assertNull(((AbstractScanPlanNode)n.getChild(1)).getPredicate());
pn = compile("select * FROM R1, R2, R3 WHERE R1.A = R2.A AND R1.C = R3.C AND R1.A > 0");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.COMPARE_EQUAL, p.getExpressionType());
AbstractPlanNode c = n.getChild(0);
assertTrue(c instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) c).getJoinPredicate();
assertEquals(ExpressionType.COMPARE_EQUAL, p.getExpressionType());
c = c.getChild(0);
assertTrue(c instanceof AbstractScanPlanNode);
p = ((AbstractScanPlanNode) c).getPredicate();
assertEquals(ExpressionType.COMPARE_GREATERTHAN, p.getExpressionType());
c = n.getChild(1);
assertTrue("R3".equalsIgnoreCase(((AbstractScanPlanNode) c).getTargetTableName()));
assertEquals(null, ((AbstractScanPlanNode) c).getPredicate());
pn = compile("select * FROM R1 JOIN R2 on R1.A = R2.A AND R1.C = R2.C where R1.A > 0");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.CONJUNCTION_AND, p.getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getRight().getExpressionType());
n = n.getChild(0);
assertTrue(n instanceof AbstractScanPlanNode);
assertTrue("R1".equalsIgnoreCase(((AbstractScanPlanNode) n).getTargetTableName()));
p = ((AbstractScanPlanNode) n).getPredicate();
assertEquals(ExpressionType.COMPARE_GREATERTHAN, p.getExpressionType());
pn = compile("select A,C FROM R1 JOIN R2 USING (A, C)");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.CONJUNCTION_AND, p.getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getRight().getExpressionType());
pn = compile("select A,C FROM R1 JOIN R2 USING (A, C) WHERE A > 0");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof AbstractJoinPlanNode);
p = ((AbstractJoinPlanNode) n).getJoinPredicate();
assertEquals(ExpressionType.CONJUNCTION_AND, p.getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getLeft().getExpressionType());
assertEquals(ExpressionType.COMPARE_EQUAL, p.getRight().getExpressionType());
n = n.getChild(1);
assertTrue(n instanceof AbstractScanPlanNode);
scan = (AbstractScanPlanNode) n;
assertTrue(scan.getPredicate() != null);
assertEquals(ExpressionType.COMPARE_GREATERTHAN, scan.getPredicate().getExpressionType());
pn = compile("select * FROM R1 JOIN R2 ON R1.A = R2.A JOIN R3 ON R1.C = R3.C WHERE R1.A > 0");
n = pn.getChild(0).getChild(0);
assertTrue(n instanceof NestLoopPlanNode);
p = ((NestLoopPlanNode) n).getJoinPredicate();