Apache Calcite关系表达式优化-基于代价分析

125 阅读1分钟

 

代价类

org.apache.calcite.plan.RelOptCost

工厂

org.apache.calcite.plan.RelOptCostFactory

默认工厂的实现

org.apache.calcite.plan.RelOptCostImpl#FACTORY

工厂的接收方-优化器

      final HepPlanner hepPlanner = new HepPlanner(hepProgram,
          null, noDag, null, RelOptCostImpl.FACTORY);

提供代价信息

org.apache.calcite.rel.metadata.RelMetadataQuery

RelMetadataQuery会把关系表达式与org.apache.calcite.util.BuiltInMethod方法的关系找到提供代价数据的方法,一般来说就是关系表达式节点

例如

org.apache.calcite.rel.metadata.RelMetadataQuery#getDistinctRowCount对应

org.apache.calcite.rel.metadata.RelMetadataQuery#distinctRowCountHandler对应

org.apache.calcite.rel.metadata.BuiltInMetadata.DistinctRowCount对应

org.apache.calcite.util.BuiltInMethod#DISTINCT_ROW_COUNT

  DISTINCT_ROW_COUNT(DistinctRowCount.class, "getDistinctRowCount",
      ImmutableBitSet.class, RexNode.class),