| 1405 | } |
| 1406 | |
| 1407 | void JoinStepLogical::buildPhysicalJoin( |
| 1408 | QueryPlanNode & node, |
| 1409 | const QueryPlanOptimizationSettings & optimization_settings, |
| 1410 | QueryPlan::Nodes & nodes) |
| 1411 | { |
| 1412 | auto * join_step = typeid_cast<JoinStepLogical *>(node.step.get()); |
| 1413 | if (!join_step || node.children.empty()) |
| 1414 | { |
| 1415 | if (node.step) |
| 1416 | { |
| 1417 | const auto & step = *node.step; |
| 1418 | auto type_name = demangle(typeid(step).name()); |
| 1419 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Expected JoinStepLogical, got '{}' of type {} with {} children", node.step->getName(), type_name, node.children.size()); |
| 1420 | } |
| 1421 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Expected JoinStepLogical, got {}", !join_step ? "nullptr" : "empty children"); |
| 1422 | } |
| 1423 | |
| 1424 | UInt64 hash_table_key_hash = optimization_settings.collect_hash_table_stats_during_joins ? join_step->getRightHashTableCacheKey() : 0; |
| 1425 | |
| 1426 | if (!join_step->join_algorithm_params) |
| 1427 | { |
| 1428 | join_step->join_algorithm_params = std::make_unique<JoinAlgorithmParams>( |
| 1429 | join_step->join_settings, |
| 1430 | optimization_settings.max_threads, |
| 1431 | hash_table_key_hash, |
| 1432 | optimization_settings.max_entries_for_hash_table_stats, |
| 1433 | optimization_settings.initial_query_id, |
| 1434 | optimization_settings.lock_acquire_timeout); |
| 1435 | |
| 1436 | if (join_step->right_rows_estimation) |
| 1437 | join_step->join_algorithm_params->rhs_size_estimation = join_step->right_rows_estimation; |
| 1438 | |
| 1439 | if (hash_table_key_hash) |
| 1440 | { |
| 1441 | StatsCollectingParams params{ |
| 1442 | /*key_=*/hash_table_key_hash, |
| 1443 | /*enable=*/ optimization_settings.collect_hash_table_stats_during_joins, |
| 1444 | optimization_settings.max_entries_for_hash_table_stats, |
| 1445 | optimization_settings.max_size_to_preallocate_for_joins}; |
| 1446 | auto & hash_table_stats = getHashTablesStatistics<HashJoinEntry>(); |
| 1447 | if (auto hint = hash_table_stats.getSizeHint(params)) |
| 1448 | join_step->join_algorithm_params->rhs_size_estimation = hint->source_rows; |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | LogicalJoinInfo logical_join_info{ |
| 1453 | .readable_relation_name = join_step->getReadableRelationName(), |
| 1454 | .result_rows_estimation = join_step->result_rows_estimation, |
| 1455 | .locality = join_step->join_operator.locality |
| 1456 | }; |
| 1457 | |
| 1458 | auto new_node = buildPhysicalJoinImpl( |
| 1459 | node.children, |
| 1460 | join_step->join_operator, |
| 1461 | std::move(join_step->expression_actions), |
| 1462 | join_step->join_settings, |
| 1463 | *join_step->join_algorithm_params, |
| 1464 | join_step->sorting_settings, |
nothing calls this directly
no test coverage detected