| 267 | } |
| 268 | |
| 269 | QueryPipelinePtr QueryPlan::buildQueryPipeline( |
| 270 | const QueryPlanOptimizationSettings & optimization_settings, const BuildQueryPipelineSettings & build_pipeline_settings) |
| 271 | { |
| 272 | checkInitialized(); |
| 273 | |
| 274 | if (!optimization_settings.enable_optimizer) |
| 275 | { |
| 276 | optimize(optimization_settings); |
| 277 | } |
| 278 | |
| 279 | struct Frame |
| 280 | { |
| 281 | Node * node = {}; |
| 282 | QueryPipelines pipelines = {}; |
| 283 | }; |
| 284 | |
| 285 | QueryPipelinePtr last_pipeline; |
| 286 | |
| 287 | std::stack<Frame> stack; |
| 288 | stack.push(Frame{.node = root}); |
| 289 | Stopwatch watch; |
| 290 | while (!stack.empty()) |
| 291 | { |
| 292 | auto & frame = stack.top(); |
| 293 | |
| 294 | if (last_pipeline) |
| 295 | { |
| 296 | frame.pipelines.emplace_back(std::move(last_pipeline)); |
| 297 | last_pipeline = nullptr; //-V1048 |
| 298 | } |
| 299 | |
| 300 | size_t next_child = frame.pipelines.size(); |
| 301 | if (next_child == frame.node->children.size()) |
| 302 | { |
| 303 | bool limit_max_threads = frame.pipelines.empty(); |
| 304 | try |
| 305 | { |
| 306 | last_pipeline = frame.node->step->updatePipeline(std::move(frame.pipelines), build_pipeline_settings); |
| 307 | updatePipelineStepInfo(last_pipeline, frame.node->step, frame.node->id); |
| 308 | } |
| 309 | catch (const Exception & e) /// Typical for an incorrect username, password, or address. |
| 310 | { |
| 311 | LOG_ERROR(log, "Build pipeline error {}", e.what()); |
| 312 | throw; |
| 313 | } |
| 314 | // #ifndef NDEBUG |
| 315 | // if (optimization_settings.enable_optimizer) |
| 316 | // { |
| 317 | // const auto & output_header = frame.node->step->getOutputStream().header; |
| 318 | // const auto & pipeline_header = last_pipeline->getHeader(); |
| 319 | // assertBlocksHaveEqualStructure( |
| 320 | // output_header, |
| 321 | // pipeline_header, |
| 322 | // "QueryPlan::buildQueryPipeline for " + frame.node->step->getName() + " (output header, pipeline header)"); |
| 323 | // } |
| 324 | // #endif |
| 325 | |
| 326 | if (limit_max_threads && max_threads) |
no test coverage detected