Search in sources :

Example 1 with IgniteCostFactory

use of org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory in project ignite-3 by apache.

the class PlannerTest method testJoinPushExpressionRule.

@Test
public void testJoinPushExpressionRule() throws Exception {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    TestTable emp = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("DEPTNO", f.createJavaType(Integer.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    };
    TestTable dept = new TestTable(new RelDataTypeFactory.Builder(f).add("DEPTNO", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    };
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("EMP", emp);
    publicSchema.addTable("DEPT", dept);
    SchemaPlus schema = createRootSchema(false).add("PUBLIC", publicSchema);
    String sql = "select d.deptno, e.deptno " + "from dept d, emp e " + "where d.deptno + e.deptno = 2";
    PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).costFactory(new IgniteCostFactory(1, 100, 1, 1)).build()).build()).query(sql).build();
    RelRoot relRoot;
    try (IgnitePlanner planner = ctx.planner()) {
        assertNotNull(planner);
        String qry = ctx.query();
        assertNotNull(qry);
        // Parse
        SqlNode sqlNode = planner.parse(qry);
        // Validate
        sqlNode = planner.validate(sqlNode);
        // Convert to Relational operators graph
        relRoot = planner.rel(sqlNode);
        RelNode rel = relRoot.rel;
        assertNotNull(rel);
        assertEquals("LogicalProject(DEPTNO=[$0], DEPTNO0=[$4])\n" + "  LogicalFilter(condition=[=(CAST(+($0, $4)):INTEGER, 2)])\n" + "    LogicalJoin(condition=[true], joinType=[inner])\n" + "      IgniteLogicalTableScan(table=[[PUBLIC, DEPT]])\n" + "      IgniteLogicalTableScan(table=[[PUBLIC, EMP]])\n", RelOptUtil.toString(rel));
        // Transformation chain
        RelTraitSet desired = rel.getCluster().traitSet().replace(IgniteConvention.INSTANCE).replace(IgniteDistributions.single()).replace(CorrelationTrait.UNCORRELATED).simplify();
        IgniteRel phys = planner.transform(PlannerPhase.OPTIMIZATION, desired, rel);
        assertNotNull(phys);
        assertEquals("IgniteProject(DEPTNO=[$3], DEPTNO0=[$2])\n" + "  IgniteCorrelatedNestedLoopJoin(condition=[=(CAST(+($3, $2)):INTEGER, 2)], joinType=[inner], " + "correlationVariables=[[$cor2]])\n" + "    IgniteTableScan(table=[[PUBLIC, EMP]])\n" + "    IgniteTableScan(table=[[PUBLIC, DEPT]], filters=[=(CAST(+($t0, $cor2.DEPTNO)):INTEGER, 2)])\n", RelOptUtil.toString(phys), "Invalid plan:\n" + RelOptUtil.toString(phys));
        checkSplitAndSerialization(phys, publicSchema);
    }
}
Also used : IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) Frameworks.newConfigBuilder(org.apache.calcite.tools.Frameworks.newConfigBuilder) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) RelRoot(org.apache.calcite.rel.RelRoot) RelTraitSet(org.apache.calcite.plan.RelTraitSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnitePlanner(org.apache.ignite.internal.sql.engine.prepare.IgnitePlanner) RelNode(org.apache.calcite.rel.RelNode) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteCostFactory

use of org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory in project ignite-3 by apache.

the class IgniteCorrelatedNestedLoopJoin method computeSelfCost.

/**
 * {@inheritDoc}
 */
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    IgniteCostFactory costFactory = (IgniteCostFactory) planner.getCostFactory();
    double leftCount = mq.getRowCount(getLeft());
    if (Double.isInfinite(leftCount)) {
        return costFactory.makeInfiniteCost();
    }
    double rightCount = mq.getRowCount(getRight());
    if (Double.isInfinite(rightCount)) {
        return costFactory.makeInfiniteCost();
    }
    double rows = leftCount * rightCount;
    return costFactory.makeCost(rows, rows * (IgniteCost.ROW_COMPARISON_COST + IgniteCost.ROW_PASS_THROUGH_COST), 0);
}
Also used : IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory)

Example 3 with IgniteCostFactory

use of org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory in project ignite-3 by apache.

the class IgniteHashIndexSpool method computeSelfCost.

/**
 * {@inheritDoc}
 */
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    double rowCnt = mq.getRowCount(getInput());
    double bytesPerRow = getRowType().getFieldCount() * IgniteCost.AVERAGE_FIELD_SIZE;
    double totalBytes = rowCnt * bytesPerRow;
    double cpuCost = IgniteCost.HASH_LOOKUP_COST;
    IgniteCostFactory costFactory = (IgniteCostFactory) planner.getCostFactory();
    return costFactory.makeCost(rowCnt, cpuCost, 0, totalBytes, 0);
}
Also used : IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory)

Example 4 with IgniteCostFactory

use of org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory in project ignite-3 by apache.

the class IgniteSort method computeSelfCost.

/**
 * {@inheritDoc}
 */
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    double rows = mq.getRowCount(getInput());
    double cpuCost = rows * IgniteCost.ROW_PASS_THROUGH_COST + Util.nLogN(rows) * IgniteCost.ROW_COMPARISON_COST;
    double memory = rows * getRowType().getFieldCount() * IgniteCost.AVERAGE_FIELD_SIZE;
    IgniteCostFactory costFactory = (IgniteCostFactory) planner.getCostFactory();
    RelOptCost cost = costFactory.makeCost(rows, cpuCost, 0, memory, 0);
    // Distributed sorting is more preferable than sorting on the single node.
    if (TraitUtils.distribution(traitSet).satisfies(IgniteDistributions.single())) {
        cost.plus(costFactory.makeTinyCost());
    }
    return cost;
}
Also used : IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory) RelOptCost(org.apache.calcite.plan.RelOptCost)

Example 5 with IgniteCostFactory

use of org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory in project ignite-3 by apache.

the class IgniteSortedIndexSpool method computeSelfCost.

/**
 * {@inheritDoc}
 */
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    double rowCnt = mq.getRowCount(getInput());
    double bytesPerRow = getRowType().getFieldCount() * IgniteCost.AVERAGE_FIELD_SIZE;
    double totalBytes = rowCnt * bytesPerRow;
    double cpuCost;
    if (idxCond.lowerCondition() != null) {
        cpuCost = Math.log(rowCnt) * IgniteCost.ROW_COMPARISON_COST;
    } else {
        cpuCost = rowCnt * IgniteCost.ROW_PASS_THROUGH_COST;
    }
    IgniteCostFactory costFactory = (IgniteCostFactory) planner.getCostFactory();
    return costFactory.makeCost(rowCnt, cpuCost, 0, totalBytes, 0);
}
Also used : IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory)

Aggregations

IgniteCostFactory (org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory)15 RelNode (org.apache.calcite.rel.RelNode)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RelOptCost (org.apache.calcite.plan.RelOptCost)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelRoot (org.apache.calcite.rel.RelRoot)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 SqlNode (org.apache.calcite.sql.SqlNode)1 Frameworks.newConfigBuilder (org.apache.calcite.tools.Frameworks.newConfigBuilder)1 IgnitePlanner (org.apache.ignite.internal.sql.engine.prepare.IgnitePlanner)1 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)1 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)1 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1 Test (org.junit.jupiter.api.Test)1