use of org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin in project ignite-3 by apache.
the class JoinCommutePlannerTest method testInnerCommute.
@Test
public void testInnerCommute() throws Exception {
String sql = "SELECT COUNT(*) FROM SMALL s JOIN HUGE h on h.id = s.id";
IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
assertNotNull(phys);
IgniteNestedLoopJoin join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
assertNotNull(join);
IgniteProject proj = findFirstNode(phys, byClass(IgniteProject.class));
assertNotNull(proj);
IgniteTableScan rightScan = findFirstNode(join.getRight(), byClass(IgniteTableScan.class));
assertNotNull(rightScan);
IgniteTableScan leftScan = findFirstNode(join.getLeft(), byClass(IgniteTableScan.class));
assertNotNull(leftScan);
List<String> rightSchemaWithName = rightScan.getTable().getQualifiedName();
assertEquals(2, rightSchemaWithName.size());
assertEquals(rightSchemaWithName.get(1), "SMALL");
List<String> leftSchemaWithName = leftScan.getTable().getQualifiedName();
assertEquals(leftSchemaWithName.get(1), "HUGE");
assertEquals(JoinRelType.INNER, join.getJoinType());
PlanningContext ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
RelOptPlanner pl = ctx.cluster().getPlanner();
RelOptCost costWithCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
assertNotNull(costWithCommute);
System.out.println("plan: " + RelOptUtil.toString(phys));
assertNotNull(phys);
phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
proj = findFirstNode(phys, byClass(IgniteProject.class));
rightScan = findFirstNode(join.getRight(), byClass(IgniteTableScan.class));
leftScan = findFirstNode(join.getLeft(), byClass(IgniteTableScan.class));
assertNotNull(join);
assertNull(proj);
assertNotNull(rightScan);
assertNotNull(leftScan);
rightSchemaWithName = rightScan.getTable().getQualifiedName();
assertEquals(2, rightSchemaWithName.size());
// no commute
assertEquals(rightSchemaWithName.get(1), "HUGE");
leftSchemaWithName = leftScan.getTable().getQualifiedName();
assertEquals(leftSchemaWithName.get(1), "SMALL");
// no commute
assertEquals(JoinRelType.INNER, join.getJoinType());
ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
pl = ctx.cluster().getPlanner();
RelOptCost costWithoutCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
System.out.println("plan: " + RelOptUtil.toString(phys));
assertTrue(costWithCommute.isLt(costWithoutCommute));
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin in project ignite-3 by apache.
the class JoinCommutePlannerTest method testOuterCommute.
@Test
public void testOuterCommute() throws Exception {
String sql = "SELECT COUNT(*) FROM SMALL s RIGHT JOIN HUGE h on h.id = s.id";
IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
assertNotNull(phys);
IgniteNestedLoopJoin join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
IgniteProject proj = findFirstNode(phys, byClass(IgniteProject.class));
assertNotNull(proj);
assertEquals(JoinRelType.LEFT, join.getJoinType());
PlanningContext ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
RelOptPlanner pl = ctx.cluster().getPlanner();
RelOptCost costWithCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
assertNotNull(costWithCommute);
System.out.println("plan: " + RelOptUtil.toString(phys));
assertNotNull(phys);
phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
proj = findFirstNode(phys, byClass(IgniteProject.class));
assertNull(proj);
// no commute
assertEquals(JoinRelType.RIGHT, join.getJoinType());
ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
pl = ctx.cluster().getPlanner();
RelOptCost costWithoutCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
System.out.println("plan: " + RelOptUtil.toString(phys));
assertTrue(costWithCommute.isLt(costWithoutCommute));
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin in project ignite-3 by apache.
the class NestedLoopJoinConverterRule method convert.
/**
* {@inheritDoc}
*/
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalJoin rel) {
RelOptCluster cluster = rel.getCluster();
RelTraitSet outTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
RelTraitSet leftInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
RelTraitSet rightInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
RelNode left = convert(rel.getLeft(), leftInTraits);
RelNode right = convert(rel.getRight(), rightInTraits);
return new IgniteNestedLoopJoin(cluster, outTraits, left, right, rel.getCondition(), rel.getVariablesSet(), rel.getJoinType());
}
Aggregations