2020-06-22 13:26:55 +00:00
|
|
|
#include <Parsers/ParserExplainQuery.h>
|
2020-12-04 02:15:44 +00:00
|
|
|
|
2020-06-22 13:26:55 +00:00
|
|
|
#include <Parsers/ASTExplainQuery.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
2020-12-04 02:15:44 +00:00
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
2020-06-22 13:26:55 +00:00
|
|
|
#include <Parsers/ParserSelectWithUnionQuery.h>
|
2021-09-03 17:29:36 +00:00
|
|
|
#include <Parsers/ParserInsertQuery.h>
|
2020-06-23 11:26:06 +00:00
|
|
|
#include <Parsers/ParserSetQuery.h>
|
2020-12-16 10:00:21 +00:00
|
|
|
#include <Parsers/ParserQuery.h>
|
2020-06-22 13:26:55 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
bool ParserExplainQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
ASTExplainQuery::ExplainKind kind;
|
|
|
|
|
|
|
|
ParserKeyword s_ast("AST");
|
|
|
|
ParserKeyword s_explain("EXPLAIN");
|
|
|
|
ParserKeyword s_syntax("SYNTAX");
|
2020-06-25 09:39:17 +00:00
|
|
|
ParserKeyword s_pipeline("PIPELINE");
|
2020-07-02 08:40:41 +00:00
|
|
|
ParserKeyword s_plan("PLAN");
|
2021-07-10 23:14:03 +00:00
|
|
|
ParserKeyword s_estimates("ESTIMATE");
|
2021-12-16 08:26:37 +00:00
|
|
|
ParserKeyword s_table_override("TABLE OVERRIDE");
|
2020-06-22 13:26:55 +00:00
|
|
|
|
2020-11-02 12:47:12 +00:00
|
|
|
if (s_explain.ignore(pos, expected))
|
2020-06-22 13:26:55 +00:00
|
|
|
{
|
|
|
|
kind = ASTExplainQuery::QueryPlan;
|
|
|
|
|
|
|
|
if (s_ast.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::ParsedAST;
|
|
|
|
else if (s_syntax.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::AnalyzedSyntax;
|
2020-06-25 09:39:17 +00:00
|
|
|
else if (s_pipeline.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::QueryPipeline;
|
2020-07-02 08:40:41 +00:00
|
|
|
else if (s_plan.ignore(pos, expected))
|
2021-05-08 16:09:17 +00:00
|
|
|
kind = ASTExplainQuery::ExplainKind::QueryPlan; //-V1048
|
2021-07-09 10:29:45 +00:00
|
|
|
else if (s_estimates.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::QueryEstimates; //-V1048
|
2021-12-16 08:26:37 +00:00
|
|
|
else if (s_table_override.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::TableOverride;
|
2020-06-22 13:26:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2020-11-02 12:47:12 +00:00
|
|
|
auto explain_query = std::make_shared<ASTExplainQuery>(kind);
|
2020-06-22 13:26:55 +00:00
|
|
|
|
2020-06-23 11:26:06 +00:00
|
|
|
{
|
|
|
|
ASTPtr settings;
|
|
|
|
ParserSetQuery parser_settings(true);
|
|
|
|
|
|
|
|
auto begin = pos;
|
|
|
|
if (parser_settings.parse(pos, settings, expected))
|
|
|
|
explain_query->setSettings(std::move(settings));
|
|
|
|
else
|
|
|
|
pos = begin;
|
|
|
|
}
|
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
ParserCreateTableQuery create_p;
|
2020-06-22 13:26:55 +00:00
|
|
|
ParserSelectWithUnionQuery select_p;
|
2021-09-03 17:29:36 +00:00
|
|
|
ParserInsertQuery insert_p(end);
|
2020-06-23 11:26:06 +00:00
|
|
|
ASTPtr query;
|
2020-12-16 10:00:21 +00:00
|
|
|
if (kind == ASTExplainQuery::ExplainKind::ParsedAST)
|
|
|
|
{
|
|
|
|
ParserQuery p(end);
|
|
|
|
if (p.parse(pos, query, expected))
|
|
|
|
explain_query->setExplainedQuery(std::move(query));
|
2021-06-23 12:29:10 +00:00
|
|
|
else
|
|
|
|
return false;
|
2020-12-16 10:00:21 +00:00
|
|
|
}
|
2021-12-16 08:26:37 +00:00
|
|
|
else if (kind == ASTExplainQuery::ExplainKind::TableOverride)
|
|
|
|
{
|
|
|
|
ASTPtr table_function;
|
|
|
|
if (!ParserFunction(true, true).parse(pos, table_function, expected))
|
|
|
|
return false;
|
|
|
|
ASTPtr table_override;
|
|
|
|
if (!ParserTableOverrideDeclaration(false).parse(pos, table_override, expected))
|
|
|
|
return false;
|
|
|
|
explain_query->setTableFunction(table_function);
|
|
|
|
explain_query->setTableOverride(table_override);
|
|
|
|
}
|
2020-12-16 10:00:21 +00:00
|
|
|
else if (select_p.parse(pos, query, expected) ||
|
2021-09-03 17:29:36 +00:00
|
|
|
create_p.parse(pos, query, expected) ||
|
|
|
|
insert_p.parse(pos, query, expected))
|
2020-12-04 02:15:44 +00:00
|
|
|
explain_query->setExplainedQuery(std::move(query));
|
|
|
|
else
|
2020-06-22 13:26:55 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
node = std::move(explain_query);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|