public class IndexPlanUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
IndexPlanUtils.ConditionIndexed |
Constructor and Description |
---|
IndexPlanUtils() |
Modifier and Type | Method and Description |
---|---|
static org.apache.calcite.rel.RelCollation |
buildCollationCoveringIndexScan(IndexDescriptor indexDesc,
IndexCallContext context)
Build the collation property for index scan
|
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
|
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
|
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) |
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
|
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
|
static 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.
|
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
|
static boolean |
generateLimit(OrderedRel sort) |
static org.apache.calcite.rel.RelCollation |
getCollation(org.apache.calcite.rel.core.Sort sort) |
static List<DrillDistributionTrait.DistributionField> |
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> |
getProjects(DrillProjectRelBase proj) |
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 index
|
static boolean |
pathOnlyInIndexedFunction(SchemaPath path) |
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 IndexPlanCallContext
|
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
|
public static IndexPlanUtils.ConditionIndexed conditionIndexed(IndexableExprMarker exprMarker, IndexDescriptor indexDesc)
exprMarker
- the marker that has analyzed original index condition on top of original scanindexDesc
- the index definition plus functions to access materialized indexpublic static boolean checkScan(DrillScanRel scanRel)
scanRel
- the current scan relpublic static boolean isCoveringIndex(IndexCallContext indexContext, FunctionalIndexInfo functionInfo)
public static org.apache.calcite.rel.RelCollation buildCollationLowerProject(List<org.apache.calcite.rex.RexNode> projectRexs, org.apache.calcite.rel.RelNode input, FunctionalIndexInfo indexInfo)
projectRexs
- list of row expressionsinput
- input as a relational expressionindexInfo
- collects functional index informationpublic 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)
projectRexs
- list of row expressionsinputCollation
- the input collationindexInfo
- collects functional index informationcollationFilterMap
- map for collation filterpublic static int getIndexFromCollation(int refIndex, List<org.apache.calcite.rel.RelFieldCollation> inputFieldCollations)
public static List<org.apache.calcite.rex.RexNode> getProjects(DrillProjectRelBase proj)
public static boolean generateLimit(OrderedRel sort)
public static org.apache.calcite.rex.RexNode getOffset(OrderedRel sort)
public static org.apache.calcite.rex.RexNode getFetch(OrderedRel sort)
public static void updateSortExpression(IndexCallContext indexContext, List<org.apache.calcite.rel.RelFieldCollation> coll)
indexContext
- the index call contextcoll
- list of field collationspublic static void updateSortExpression(IndexPhysicalPlanCallContext indexContext, List<org.apache.calcite.rel.RelFieldCollation> coll)
indexContext
- the index call contextcoll
- list of field collationspublic 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)
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 processpublic static org.apache.calcite.rel.RelCollation buildCollationCoveringIndexScan(IndexDescriptor indexDesc, IndexCallContext context)
indexDesc
- the index for which we are building index plancontext
- the context of this index planning processpublic static Map<LogicalExpression,Integer> getProjectExprs(List<org.apache.calcite.rex.RexNode> projectRexs, DrillProjectRelBase project, org.apache.calcite.rel.RelNode input)
public static Map<LogicalExpression,Integer> getExprsFromRowType(org.apache.calcite.rel.type.RelDataType indexScanRowType)
public static org.apache.calcite.rel.RelCollation buildCollationForExpressions(Map<LogicalExpression,Integer> projectExprs, IndexDescriptor indexDesc, IndexCallContext context)
projectExprs
- the output expression list of a RelNodeindexDesc
- the index for which we are building index plancontext
- the context of this index planning processpublic static boolean pathOnlyInIndexedFunction(SchemaPath path)
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)
public static boolean scanIsPartition(GroupScan scan)
public static GroupScan getGroupScan(DrillScanRelBase relNode)
public static org.apache.calcite.rel.RelCollation getCollation(org.apache.calcite.rel.core.Sort sort)
public static List<DrillDistributionTrait.DistributionField> getDistributionField(org.apache.calcite.rel.core.Sort rel)
public static ScanPrel buildCoveringIndexScan(DrillScanRelBase origScan, IndexGroupScan indexGroupScan, IndexCallContext indexContext, IndexDescriptor indexDesc)
public static List<SchemaPath> rewriteFunctionColumn(List<SchemaPath> paths, FunctionalIndexInfo functionInfo, List<SchemaPath> addedPaths)
paths
- list of pathsfunctionInfo
- functional index information that may impact rewriteaddedPaths
- list of paths addedpublic 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)
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 rewritepublic 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)
public static List<org.apache.calcite.rex.RexNode> getLeadingFilters(Map<LogicalExpression,org.apache.calcite.rex.RexNode> leadingPrefixMap, List<LogicalExpression> indexCols)
public static org.apache.calcite.rex.RexNode getLeadingColumnsFilter(List<org.apache.calcite.rex.RexNode> leadingFilters, org.apache.calcite.rex.RexBuilder rexBuilder)
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)
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)
Copyright © 2022 The Apache Software Foundation. All rights reserved.