| 338 | |
| 339 | |
| 340 | void executeQuery( |
| 341 | QueryPlan & query_plan, |
| 342 | SharedHeader header, |
| 343 | QueryProcessingStage::Enum processed_stage, |
| 344 | const StorageID & main_table, |
| 345 | const ASTPtr & table_func_ptr, |
| 346 | SelectStreamFactory & stream_factory, |
| 347 | LoggerPtr log, |
| 348 | ContextPtr context, |
| 349 | const SelectQueryInfo & query_info, |
| 350 | const ExpressionActionsPtr & sharding_key_expr, |
| 351 | const std::string & sharding_key_column_name, |
| 352 | const DistributedSettings & distributed_settings, |
| 353 | AdditionalShardFilterGenerator shard_filter_generator, |
| 354 | bool is_remote_function) |
| 355 | { |
| 356 | const Settings & settings = context->getSettingsRef(); |
| 357 | |
| 358 | if (settings[Setting::max_distributed_depth] && context->getClientInfo().distributed_depth >= settings[Setting::max_distributed_depth]) |
| 359 | throw Exception(ErrorCodes::TOO_LARGE_DISTRIBUTED_DEPTH, "Maximum distributed depth exceeded"); |
| 360 | |
| 361 | const ClusterPtr & not_optimized_cluster = query_info.cluster; |
| 362 | |
| 363 | std::vector<QueryPlanPtr> plans; |
| 364 | SelectStreamFactory::Shards remote_shards; |
| 365 | |
| 366 | auto cluster = query_info.getCluster(); |
| 367 | auto new_context = updateSettingsAndClientInfoForCluster(*cluster, is_remote_function, context, |
| 368 | settings, main_table, query_info.additional_filter_ast, log, &distributed_settings); |
| 369 | if (context->getSettingsRef()[Setting::allow_experimental_parallel_reading_from_replicas].value |
| 370 | && context->getSettingsRef()[Setting::allow_experimental_parallel_reading_from_replicas].value |
| 371 | != new_context->getSettingsRef()[Setting::allow_experimental_parallel_reading_from_replicas].value) |
| 372 | { |
| 373 | LOG_TRACE( |
| 374 | log, |
| 375 | "Parallel reading from replicas is disabled for cluster. There are no shards with more than 1 replica: cluster={}", |
| 376 | cluster->getName()); |
| 377 | } |
| 378 | |
| 379 | new_context->increaseDistributedDepth(); |
| 380 | |
| 381 | const size_t shards = cluster->getShardCount(); |
| 382 | ProfileEvents::increment(ProfileEvents::Shards, shards); |
| 383 | |
| 384 | /// Tracker is shared between local-missing-table skip path in SelectStreamFactory and |
| 385 | /// remote unavailable-shard skip path in ReadFromRemote so max_skip_unavailable_shards_num |
| 386 | /// and max_skip_unavailable_shards_ratio are enforced uniformly across both paths. |
| 387 | UnavailableShardTrackerPtr unavailable_shard_tracker; |
| 388 | { |
| 389 | const auto & new_settings_ref = new_context->getSettingsRef(); |
| 390 | if (new_settings_ref[Setting::skip_unavailable_shards]) |
| 391 | { |
| 392 | size_t max_num = new_settings_ref[Setting::max_skip_unavailable_shards_num]; |
| 393 | Float64 max_ratio = static_cast<double>(new_settings_ref[Setting::max_skip_unavailable_shards_ratio]); |
| 394 | if (max_num > 0 || max_ratio > 0) |
| 395 | unavailable_shard_tracker = std::make_shared<UnavailableShardTracker>(shards, max_num, max_ratio); |
| 396 | } |
| 397 | } |
no test coverage detected