private RexNode convertCastForFIdx(RexCall condition, IndexDescriptor index, IndexCallContext context, RelNode origScan) { if (index == null) { return condition; } FunctionalIndexInfo functionInfo = index.getFunctionalInfo(); if (!functionInfo.hasFunctional()) { return condition; } // The functional index has a different row-type than the original scan. Use the index row-type when // converting the condition RelDataType newRowType = FunctionalIndexHelper.rewriteFunctionalRowType(origScan, context, functionInfo); RexBuilder builder = origScan.getCluster().getRexBuilder(); return FunctionalIndexHelper.convertConditionForIndexScan(condition, origScan, newRowType, builder, functionInfo); }
IndexDescriptor index = iterator.next(); if (index.getIndexColumns() != null) { List<IndexDescriptor> idxList; String firstCol = convertLExToStr(index.getIndexColumns().get(0)); if (firstColIndexMap.get(firstCol) != null) { idxList = firstColIndexMap.get(firstCol); && (selectedIdx == null || idx.getIndexName().compareTo(selectedIdx.getIndexName()) < 0))) { maxAvgRowSize = idxRowSize; selectedIdx = idx;
@Override public String buildUniqueIndexIdentifier(IndexDescriptor idx) { if (idx == null) { return null; } else { return idx.getTableName() + "_" + idx.getIndexName(); } }
private void init() { int count = 0; for (LogicalExpression indexedExpr : indexDesc.getIndexColumns()) { if (!(indexedExpr instanceof SchemaPath)) { hasFunctionalField = true; SchemaPath functionalFieldPath = SchemaPath.getSimplePath("$"+count); newPathsForIndexedFunction.add(functionalFieldPath); // now we handle only cast expression if (indexedExpr instanceof CastExpression) { // We handle only CAST directly on SchemaPath for now. SchemaPath pathBeingCasted = (SchemaPath)((CastExpression) indexedExpr).getInput(); addTargetPathForOriginalPath(pathBeingCasted, functionalFieldPath); addPathInExpr(indexedExpr, pathBeingCasted); exprToConvert.put(indexedExpr, functionalFieldPath); allPathsInFunction.add(pathBeingCasted); } count++; } } }
Arrays.asList(SqlKind.CAST, SqlKind.LIKE)); RelDataType newRowType; FunctionalIndexInfo functionInfo = idx.getFunctionalInfo(); if (functionInfo.hasFunctional()) { newRowType = FunctionalIndexHelper.rewriteFunctionalRowType(scanRel, context, functionInfo); RexNode idxRemColCondition = IndexPlanUtils.getLeadingPrefixMap(leadingPrefixMap, idx.getIndexColumns(), infoBuilder, idxCondition); RexNode idxLeadColCondition = IndexPlanUtils.getLeadingColumnsFilter( IndexPlanUtils.getLeadingFilters(leadingPrefixMap, idx.getIndexColumns()), builder); RexNode idxTotRemColCondition = IndexPlanUtils.getTotalRemainderFilter(idxRemColCondition, idxIncColCondition, builder); RexNode idxTotColCondition = IndexPlanUtils.getTotalFilter(idxLeadColCondition, idxTotRemColCondition, builder); FunctionalIndexInfo functionInfo = idx.getFunctionalInfo(); RelDataType newRowType = scanRel.getRowType(); if (functionInfo.hasFunctional()) {
if (isValidIndexHint && !indexContext.indexHint.equals(indexDesc.getIndexName())) { logger.info("index_plan_info: Index {} is being discarded due to index Hint", indexDesc.getIndexName()); continue; FunctionalIndexInfo functionInfo = indexDesc.getFunctionalInfo(); selector.addIndex(indexDesc, IndexPlanUtils.isCoveringIndex(indexContext, functionInfo), indexContext.lowerProject != null ? indexContext.lowerProject.getRowType().getFieldCount() : strb.append("Covering indexes:"); for (IndexGroup index : coveringIndexes) { strb.append(index.getIndexProps().get(0).getIndexDesc().getIndexName()).append(", "); strb.append("Non-covering indexes:"); for (IndexGroup index : nonCoveringIndexes) { strb.append(index.getIndexProps().get(0).getIndexDesc().getIndexName()).append(", "); for (IndexGroup index : nonCoveringIndexes) { IndexDescriptor indexDesc = index.getIndexProps().get(0).getIndexDesc(); IndexGroupScan idxScan = indexDesc.getIndexGroupScan(); List<String> indices = new ArrayList<>(nonCoveringIndexes.size()); for (IndexGroup index : nonCoveringIndexes) { indices.add(index.getIndexProps().get(0).getIndexDesc().getIndexName()); IndexProperties indexProps = index.getIndexProps().get(0); IndexDescriptor indexDesc = indexProps.getIndexDesc(); IndexGroupScan idxScan = indexDesc.getIndexGroupScan(); FunctionalIndexInfo indexInfo = indexDesc.getFunctionalInfo();
IndexSelector selector = new IndexSelector(indexContext); for (IndexDescriptor indexDesc : indexCollection) { indexDesc.getIndexGroupScan().setStatistics(groupScan.getStatistics()); FunctionalIndexInfo functionInfo = indexDesc.getFunctionalInfo(); if (IndexPlanUtils.isCoveringIndex(indexContext, functionInfo)) { selector.addIndex(indexDesc, true, new CoveringPlanNoFilterGenerator(indexContext, idxProp.getIndexDesc().getFunctionalInfo(), false, settings); if (planGen.convertChild() != null) {
if (indexDesc.getCollation() == null) { return RelCollations.of(newFields); List<LogicalExpression> indexedCols = indexDesc.getIndexColumns(); for (int idxFieldCount=0; idxFieldCount<indexedCols.size(); ++idxFieldCount) { LogicalExpression expr = indexedCols.get(idxFieldCount); RelCollation idxCollation = indexDesc.getCollation(); RelFieldCollation.NullDirection nullsDir = idxCollation == null ? RelFieldCollation.NullDirection.UNSPECIFIED : idxCollation.getFieldCollations().get(idxFieldCount).nullDirection;
public static ScanPrel buildCoveringIndexScan(DrillScanRelBase origScan, IndexGroupScan indexGroupScan, IndexCallContext indexContext, IndexDescriptor indexDesc) { FunctionalIndexInfo functionInfo = indexDesc.getFunctionalInfo(); //to record the new (renamed)paths added List<SchemaPath> rewrittenPaths = Lists.newArrayList(); DbGroupScan dbGroupScan = (DbGroupScan) getGroupScan(origScan); indexGroupScan.setColumns( rewriteFunctionColumn(dbGroupScan.getColumns(), functionInfo, rewrittenPaths)); DrillDistributionTrait partition = scanIsPartition(getGroupScan(origScan))? DrillDistributionTrait.RANDOM_DISTRIBUTED : DrillDistributionTrait.SINGLETON; RelDataType newRowType = FunctionalIndexHelper.rewriteFunctionalRowType(origScan, indexContext, functionInfo, rewrittenPaths); // add a default collation trait otherwise Calcite runs into a ClassCastException, which at first glance // seems like a Calcite bug RelTraitSet indexScanTraitSet = origScan.getTraitSet().plus(Prel.DRILL_PHYSICAL). plus(RelCollationTraitDef.INSTANCE.getDefault()).plus(partition); // Create the collation traits for index scan based on the index columns under the // condition that the index actually has collation property (e.g hash indexes don't) if (indexDesc.getCollation() != null) { RelCollation collationTrait = buildCollationCoveringIndexScan(indexDesc, indexContext); indexScanTraitSet = indexScanTraitSet.plus(collationTrait); } ScanPrel indexScanPrel = new ScanPrel(origScan.getCluster(), indexScanTraitSet, indexGroupScan, newRowType, origScan.getTable()); return indexScanPrel; }
public boolean isValidIndexHint(IndexLogicalPlanCallContext indexContext) { if (indexContext.indexHint.equals("")) { return false; } for (IndexDescriptor index: indexes ) { if (indexContext.indexHint.equals(index.getIndexName())) { return true; } } return false; }
/** * Check if any of the fields of the index are present in a list of LogicalExpressions supplied * as part of IndexableExprMarker * @param exprMarker, the marker that has analyzed original index condition on top of original scan * @param indexDesc * @return 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 * */ static public ConditionIndexed conditionIndexed(IndexableExprMarker exprMarker, IndexDescriptor indexDesc) { Map<RexNode, LogicalExpression> mapRexExpr = exprMarker.getIndexableExpression(); List<LogicalExpression> infoCols = Lists.newArrayList(); infoCols.addAll(mapRexExpr.values()); if (indexDesc.allColumnsIndexed(infoCols)) { return ConditionIndexed.FULL; } else if (indexDesc.someColumnsIndexed(infoCols)) { return ConditionIndexed.PARTIAL; } else { return ConditionIndexed.NONE; } }
if (indexDesc.getCollation() != null && !settings.isIndexForceSortNonCovering()) { collation = IndexPlanUtils.buildCollationNonCoveringIndexScan(indexDesc, indexScanRowType, dbscanRowType, indexContext); if (indexDesc.isAsyncIndex()) { leftIndexFilterPrel = new FilterPrel(dbScan.getCluster(), dbScan.getTraitSet(), dbScan, indexContext.getOrigCondition());
@Override public IndexGroupScan getGroupScan() { return getIndexDescriptor().getIndexGroupScan(); }
@Override public boolean isColumnIndexed(SchemaPath path) { for (IndexDescriptor index : indexes) { if (index.getIndexColumnOrdinal(path) >= 0) { return true; } } return false; }
public RelOptCost getSelfCost(RelOptPlanner planner) { if (selfCost != null) { return selfCost; } selfCost = indexDescriptor.getCost(this, planner, numProjectedFields, IndexPlanUtils.getGroupScan(primaryTableScan)); return selfCost; }
/** * Abstract function getDrillTable will be implemented the IndexDiscover within storage plugin(e.g. HBase, MaprDB) * since the implementations of AbstractStoragePlugin, IndexDescriptor and DrillTable in that storage plugin may have * the implement details. * @param idxDesc * @return */ public DrillTable buildDrillTable(IndexDescriptor idxDesc) { if(idxDesc.getIndexType() == IndexDescriptor.IndexType.EXTERNAL_SECONDARY_INDEX) { return getExternalDrillTable(idxDesc); } else { return getNativeDrillTable(idxDesc); } }
final Map<LogicalExpression, RelFieldCollation> collationMap = indexDesc.getCollationMap();
/** * Get a single IndexConditionInfo in which indexCondition has field on all indexes in this.indexes * @return */ public IndexConditionInfo getCollectiveInfo(IndexLogicalPlanCallContext indexContext) { Set<LogicalExpression> paths = Sets.newLinkedHashSet(); for (IndexDescriptor index : indexes ) { paths.addAll(index.getIndexColumns()); //paths.addAll(index.getNonIndexColumns()); } return indexConditionRelatedToFields(Lists.newArrayList(paths), condition); }
Arrays.asList(SqlKind.CAST, SqlKind.LIKE)); RelDataType newRowType; FunctionalIndexInfo functionInfo = idx.getFunctionalInfo(); if (functionInfo.hasFunctional()) { newRowType = FunctionalIndexHelper.rewriteFunctionalRowType(scanRel, context, functionInfo); RexNode idxRemColCondition = IndexPlanUtils.getLeadingPrefixMap(leadingPrefixMap, idx.getIndexColumns(), infoBuilder, idxCondition); RexNode idxLeadColCondition = IndexPlanUtils.getLeadingColumnsFilter( IndexPlanUtils.getLeadingFilters(leadingPrefixMap, idx.getIndexColumns()), builder); RexNode idxTotRemColCondition = IndexPlanUtils.getTotalRemainderFilter(idxRemColCondition, idxIncColCondition, builder); RexNode idxTotColCondition = IndexPlanUtils.getTotalFilter(idxLeadColCondition, idxTotRemColCondition, builder); FunctionalIndexInfo functionInfo = idx.getFunctionalInfo(); RelDataType newRowType = scanRel.getRowType(); if (functionInfo.hasFunctional()) {
@Override public String buildUniqueIndexIdentifier(IndexDescriptor idx) { if (idx == null) { return null; } else { return idx.getTableName() + "_" + idx.getIndexName(); } }