| 963 | } |
| 964 | |
| 965 | void TableScanStep::rewriteDynamicFilter(SelectQueryInfo & select_query, const BuildQueryPipelineSettings & build_settings, bool use_expand_pipe) |
| 966 | { |
| 967 | if (select_query.partition_filter) |
| 968 | { |
| 969 | Stopwatch watch; |
| 970 | |
| 971 | auto [rf_filters, where_predicates] = RuntimeFilterUtils::extractRuntimeFilters(select_query.partition_filter); |
| 972 | std::vector<RuntimeFilterDescription> descriptions; |
| 973 | descriptions.reserve(rf_filters.size()); |
| 974 | for (const auto & predicate : rf_filters) |
| 975 | descriptions.emplace_back(RuntimeFilterUtils::extractDescription(predicate).value()); |
| 976 | |
| 977 | const auto & query_id = build_settings.distributed_settings.query_id; |
| 978 | const auto & setting = build_settings.context->getSettingsRef(); |
| 979 | size_t wait_ms = use_expand_pipe ? 0 : setting.wait_runtime_filter_timeout; |
| 980 | bool enable_bf_in_prewhere = setting.enable_rewrite_bf_into_prewhere; |
| 981 | bool enable_range_cover = setting.enable_range_cover; |
| 982 | for (auto & description : descriptions) |
| 983 | { |
| 984 | bool is_range_or_set = false; |
| 985 | bool has_bf = false; |
| 986 | auto runtime_filters = RuntimeFilterUtils::createRuntimeFilterForTableScan( |
| 987 | description, query_id, wait_ms, enable_bf_in_prewhere, enable_range_cover, is_range_or_set, has_bf); |
| 988 | where_predicates.insert(where_predicates.end(), runtime_filters.begin(), runtime_filters.end()); |
| 989 | } |
| 990 | auto where_dicates = PredicateUtils::combineConjuncts(where_predicates); |
| 991 | select_query.partition_filter = !PredicateUtils::isTruePredicate(where_dicates) ? std::move(where_dicates) : nullptr; |
| 992 | |
| 993 | LOG_DEBUG( |
| 994 | log, |
| 995 | "rewrite partition runtime filter done, cost:{} ms, query:{}", |
| 996 | watch.elapsedMilliseconds(), |
| 997 | select_query.partition_filter ? queryToString(*select_query.partition_filter) : "null"); |
| 998 | } |
| 999 | |
| 1000 | auto * query = select_query.query->as<ASTSelectQuery>(); |
| 1001 | auto where = query->getWhere(); |
| 1002 | auto prehwere = query->getPrewhere(); |
| 1003 | if (where || prehwere) |
| 1004 | { |
| 1005 | auto [rf_filters, where_predicates] = RuntimeFilterUtils::extractRuntimeFilters(where); |
| 1006 | auto [prewher_rf_filters, prewhere_predicates] = RuntimeFilterUtils::extractRuntimeFilters(prehwere); |
| 1007 | if (rf_filters.empty() && prewher_rf_filters.empty()) |
| 1008 | return; |
| 1009 | rf_filters.insert(rf_filters.end(), prewher_rf_filters.begin(), prewher_rf_filters.end()); |
| 1010 | |
| 1011 | std::vector<ConstASTPtr> tmp_prewhere_predicates; |
| 1012 | std::vector<RuntimeFilterDescription> descriptions; |
| 1013 | descriptions.reserve(rf_filters.size()); |
| 1014 | for (const auto & predicate : rf_filters) |
| 1015 | descriptions.emplace_back(RuntimeFilterUtils::extractDescription(predicate).value()); |
| 1016 | |
| 1017 | if (descriptions.empty()) |
| 1018 | return ; |
| 1019 | |
| 1020 | std::sort(descriptions.begin(), descriptions.end(), [](const auto & lhs, const auto & rhs) { |
| 1021 | return lhs.filter_factor > rhs.filter_factor; |
| 1022 | }); |
nothing calls this directly
no test coverage detected