MCPcopy Create free account
hub / github.com/ByConity/ByConity / explainUsingOptimizer

Method explainUsingOptimizer

src/Interpreters/InterpreterExplainQuery.cpp:647–713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647BlockInputStreamPtr InterpreterExplainQuery::explainUsingOptimizer()
648{
649 WriteBufferFromOwnString buffer;
650 bool single_line = false;
651 const auto & explain = query->as<ASTExplainQuery &>();
652 auto context = getContext();
653
654 if (explain.getKind() == ASTExplainQuery::AnalyzedSyntax)
655 {
656 if (explain.getSettings())
657 throw Exception("Settings are not supported for EXPLAIN SYNTAX query.", ErrorCodes::UNKNOWN_SETTING);
658
659 auto query_ptr = explain.getExplainedQuery();
660 query_ptr = QueryRewriter().rewrite(query_ptr, context);
661 query_ptr->format(IAST::FormatSettings(buffer, false));
662 }
663 else if (explain.getKind() == ASTExplainQuery::TraceOptimizer || explain.getKind() == ASTExplainQuery::TraceOptimizerRule)
664 {
665 if (explain.getSettings())
666 throw Exception("Settings are not supported for EXPLAIN TRACE OPTIMIZER query.", ErrorCodes::UNKNOWN_SETTING);
667
668 context->initOptimizerProfile();
669 try
670 {
671 InterpreterSelectQueryUseOptimizer interpreter(explain.getExplainedQuery(), context, SelectQueryOptions());
672 interpreter.getPlanSegment();
673 }
674 catch (...)
675 {
676 context->clearOptimizerProfile();
677 throw;
678 }
679
680 if (explain.getKind() == ASTExplainQuery::TraceOptimizerRule)
681 buffer << context->getOptimizerProfile(true);
682 else
683 buffer << context->getOptimizerProfile();
684 }
685 else
686 {
687 InterpreterSelectQueryUseOptimizer interpreter(explain.getExplainedQuery(), context, SelectQueryOptions());
688 auto query_plan = interpreter.getQueryPlan();
689 if (explain.getKind() == ASTExplainQuery::ExplainKind::OptimizerPlan
690 || explain.getKind() == ASTExplainQuery::ExplainKind::QueryPlan)
691 {
692 explainPlanWithOptimizer(explain, *query_plan, buffer, context, single_line);
693 }
694 else if (explain.getKind() == ASTExplainQuery::ExplainKind::Distributed)
695 {
696 explainDistributedWithOptimizer(explain, *query_plan, buffer, context);
697 }
698 else if (explain.getKind() == ASTExplainQuery::ExplainKind::QueryPipeline)
699 {
700 explainPipelineWithOptimizer(explain, *query_plan, buffer, context);
701 }
702 }
703
704 Block sample_block = getSampleBlock();

Callers

nothing calls this directly

Calls 15

QueryRewriterClass · 0.85
initOptimizerProfileMethod · 0.80
clearOptimizerProfileMethod · 0.80
cloneWithColumnsMethod · 0.80
ExceptionClass · 0.70
SelectQueryOptionsClass · 0.70
FormatSettingsClass · 0.50
getKindMethod · 0.45
getSettingsMethod · 0.45
rewriteMethod · 0.45
formatMethod · 0.45
getPlanSegmentMethod · 0.45

Tested by

no test coverage detected