candidateDescs.add(prop.getIndexDesc()); candidateDescs.add(candidateIndexes.get(idx).getIndexProps().get(0).getIndexDesc()); Map<IndexDescriptor, IndexConditionInfo> intersectIdxInfoMap = infoBuilder.getIndexConditionMap(candidateDescs);
/** * This method analyzes an index's columns and starting from the first column, checks * which part of the filter condition matches that column. This process continues with * subsequent columns. The goal is to identify the portion of the filter condition that * match the prefix columns. If there are additional conditions that don't match prefix * columns, that condition is set as a remainder condition. * @param indexProps */ public void analyzePrefixMatches(IndexProperties indexProps) { RexNode initCondition = indexCondition.isAlwaysTrue() ? null : indexCondition; Map<LogicalExpression, RexNode> leadingPrefixMap = Maps.newHashMap(); List<LogicalExpression> indexCols = indexProps.getIndexDesc().getIndexColumns(); boolean satisfiesCollation = false; if (indexCols.size() > 0) { if (initCondition != null) { // check filter condition initCondition = IndexPlanUtils.getLeadingPrefixMap(leadingPrefixMap, indexCols, builder, indexCondition); } if (requiredCollation()) { satisfiesCollation = buildAndCheckCollation(indexProps); } } indexProps.setProperties(leadingPrefixMap, satisfiesCollation, initCondition /* the remainder condition for indexed columns */, stats); }
if (p.getLeadingSelectivity() > selThreshold) { logger.debug("Skipping index {}. The leading selectivity {} is larger than threshold {}", p.getIndexDesc().getIndexName(), p.getLeadingSelectivity(), selThreshold); logger.debug("index_plan_info: Skipping covering index {} because a higher ranked covering index with collation already exists.", indexProps.getIndexDesc().getIndexName()); continue; indexProps.getIndexDesc().getIndexName(), indexProps.satisfiesCollation(), indexProps.getLeadingSelectivity(), (foundCovering && !indexProps.satisfiesCollation())) { logger.debug("index_plan_info: Skipping non-covering index {} because it does not have collation and a higher ranked covering index already exists.", indexProps.getIndexDesc().getIndexName()); continue; indexProps.getIndexDesc().getIndexName(), indexProps.satisfiesCollation(), indexProps.getLeadingSelectivity(), isectLeadingSel *= indexProps.getLeadingSelectivity(); logger.info("name: {}, {}, collation: {}, leadingSelectivity: {}, cost: {}", indexProps.getIndexDesc().getIndexName(), isectName, indexProps.satisfiesCollation(),
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(", "); List<IndexDescriptor> indexList = Lists.newArrayList(); for (IndexGroup index : nonCoveringIndexes) { IndexDescriptor indexDesc = index.getIndexProps().get(0).getIndexDesc(); IndexGroupScan idxScan = indexDesc.getIndexGroupScan(); indexList.add(index.getIndexProps().get(0).getIndexDesc()); List<String> indices = new ArrayList<>(nonCoveringIndexes.size()); for (IndexGroup index : nonCoveringIndexes) { indices.add(index.getIndexProps().get(0).getIndexDesc().getIndexName()); List<IndexDescriptor> candidateDesc = Lists.newArrayList(); for (IndexProperties candProp : index.getIndexProps()) { candidateDesc.add(candProp.getIndexDesc()); for (IndexGroup index : coveringIndexes) { IndexProperties indexProps = index.getIndexProps().get(0); IndexDescriptor indexDesc = indexProps.getIndexDesc(); IndexGroupScan idxScan = indexDesc.getIndexGroupScan(); FunctionalIndexInfo indexInfo = indexDesc.getFunctionalInfo();
rightSideRows = leadRowCount; remFilters = remainderCondition(indexProps.getIndexDesc(), builder, remFilters);
new CoveringPlanNoFilterGenerator(indexContext, idxProp.getIndexDesc().getFunctionalInfo(), false, settings); if (planGen.convertChild() != null) {
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; }