MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / explainPlan

Method explainPlan

src/Processors/QueryPlan/QueryPlan.cpp:332–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332JSONBuilder::ItemPtr QueryPlan::explainPlan(const ExplainPlanOptions & options) const
333{
334 checkInitialized();
335
336 struct Frame
337 {
338 Node * node = {};
339 size_t next_child = 0;
340 std::unique_ptr<JSONBuilder::JSONMap> node_map = {};
341 std::unique_ptr<JSONBuilder::JSONArray> children_array = {};
342 };
343
344 std::stack<Frame> stack;
345 stack.push(Frame{.node = root});
346
347 std::unique_ptr<JSONBuilder::JSONMap> tree;
348
349 while (!stack.empty())
350 {
351 auto & frame = stack.top();
352
353 if (frame.next_child == 0)
354 {
355 if (!frame.node->children.empty())
356 frame.children_array = std::make_unique<JSONBuilder::JSONArray>();
357
358 frame.node_map = std::make_unique<JSONBuilder::JSONMap>();
359 explainStep(*frame.node->step, *frame.node_map, options);
360 }
361
362 if (frame.next_child < frame.node->children.size())
363 {
364 stack.push(Frame{frame.node->children[frame.next_child]});
365 ++frame.next_child;
366 }
367 else
368 {
369 auto child_plans = frame.node->step->getChildPlans();
370
371 if (!frame.children_array && !child_plans.empty())
372 frame.children_array = std::make_unique<JSONBuilder::JSONArray>();
373
374 for (const auto & child_plan : child_plans)
375 frame.children_array->add(child_plan->explainPlan(options));
376
377 if (frame.children_array)
378 frame.node_map->add("Plans", std::move(frame.children_array));
379
380 tree.swap(frame.node_map);
381 stack.pop();
382
383 if (!stack.empty())
384 stack.top().children_array->add(std::move(tree));
385 }
386 }
387
388 return tree;
389}

Callers 8

dumpQueryPlanFunction · 0.80
getFilterFromQueryFunction · 0.80
explainPlanFunction · 0.80
debugExplainPlanFunction · 0.80
dumpQueryPlanShortFunction · 0.80
executeQueryImplFunction · 0.80
executeImplMethod · 0.80

Calls 15

checkInitializedFunction · 0.85
explainStepFunction · 0.85
buildPrettyNamesMapFunction · 0.85
PrettyColumnNameClass · 0.85
formatOutputColumnsFunction · 0.85
buildTreeOffsetFunction · 0.85
buildIndentOffsetFunction · 0.85
toStringFunction · 0.70
pushMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
getChildPlansMethod · 0.45

Tested by

no test coverage detected