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

Function explainQueryTree

src/Interpreters/InterpreterExplainQuery.cpp:556–622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554}
555
556bool explainQueryTree(
557 ASTPtr explained_query,
558 ContextPtr query_context,
559 const QueryTreeSettings & settings,
560 WriteBuffer & buf,
561 bool format_ast_as_syntax)
562{
563 if (explained_query->as<ASTSelectWithUnionQuery>() == nullptr)
564 return false;
565
566 auto query_tree = buildQueryTree(explained_query, query_context);
567 bool need_newline = false;
568
569 if (!query_context->getSettingsRef()[Setting::format_display_secrets_in_show_and_select])
570 {
571 TableFunctionSecretsVisitor visitor;
572 visitor.visit(query_tree);
573 }
574
575 if (settings.run_passes)
576 {
577 auto query_tree_pass_manager = QueryTreePassManager(query_context);
578 addQueryTreePasses(query_tree_pass_manager);
579
580 size_t pass_index = settings.passes < 0 ? query_tree_pass_manager.getPasses().size() : static_cast<size_t>(settings.passes);
581
582 if (settings.dump_passes)
583 {
584 query_tree_pass_manager.dump(buf, pass_index);
585 need_newline = true;
586 }
587
588 query_tree_pass_manager.run(query_tree, pass_index);
589 }
590
591 if (settings.dump_tree)
592 {
593 if (need_newline)
594 buf << "\n\n";
595
596 query_tree->dumpTree(buf);
597 need_newline = true;
598 }
599
600 if (settings.dump_ast)
601 {
602 if (need_newline)
603 buf << "\n\n";
604
605 IAST::FormatSettings format_settings(settings.ast_one_line);
606 format_settings.show_secrets = query_context->getSettingsRef()[Setting::format_display_secrets_in_show_and_select];
607
608 ConvertToASTOptions ast_options;
609 /// `EXPLAIN SYNTAX` shows the query in a canonical, close-to-syntax form, so constants are
610 /// rendered as their source expressions and function calls are preferred over operator syntax.
611 /// `EXPLAIN QUERY TREE` (dump_ast) must show the query as it actually is after the query tree passes,
612 /// so neither source-expression rendering nor operator-to-function conversion is applied there.
613 ast_options.use_source_expression_for_constants = format_ast_as_syntax;

Callers 1

executeImplMethod · 0.85

Calls 10

buildQueryTreeFunction · 0.85
addQueryTreePassesFunction · 0.85
visitMethod · 0.45
sizeMethod · 0.45
dumpMethod · 0.45
runMethod · 0.45
dumpTreeMethod · 0.45
formatMethod · 0.45
toASTMethod · 0.45

Tested by

no test coverage detected