Class IndexPlanUtils
java.lang.Object
org.apache.drill.exec.planner.index.IndexPlanUtils
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.calcite.rel.RelCollation
buildCollationCoveringIndexScan
(IndexDescriptor indexDesc, IndexCallContext context) Build the collation property for index scanstatic org.apache.calcite.rel.RelCollation
buildCollationForExpressions
(Map<LogicalExpression, Integer> projectExprs, IndexDescriptor indexDesc, IndexCallContext context) Given index, compute the collations for a list of projected expressions(from Scan's rowType or Project's ) in the contextstatic org.apache.calcite.rel.RelCollation
buildCollationLowerProject
(List<org.apache.calcite.rex.RexNode> projectRexs, org.apache.calcite.rel.RelNode input, FunctionalIndexInfo indexInfo) Build collation property for the 'lower' project, the one closer to the Scanstatic org.apache.calcite.rel.RelCollation
buildCollationNonCoveringIndexScan
(IndexDescriptor indexDesc, org.apache.calcite.rel.type.RelDataType indexScanRowType, org.apache.calcite.rel.type.RelDataType restrictedScanRowType, IndexCallContext context) static org.apache.calcite.rel.RelCollation
buildCollationProject
(List<org.apache.calcite.rex.RexNode> projectRexs, DrillProjectRelBase project, org.apache.calcite.rel.RelNode input, FunctionalIndexInfo indexInfo, IndexCallContext context) Build collation property for project, the one closer to the Scanstatic org.apache.calcite.rel.RelCollation
buildCollationUpperProject
(List<org.apache.calcite.rex.RexNode> projectRexs, org.apache.calcite.rel.RelCollation inputCollation, FunctionalIndexInfo indexInfo, Map<Integer, List<org.apache.calcite.rex.RexNode>> collationFilterMap) Build collation property for the 'upper' project, the one above the filterstatic ScanPrel
buildCoveringIndexScan
(DrillScanRelBase origScan, IndexGroupScan indexGroupScan, IndexCallContext indexContext, IndexDescriptor indexDesc) static boolean
checkScan
(DrillScanRel scanRel) check if we want to apply index rules on this scan, if group scan is not instance of DbGroupScan, or this DbGroupScan instance does not support secondary index, or this scan is already an index scan or Restricted Scan, do not apply index plan rules on it.conditionIndexed
(IndexableExprMarker exprMarker, IndexDescriptor indexDesc) Check if any of the fields of the index are present in a list of LogicalExpressions supplied as part of IndexableExprMarkerstatic boolean
generateLimit
(OrderedRel sort) static org.apache.calcite.rel.RelCollation
getCollation
(org.apache.calcite.rel.core.Sort sort) getDistributionField
(org.apache.calcite.rel.core.Sort rel) static Map<LogicalExpression,
Integer> getExprsFromRowType
(org.apache.calcite.rel.type.RelDataType indexScanRowType) static org.apache.calcite.rex.RexNode
getFetch
(OrderedRel sort) static GroupScan
getGroupScan
(DrillScanRelBase relNode) static int
getIndexFromCollation
(int refIndex, List<org.apache.calcite.rel.RelFieldCollation> inputFieldCollations) static org.apache.calcite.rex.RexNode
getLeadingColumnsFilter
(List<org.apache.calcite.rex.RexNode> leadingFilters, org.apache.calcite.rex.RexBuilder rexBuilder) static List<org.apache.calcite.rex.RexNode>
getLeadingFilters
(Map<LogicalExpression, org.apache.calcite.rex.RexNode> leadingPrefixMap, List<LogicalExpression> indexCols) static org.apache.calcite.rex.RexNode
getLeadingPrefixMap
(Map<LogicalExpression, org.apache.calcite.rex.RexNode> leadingPrefixMap, List<LogicalExpression> indexCols, IndexConditionInfo.Builder builder, org.apache.calcite.rex.RexNode condition) static org.apache.calcite.rex.RexNode
getOffset
(OrderedRel sort) static Map<LogicalExpression,
Integer> getProjectExprs
(List<org.apache.calcite.rex.RexNode> projectRexs, DrillProjectRelBase project, org.apache.calcite.rel.RelNode input) static List<org.apache.calcite.rex.RexNode>
static org.apache.calcite.rex.RexNode
getTotalFilter
(org.apache.calcite.rex.RexNode leadColsFilter, org.apache.calcite.rex.RexNode totRemColsFilter, org.apache.calcite.rex.RexBuilder rexBuilder) static org.apache.calcite.rex.RexNode
getTotalRemainderFilter
(org.apache.calcite.rex.RexNode indexColsRemFilter, org.apache.calcite.rex.RexNode incColsRemFilter, org.apache.calcite.rex.RexBuilder rexBuilder) static boolean
isCoveringIndex
(IndexCallContext indexContext, FunctionalIndexInfo functionInfo) For a particular table scan for table T1 and an index on that table, find out if it is a covering indexstatic boolean
static org.apache.calcite.rex.RexNode
rewriteFunctionalRex
(IndexCallContext indexContext, DrillParseContext parseContext, DrillProjectRelBase project, org.apache.calcite.rel.RelNode scan, org.apache.calcite.rex.RexNode toRewriteRex, org.apache.calcite.rel.type.RelDataType newRowType, FunctionalIndexInfo functionInfo) A RexNode forest with three RexNodes for expressions "cast(a.q as int) * 2, b+c, concat(a.q, " world")" on Scan RowType('a', 'b', 'c') will be like this: (0)Call:"*" Call:"concat" / \ / \ (1)Call:CAST 2 Call:"+" (5)Call:ITEM ' world' / \ / \ / \ (2)Call:ITEM TYPE:INT (3)$1 (4)$2 $0 'q' / \ $0 'q' So for above expressions, when visiting the RexNode trees using PathInExpr, we could mark indexed expressions in the trees, as shown in the diagram above are the node (1), then collect the schema paths in the indexed expression but found out of the indexed expression -- node (5), and other regular schema paths (3) (4)static List<SchemaPath>
rewriteFunctionColumn
(List<SchemaPath> paths, FunctionalIndexInfo functionInfo, List<SchemaPath> addedPaths) For IndexGroupScan, if a column is only appeared in the should-be-renamed function, this column is to-be-replaced column, we replace that column(schemaPath) from 'a.b' to '$1' in the list of SchemaPath.static boolean
scanIsPartition
(GroupScan scan) static void
updateSortExpression
(IndexCallContext indexContext, List<org.apache.calcite.rel.RelFieldCollation> coll) generate logical expressions for sort rexNodes in SortRel, the result is store to IndexPlanCallContextstatic void
updateSortExpression
(IndexPhysicalPlanCallContext indexContext, List<org.apache.calcite.rel.RelFieldCollation> coll) generate logical expressions for sort rexNodes in SortRel, the result is store to IndexPlanCallContext
-
Constructor Details
-
IndexPlanUtils
public IndexPlanUtils()
-
-
Method Details
-
conditionIndexed
public static IndexPlanUtils.ConditionIndexed conditionIndexed(IndexableExprMarker exprMarker, IndexDescriptor indexDesc) Check if any of the fields of the index are present in a list of LogicalExpressions supplied as part of IndexableExprMarker- Parameters:
exprMarker
- the marker that has analyzed original index condition on top of original scanindexDesc
- the index definition plus functions to access materialized index- Returns:
- ConditionIndexed.FULL, PARTIAL or NONE depending on whether all, some or no columns of the indexDesc are present in the list of LogicalExpressions supplied as part of exprMarker
-
checkScan
check if we want to apply index rules on this scan, if group scan is not instance of DbGroupScan, or this DbGroupScan instance does not support secondary index, or this scan is already an index scan or Restricted Scan, do not apply index plan rules on it.- Parameters:
scanRel
- the current scan rel- Returns:
- true to indicate that we want to apply index rules on this scan, otherwise false
-
isCoveringIndex
public static boolean isCoveringIndex(IndexCallContext indexContext, FunctionalIndexInfo functionInfo) For a particular table scan for table T1 and an index on that table, find out if it is a covering index- Returns:
- true if it is a covering index, otherwise false
-
buildCollationLowerProject
public static org.apache.calcite.rel.RelCollation buildCollationLowerProject(List<org.apache.calcite.rex.RexNode> projectRexs, org.apache.calcite.rel.RelNode input, FunctionalIndexInfo indexInfo) Build collation property for the 'lower' project, the one closer to the Scan- Parameters:
projectRexs
- list of row expressionsinput
- input as a relational expressionindexInfo
- collects functional index information- Returns:
- the output RelCollation
-
buildCollationUpperProject
public static org.apache.calcite.rel.RelCollation buildCollationUpperProject(List<org.apache.calcite.rex.RexNode> projectRexs, org.apache.calcite.rel.RelCollation inputCollation, FunctionalIndexInfo indexInfo, Map<Integer, List<org.apache.calcite.rex.RexNode>> collationFilterMap) Build collation property for the 'upper' project, the one above the filter- Parameters:
projectRexs
- list of row expressionsinputCollation
- the input collationindexInfo
- collects functional index informationcollationFilterMap
- map for collation filter- Returns:
- the output RelCollation
-
getIndexFromCollation
public static int getIndexFromCollation(int refIndex, List<org.apache.calcite.rel.RelFieldCollation> inputFieldCollations) -
getProjects
-
generateLimit
-
getOffset
-
getFetch
-
updateSortExpression
public static void updateSortExpression(IndexCallContext indexContext, List<org.apache.calcite.rel.RelFieldCollation> coll) generate logical expressions for sort rexNodes in SortRel, the result is store to IndexPlanCallContext- Parameters:
indexContext
- the index call contextcoll
- list of field collations
-
updateSortExpression
public static void updateSortExpression(IndexPhysicalPlanCallContext indexContext, List<org.apache.calcite.rel.RelFieldCollation> coll) generate logical expressions for sort rexNodes in SortRel, the result is store to IndexPlanCallContext- Parameters:
indexContext
- the index call contextcoll
- list of field collations
-
buildCollationProject
public static org.apache.calcite.rel.RelCollation buildCollationProject(List<org.apache.calcite.rex.RexNode> projectRexs, DrillProjectRelBase project, org.apache.calcite.rel.RelNode input, FunctionalIndexInfo indexInfo, IndexCallContext context) Build collation property for project, the one closer to the Scan- Parameters:
projectRexs
- the expressions to projectproject
- the project between projectRexs and input, it could be null if no such intermediate project(lower project)input
- the input RelNode to the project, usually it is the scan operator.indexInfo
- the index for which we are building index plancontext
- the context of this index planning process- Returns:
- the output RelCollation
-
buildCollationCoveringIndexScan
public static org.apache.calcite.rel.RelCollation buildCollationCoveringIndexScan(IndexDescriptor indexDesc, IndexCallContext context) Build the collation property for index scan- Parameters:
indexDesc
- the index for which we are building index plancontext
- the context of this index planning process- Returns:
- the output RelCollation for the scan on index
-
getProjectExprs
public static Map<LogicalExpression,Integer> getProjectExprs(List<org.apache.calcite.rex.RexNode> projectRexs, DrillProjectRelBase project, org.apache.calcite.rel.RelNode input) -
getExprsFromRowType
public static Map<LogicalExpression,Integer> getExprsFromRowType(org.apache.calcite.rel.type.RelDataType indexScanRowType) -
buildCollationForExpressions
public static org.apache.calcite.rel.RelCollation buildCollationForExpressions(Map<LogicalExpression, Integer> projectExprs, IndexDescriptor indexDesc, IndexCallContext context) Given index, compute the collations for a list of projected expressions(from Scan's rowType or Project's ) in the context- Parameters:
projectExprs
- the output expression list of a RelNodeindexDesc
- the index for which we are building index plancontext
- the context of this index planning process- Returns:
- the collation provided by index that will be exposed by the expression list
-
pathOnlyInIndexedFunction
-
buildCollationNonCoveringIndexScan
public static org.apache.calcite.rel.RelCollation buildCollationNonCoveringIndexScan(IndexDescriptor indexDesc, org.apache.calcite.rel.type.RelDataType indexScanRowType, org.apache.calcite.rel.type.RelDataType restrictedScanRowType, IndexCallContext context) -
scanIsPartition
-
getGroupScan
-
getCollation
public static org.apache.calcite.rel.RelCollation getCollation(org.apache.calcite.rel.core.Sort sort) -
getDistributionField
public static List<DrillDistributionTrait.DistributionField> getDistributionField(org.apache.calcite.rel.core.Sort rel) -
buildCoveringIndexScan
public static ScanPrel buildCoveringIndexScan(DrillScanRelBase origScan, IndexGroupScan indexGroupScan, IndexCallContext indexContext, IndexDescriptor indexDesc) -
rewriteFunctionColumn
public static List<SchemaPath> rewriteFunctionColumn(List<SchemaPath> paths, FunctionalIndexInfo functionInfo, List<SchemaPath> addedPaths) For IndexGroupScan, if a column is only appeared in the should-be-renamed function, this column is to-be-replaced column, we replace that column(schemaPath) from 'a.b' to '$1' in the list of SchemaPath.- Parameters:
paths
- list of pathsfunctionInfo
- functional index information that may impact rewriteaddedPaths
- list of paths added- Returns:
- list of new paths
-
rewriteFunctionalRex
public static org.apache.calcite.rex.RexNode rewriteFunctionalRex(IndexCallContext indexContext, DrillParseContext parseContext, DrillProjectRelBase project, org.apache.calcite.rel.RelNode scan, org.apache.calcite.rex.RexNode toRewriteRex, org.apache.calcite.rel.type.RelDataType newRowType, FunctionalIndexInfo functionInfo) A RexNode forest with three RexNodes for expressions "cast(a.q as int) * 2, b+c, concat(a.q, " world")" on Scan RowType('a', 'b', 'c') will be like this: (0)Call:"*" Call:"concat" / \ / \ (1)Call:CAST 2 Call:"+" (5)Call:ITEM ' world' / \ / \ / \ (2)Call:ITEM TYPE:INT (3)$1 (4)$2 $0 'q' / \ $0 'q' So for above expressions, when visiting the RexNode trees using PathInExpr, we could mark indexed expressions in the trees, as shown in the diagram above are the node (1), then collect the schema paths in the indexed expression but found out of the indexed expression -- node (5), and other regular schema paths (3) (4)- Parameters:
indexContext
- the index call contextparseContext
- the drill parse contextproject
- the drill base class for logical and physical projectsscan
- a rel node scantoRewriteRex
- the RexNode to be converted if it contains a functional index expressionnewRowType
- data type for new rowfunctionInfo
- functional index information that may impact rewrite- Returns:
- rewritten functional row expression
-
getLeadingPrefixMap
public static org.apache.calcite.rex.RexNode getLeadingPrefixMap(Map<LogicalExpression, org.apache.calcite.rex.RexNode> leadingPrefixMap, List<LogicalExpression> indexCols, IndexConditionInfo.Builder builder, org.apache.calcite.rex.RexNode condition) -
getLeadingFilters
public static List<org.apache.calcite.rex.RexNode> getLeadingFilters(Map<LogicalExpression, org.apache.calcite.rex.RexNode> leadingPrefixMap, List<LogicalExpression> indexCols) -
getLeadingColumnsFilter
public static org.apache.calcite.rex.RexNode getLeadingColumnsFilter(List<org.apache.calcite.rex.RexNode> leadingFilters, org.apache.calcite.rex.RexBuilder rexBuilder) -
getTotalRemainderFilter
public static org.apache.calcite.rex.RexNode getTotalRemainderFilter(org.apache.calcite.rex.RexNode indexColsRemFilter, org.apache.calcite.rex.RexNode incColsRemFilter, org.apache.calcite.rex.RexBuilder rexBuilder) -
getTotalFilter
public static org.apache.calcite.rex.RexNode getTotalFilter(org.apache.calcite.rex.RexNode leadColsFilter, org.apache.calcite.rex.RexNode totRemColsFilter, org.apache.calcite.rex.RexBuilder rexBuilder)
-