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);
}
}
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);
}
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);
}
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;
}
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);
}
Aggregations