use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.
the class JoinColocationPlannerTest method joinComplexToComplexAffWithDifferentOrder.
/**
* Re-hashing for complex affinity is not supported.
*/
@Test
public void joinComplexToComplexAffWithDifferentOrder() throws Exception {
TestTable complexTblDirect = createTable("COMPLEX_TBL_DIRECT", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
complexTblDirect.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTblDirect));
TestTable complexTblIndirect = createTable("COMPLEX_TBL_INDIRECT", IgniteDistributions.affinity(ImmutableIntList.of(1, 0), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
complexTblIndirect.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTblIndirect));
IgniteSchema schema = createSchema(complexTblDirect, complexTblIndirect);
String sql = "select count(*) " + "from COMPLEX_TBL_DIRECT t1 " + "join COMPLEX_TBL_INDIRECT t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
IgniteMergeJoin exchange = findFirstNode(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
assertThat(invalidPlanMsg, exchange, nullValue());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.
the class MergeJoinConverterRule method convert.
/**
* {@inheritDoc}
*/
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalJoin rel) {
RelOptCluster cluster = rel.getCluster();
JoinInfo joinInfo = JoinInfo.of(rel.getLeft(), rel.getRight(), rel.getCondition());
RelTraitSet leftInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(RelCollations.of(joinInfo.leftKeys));
RelTraitSet outTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
RelTraitSet rightInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(RelCollations.of(joinInfo.rightKeys));
RelNode left = convert(rel.getLeft(), leftInTraits);
RelNode right = convert(rel.getRight(), rightInTraits);
return new IgniteMergeJoin(cluster, outTraits, left, right, rel.getCondition(), rel.getVariablesSet(), rel.getJoinType());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.
the class JoinColocationPlannerTest method joinSameTableSimpleAff.
/**
* Join of the same tables with a simple affinity is expected to be colocated.
*/
@Test
public void joinSameTableSimpleAff() throws Exception {
TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
tbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", tbl));
IgniteSchema schema = createSchema(tbl);
String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id = t2.id";
RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
assertThat(invalidPlanMsg, join, notNullValue());
assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.
the class JoinColocationPlannerTest method joinSameTableComplexAff.
/**
* Join of the same tables with a complex affinity is expected to be colocated.
*/
@Test
public void joinSameTableComplexAff() throws Exception {
TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
tbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", tbl));
IgniteSchema schema = createSchema(tbl);
String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
assertThat(invalidPlanMsg, join, notNullValue());
assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.
the class JoinColocationPlannerTest method joinComplexToSimpleAff.
/**
* Re-hashing based on simple affinity is possible, so bigger table with complex affinity should be sended to the smaller one.
*/
@Test
public void joinComplexToSimpleAff() throws Exception {
TestTable complexTbl = createTable("COMPLEX_TBL", 2 * DEFAULT_TBL_SIZE, IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
complexTbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTbl));
TestTable simpleTbl = createTable("SIMPLE_TBL", DEFAULT_TBL_SIZE, IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
simpleTbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", simpleTbl));
IgniteSchema schema = createSchema(complexTbl, simpleTbl);
String sql = "select count(*) " + "from COMPLEX_TBL t1 " + "join SIMPLE_TBL t2 on t1.id1 = t2.id";
RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
assertThat(invalidPlanMsg, join, notNullValue());
assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
List<IgniteExchange> exchanges = findNodes(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
assertThat(invalidPlanMsg, exchanges, hasSize(1));
assertThat(invalidPlanMsg, exchanges.get(0).getInput(0), instanceOf(IgniteIndexScan.class));
assertThat(invalidPlanMsg, exchanges.get(0).getInput(0).getTable().unwrap(TestTable.class), equalTo(complexTbl));
}
Aggregations