gianm commented on a change in pull request #8209: add mechanism to control filter optimization in historical query processing URL: https://github.com/apache/incubator-druid/pull/8209#discussion_r311788696
########## File path: processing/src/main/java/org/apache/druid/segment/filter/Filters.java ########## @@ -651,4 +652,31 @@ private static void generateAllCombinations( generateAllCombinations(result, andList.subList(1, andList.size()), nonAndList); } } + + /** + * This method provides a "standard" implementation of {@link Filter#shouldUseIndex(BitmapIndexSelector)} which takes + * a {@link Filter}, a {@link BitmapIndexSelector}, and {@link FilterTuning} to determine if: + * a) the filter supports bitmap indexes + * b) the filter tuning specifies that it should use the index + * c) the cardinality of the column is above the minimum threshold and below the maximum threshold to use the index + * + * If all these things are true, {@link org.apache.druid.segment.QueryableIndexStorageAdapter} will utilize the + * indexes. + */ + public static boolean shouldUseIndex( + Filter filter, + BitmapIndexSelector indexSelector, + @Nullable FilterTuning filterTuning + ) + { + final FilterTuning tuning = filterTuning != null ? filterTuning : FilterTuning.createDefault(filter, indexSelector); + if (filter.supportsBitmapIndex(indexSelector) && tuning.getUseIndex()) { + return filter.getRequiredColumns().stream().allMatch(column -> { + final int cardinality = indexSelector.getBitmapIndex(column).getCardinality(); Review comment: I think of those options the one that seems nicest to me is adding a sentence like this to Filter's `getRequiredColumns`: > If `#supportsBitmapIndex` returns true, all columns returned by this method can be expected to have a bitmap index retrievable via `BitmapIndexSelector#getBitmapIndex`. (And/or something equivalent in `supportsBitmapIndex`) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org