#include #include #include #include #include #include #include #include #include #include namespace DB { BlockIO InterpreterExplainQuery::execute() { BlockIO res; res.in = executeImpl(); return res; } Block InterpreterExplainQuery::getSampleBlock() { Block block; ColumnWithTypeAndName col; col.name = "explain"; col.type = std::make_shared(); col.column = col.type->createColumn(); block.insert(col); return block; } BlockInputStreamPtr InterpreterExplainQuery::executeImpl() { const auto & ast = query->as(); Block sample_block = getSampleBlock(); MutableColumns res_columns = sample_block.cloneEmptyColumns(); std::stringstream ss; if (ast.getKind() == ASTExplainQuery::ParsedAST) { dumpAST(ast, ss); } else if (ast.getKind() == ASTExplainQuery::AnalyzedSyntax) { InterpreterSelectWithUnionQuery interpreter(ast.children.at(0), context, modify(analyze(SelectQueryOptions(QueryProcessingStage::FetchColumns)))); interpreter.getQuery()->format(IAST::FormatSettings(ss, false)); } res_columns[0]->insert(ss.str()); return std::make_shared(sample_block.cloneWithColumns(std::move(res_columns))); } }