@@ -44,6 +44,14 @@ const ActionsDAG::Node & createRuntimeFilterCondition(ActionsDAG & actions_dag,
4444 return condition;
4545}
4646
47+ static bool supportsRuntimeFilter (JoinAlgorithm join_algorithm)
48+ {
49+ // / Runtime filter can only be applied to join algorithms that first read the right side and only after that read the left side.
50+ return
51+ join_algorithm == JoinAlgorithm::HASH ||
52+ join_algorithm == JoinAlgorithm::PARALLEL_HASH;
53+ }
54+
4755bool tryAddJoinRuntimeFilter (QueryPlan::Node & node, QueryPlan::Nodes & nodes, const QueryPlanOptimizationSettings & optimization_settings)
4856{
4957 // / Is this a join step?
@@ -57,12 +65,14 @@ bool tryAddJoinRuntimeFilter(QueryPlan::Node & node, QueryPlan::Nodes & nodes, c
5765
5866 // / Check if join can do runtime filtering on left table
5967 const auto & join_operator = join_step->getJoinOperator ();
68+ auto & join_algorithms = join_step->getJoinSettings ().join_algorithms ;
6069 const bool can_use_runtime_filter =
6170 (
6271 (join_operator.kind == JoinKind::Inner && (join_operator.strictness == JoinStrictness::All || join_operator.strictness == JoinStrictness::Any)) ||
6372 ((join_operator.kind == JoinKind::Left || join_operator.kind == JoinKind::Right) && join_operator.strictness == JoinStrictness::Semi)
6473 ) &&
65- (join_operator.locality == JoinLocality::Unspecified || join_operator.locality == JoinLocality::Local);
74+ (join_operator.locality == JoinLocality::Unspecified || join_operator.locality == JoinLocality::Local) &&
75+ std::find_if (join_algorithms.begin (), join_algorithms.end (), supportsRuntimeFilter) != join_algorithms.end ();
6676
6777 if (!can_use_runtime_filter)
6878 return false ;
@@ -183,6 +193,9 @@ bool tryAddJoinRuntimeFilter(QueryPlan::Node & node, QueryPlan::Nodes & nodes, c
183193
184194 node.children = {apply_filter_node, build_filter_node};
185195
196+ // / Remove algorithms that are not compatible with runtime filters
197+ std::erase_if (join_algorithms, [](auto join_algorithm) { return !supportsRuntimeFilter (join_algorithm); });
198+
186199 return true ;
187200}
188201
0 commit comments