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++; } } }
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);
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);
/** * 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); }
public RexNode remainderCondition(IndexDescriptor indexDesc, IndexConditionInfo.Builder builder, RexNode initCondition) { List<LogicalExpression> indexCols = indexDesc.getIndexColumns(); boolean prefix = true; if (indexCols.size() > 0 && initCondition != null) { int i=0; while (prefix && i < indexCols.size()) { LogicalExpression p = indexCols.get(i++); List<LogicalExpression> prefixCol = ImmutableList.of(p); IndexConditionInfo info = builder.indexConditionRelatedToFields(prefixCol, initCondition); if(info != null && info.hasIndexCol) { initCondition = info.remainderCondition; if (initCondition.isAlwaysTrue()) { // all filter conditions are accounted for, so if the remainder is TRUE, set it to NULL because // we don't need to keep track of it for rest of the index selection initCondition = null; break; } } else { prefix = false; } } } return initCondition; } }
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++; } } }
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);
List<LogicalExpression> indexCols = indexDesc.getIndexColumns(); boolean prefix = true; int numPrefix = 0;
leadingColumns.add(index.getIndexColumns().get(0)); IndexConditionInfo info = indexConditionRelatedToFields(leadingColumns, initCondition); if (info == null || info.hasIndexCol == false) {
private Map<IndexDescriptor, IndexConditionInfo> getIndexConditionMapInternal(List<IndexDescriptor> indexes) { Map<IndexDescriptor, IndexConditionInfo> indexInfoMap = Maps.newLinkedHashMap(); RexNode initCondition = condition; for (IndexDescriptor index : indexes) { if (initCondition.isAlwaysTrue()) { break; } if (!isConditionPrefix(index, initCondition)) { continue; } IndexConditionInfo info = indexConditionRelatedToFields(index.getIndexColumns(), initCondition); if (info == null || info.hasIndexCol == false) { continue; } initCondition = info.remainderCondition; indexInfoMap.put(index, info); } return indexInfoMap; }
leadingFilters = IndexPlanUtils.getLeadingFilters(leadingPrefixMap, indexDescriptor.getIndexColumns());
List<LogicalExpression> indexedCols = indexDesc.getIndexColumns(); for (int idxFieldCount=0; idxFieldCount<indexedCols.size(); ++idxFieldCount) { LogicalExpression expr = indexedCols.get(idxFieldCount);
/** * 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); }
for (LogicalExpression expr : indexInfo.getIndexDesc().getIndexColumns()) { if (!projectExprs.containsKey(expr)) { break;
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);