public IndexSelector(RexNode indexCondition, RexNode otherRemainderCondition, IndexCallContext indexContext, IndexCollection collection, RexBuilder rexBuilder, double totalRows) { this.indexCondition = indexCondition; this.otherRemainderCondition = otherRemainderCondition; this.indexContext = indexContext; this.totalRows = totalRows; this.stats = indexContext.getGroupScan().getStatistics(); this.rexBuilder = rexBuilder; this.builder = IndexConditionInfo.newBuilder(indexCondition, collection, rexBuilder, indexContext.getScan()); this.primaryTableScan = indexContext.getScan(); this.indexPropList = Lists.newArrayList(); }
if (indexContext.getLowerProject() == null) { for (RexNode rex : indexContext.getUpperProject().getProjects()) { LogicalExpression expr = RexToExpression.toDrill(parserContext, null, indexContext.getScan(), rex); exprs.add(expr); IndexableExprMarker filterMarker = new IndexableExprMarker(indexContext.getScan()); indexContext.getFilterCondition().accept(filterMarker); for (RexNode rex : filterMarker.getIndexableExpression().keySet()) { LogicalExpression expr = RexToExpression.toDrill(parserContext, null, indexContext.getScan(), rex); exprs.add(expr); LogicalExpression expr = RexToExpression.toDrill(parserContext, indexContext.getLowerProject(), indexContext.getScan(), rex); exprs.add(expr); IndexableExprMarker filterMarker = new IndexableExprMarker(indexContext.getScan()); indexContext.getOrigCondition().accept(filterMarker); LogicalExpression expr = RexToExpression.toDrill(parserContext, null, indexContext.getScan(), rex); exprs.add(expr); LogicalExpression expr = DrillOptiq.toDrill(parserContext, indexContext.getScan(), rex); exprs.add(expr);
/** * This constructor is to build selector for no index condition case (no filter) * @param indexContext */ public IndexSelector(IndexCallContext indexContext) { this.indexCondition = null; this.otherRemainderCondition = null; this.indexContext = indexContext; this.totalRows = Statistics.ROWCOUNT_UNKNOWN; this.stats = indexContext.getGroupScan().getStatistics(); this.rexBuilder = indexContext.getScan().getCluster().getRexBuilder(); this.builder = null; this.primaryTableScan = indexContext.getScan(); this.indexPropList = Lists.newArrayList(); }
/** * Build the collation property for index scan * @param indexDesc the index for which we are building index plan * @param context the context of this index planning process * @return the output RelCollation for the scan on index */ public static RelCollation buildCollationCoveringIndexScan(IndexDescriptor indexDesc, IndexCallContext context) { Map<LogicalExpression, Integer> rowTypeExprs = getExprsFromRowType(context.getScan().getRowType()); return buildCollationForExpressions(rowTypeExprs, indexDesc, context); }
public AbstractIndexPlanGenerator(IndexCallContext indexContext, RexNode indexCondition, RexNode remainderCondition, RexBuilder builder, PlannerSettings settings) { super(indexContext.getCall()); this.origProject = indexContext.getLowerProject(); this.origScan = indexContext.getScan(); this.upperProject = indexContext.getUpperProject(); this.indexCondition = indexCondition; this.remainderCondition = remainderCondition; this.indexContext = indexContext; this.builder = builder; this.settings = settings; }
/** * For a particular table scan for table T1 and an index on that table, find out if it is a covering index * @return */ static public boolean isCoveringIndex(IndexCallContext indexContext, FunctionalIndexInfo functionInfo) { if (functionInfo.hasFunctional()) { // need info from full query return queryCoveredByIndex(indexContext, functionInfo); } DbGroupScan groupScan = (DbGroupScan) getGroupScan(indexContext.getScan()); List<LogicalExpression> tableCols = Lists.newArrayList(); tableCols.addAll(groupScan.getColumns()); return functionInfo.getIndexDesc().isCoveringIndex(tableCols); }
DrillProjectRelBase oneProject; if (indexContext.getUpperProject() != null && indexContext.getLowerProject() != null) { LogicalExpression expr = RexToExpression.toDrill(parserContext, indexContext.getLowerProject(), indexContext.getScan(), indexContext.getUpperProject().getProjects().get(idx)); indexContext.getSortExprs().add(expr); oneProject = (indexContext.getUpperProject() != null)? indexContext.getUpperProject() : indexContext.getLowerProject(); if (oneProject != null) { LogicalExpression expr = RexToExpression.toDrill(parserContext, null, indexContext.getScan(), getProjects(oneProject).get(idx)); indexContext.getSortExprs().add(expr); RelDataTypeField f = indexContext.getScan().getRowType().getFieldList().get(idx); String pathSeg = f.getName().replaceAll("`", ""); final String[] segs = pathSeg.split("\\.");
private boolean buildAndCheckCollation(IndexProperties indexProps) { IndexDescriptor indexDesc = indexProps.getIndexDesc(); FunctionalIndexInfo functionInfo = indexDesc.getFunctionalInfo(); RelCollation inputCollation; // for the purpose of collation we can assume that a covering index scan would provide // the collation property that would be relevant for non-covering as well ScanPrel indexScanPrel = IndexPlanUtils.buildCoveringIndexScan(indexContext.getScan(), indexDesc.getIndexGroupScan(), indexContext, indexDesc); inputCollation = indexScanPrel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE); // we don't create collation for Filter because it will inherit the child's collation if (indexContext.hasLowerProject()) { inputCollation = IndexPlanUtils.buildCollationProject(indexContext.getLowerProject().getProjects(), null, indexContext.getScan(), functionInfo,indexContext); } if (indexContext.hasUpperProject()) { inputCollation = IndexPlanUtils.buildCollationProject(indexContext.getUpperProject().getProjects(), indexContext.getLowerProject(), indexContext.getScan(), functionInfo, indexContext); } if ((inputCollation != null) && (inputCollation.satisfies(indexContext.getCollation()))) { return true; } return false; }
indexContext.getScan(), functionInfo, indexContext); finalRel = new ProjectPrel(indexContext.getScan().getCluster(), indexScanTraitSet.plus(collation), indexScanPrel, indexContext.getLowerProject().getProjects(), indexContext.getLowerProject().getRowType()); finalRel.toString(), indexContext.getScan().toString(), indexContext.getLowerProject()!=null?indexContext.getLowerProject().getDigest(): indexContext.getScan().getDigest(), finalRel.getDigest()); return finalRel;