diff --git a/src/Planner/PlannerJoinTree.cpp b/src/Planner/PlannerJoinTree.cpp index 9a30ee689fd..a710aa3946d 100644 --- a/src/Planner/PlannerJoinTree.cpp +++ b/src/Planner/PlannerJoinTree.cpp @@ -1407,7 +1407,10 @@ std::tuple buildJoinQueryPlan( set_used_column_with_duplicates(columns_from_right_table, JoinTableSide::Right); } - auto join_algorithm = chooseJoinAlgorithm(table_join, right_table_expression, left_header, right_header, planner_context, select_query_info); + trySetStorageInTableJoin(right_table_expression, table_join); + auto prepared_join_storage = tryGetStorageInTableJoin(right_table_expression, planner_context); + auto hash_table_stat_cache_key = preCalculateCacheKey(right_table_expression, select_query_info); + auto join_algorithm = chooseJoinAlgorithm(table_join, prepared_join_storage, left_header, right_header, planner_context->getQueryContext(), std::move(hash_table_stat_cache_key)); auto result_plan = QueryPlan(); bool is_filled_join = join_algorithm->isFilled(); diff --git a/src/Planner/PlannerJoinsLogical.cpp b/src/Planner/PlannerJoinsLogical.cpp index adcf4d299fe..c0a7d5b6038 100644 --- a/src/Planner/PlannerJoinsLogical.cpp +++ b/src/Planner/PlannerJoinsLogical.cpp @@ -394,6 +394,8 @@ PreparedJoinStorage tryGetStorageInTableJoin(const QueryTreeNodePtr & table_expr storage = table_node->getStorage(); else if (auto * table_function = table_expression->as()) storage = table_function->getStorage(); + else + return {}; PreparedJoinStorage result; const auto & table_expression_data = planner_context->getTableExpressionDataOrThrow(table_expression);