Search in sources :

Example 1 with IgniteSortedIndexSpool

use of org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool in project ignite-3 by apache.

the class SortedIndexSpoolPlannerTest method testPartialIndexForCondition.

/**
 * Check case when exists index (collation) isn't applied not for whole join condition but may be used by part of
 * condition.
 */
@Test
public void testPartialIndexForCondition() throws Exception {
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    publicSchema.addTable("T0", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID0", f.createJavaType(Integer.class)).add("JID1", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T0", "hash");
        }
    });
    publicSchema.addTable("T1", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID0", f.createJavaType(Integer.class)).add("JID1", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T1", "hash");
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid0_idx"));
    String sql = "select * " + "from t0 " + "join t1 on t0.jid0 = t1.jid0 and t0.jid1 = t1.jid1";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeToHashIndexSpoolRule");
    System.out.println("+++ \n" + RelOptUtil.toString(phys));
    IgniteSortedIndexSpool idxSpool = findFirstNode(phys, byClass(IgniteSortedIndexSpool.class));
    List<RexNode> lowerBound = idxSpool.indexCondition().lowerBound();
    assertNotNull(lowerBound);
    assertEquals(4, lowerBound.size());
    assertTrue(((RexLiteral) lowerBound.get(0)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(3)).isNull());
    assertTrue(lowerBound.get(1) instanceof RexFieldAccess);
    List<RexNode> upperBound = idxSpool.indexCondition().upperBound();
    assertNotNull(upperBound);
    assertEquals(4, upperBound.size());
    assertTrue(((RexLiteral) upperBound.get(0)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(3)).isNull());
    assertTrue(upperBound.get(1) instanceof RexFieldAccess);
}
Also used : IgniteSortedIndexSpool(org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteDistribution(org.apache.ignite.internal.sql.engine.trait.IgniteDistribution) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteSortedIndexSpool

use of org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool in project ignite-3 by apache.

the class FilterSpoolMergeToSortedIndexSpoolRule method onMatch.

/**
 * {@inheritDoc}
 */
@Override
public void onMatch(RelOptRuleCall call) {
    final IgniteFilter filter = call.rel(0);
    final IgniteTableSpool spool = call.rel(1);
    RelOptCluster cluster = spool.getCluster();
    RelTraitSet trait = spool.getTraitSet();
    CorrelationTrait filterCorr = TraitUtils.correlation(filter);
    if (filterCorr.correlated()) {
        trait = trait.replace(filterCorr);
    }
    RelNode input = spool.getInput();
    IndexConditions idxCond = RexUtils.buildSortedIndexConditions(cluster, TraitUtils.collation(input), filter.getCondition(), spool.getRowType(), null);
    if (nullOrEmpty(idxCond.lowerCondition()) && nullOrEmpty(idxCond.upperCondition())) {
        return;
    }
    RelCollation collation = TraitUtils.createCollation(idxCond.keys());
    RelNode res = new IgniteSortedIndexSpool(cluster, trait.replace(collation), convert(input, input.getTraitSet().replace(collation)), collation, filter.getCondition(), idxCond);
    call.transformTo(res);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) IgniteSortedIndexSpool(org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool) CorrelationTrait(org.apache.ignite.internal.sql.engine.trait.CorrelationTrait) RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) IgniteFilter(org.apache.ignite.internal.sql.engine.rel.IgniteFilter) IgniteTableSpool(org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool) IndexConditions(org.apache.ignite.internal.sql.engine.util.IndexConditions) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 3 with IgniteSortedIndexSpool

use of org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool in project ignite-3 by apache.

the class SortedIndexSpoolPlannerTest method testNotColocatedEqJoin.

/**
 * Check equi-join on not colocated fields. CorrelatedNestedLoopJoinTest is applicable for this case only with
 * IndexSpool.
 */
@Test
public void testNotColocatedEqJoin() throws Exception {
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    publicSchema.addTable("T0", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T0", "hash");
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t0_jid_idx"));
    publicSchema.addTable("T1", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T1", "hash");
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid_idx"));
    String sql = "select * " + "from t0 " + "join t1 on t0.jid = t1.jid";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeToHashIndexSpoolRule");
    IgniteSortedIndexSpool idxSpool = findFirstNode(phys, byClass(IgniteSortedIndexSpool.class));
    List<RexNode> lowerBound = idxSpool.indexCondition().lowerBound();
    assertNotNull(lowerBound);
    assertEquals(3, lowerBound.size());
    assertTrue(((RexLiteral) lowerBound.get(0)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
    assertTrue(lowerBound.get(1) instanceof RexFieldAccess);
    List<RexNode> upperBound = idxSpool.indexCondition().upperBound();
    assertNotNull(upperBound);
    assertEquals(3, upperBound.size());
    assertTrue(((RexLiteral) upperBound.get(0)).isNull());
    assertTrue(((RexLiteral) upperBound.get(2)).isNull());
    assertTrue(upperBound.get(1) instanceof RexFieldAccess);
}
Also used : IgniteSortedIndexSpool(org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteSortedIndexSpool (org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool)3 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)2 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)2 RexNode (org.apache.calcite.rex.RexNode)2 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)2 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)2 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)2 Test (org.junit.jupiter.api.Test)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelCollation (org.apache.calcite.rel.RelCollation)1 RelNode (org.apache.calcite.rel.RelNode)1 IgniteFilter (org.apache.ignite.internal.sql.engine.rel.IgniteFilter)1 IgniteTableSpool (org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool)1 CorrelationTrait (org.apache.ignite.internal.sql.engine.trait.CorrelationTrait)1 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)1 IndexConditions (org.apache.ignite.internal.sql.engine.util.IndexConditions)1