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>
|
2022-04-26 09:24:24 +00:00
|
|
|
#include <Parsers/ParserSystemQuery.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");
|
2022-07-19 10:54:45 +00:00
|
|
|
ParserKeyword s_query_tree("QUERY TREE");
|
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");
|
2022-02-14 19:47:17 +00:00
|
|
|
ParserKeyword s_current_transaction("CURRENT TRANSACTION");
|
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;
|
2022-07-14 11:20:16 +00:00
|
|
|
else if (s_query_tree.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::QueryTree;
|
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))
|
2023-02-19 22:15:09 +00:00
|
|
|
kind = ASTExplainQuery::ExplainKind::QueryPlan;
|
2021-07-09 10:29:45 +00:00
|
|
|
else if (s_estimates.ignore(pos, expected))
|
2023-02-19 22:15:09 +00:00
|
|
|
kind = ASTExplainQuery::ExplainKind::QueryEstimates;
|
2021-12-16 08:26:37 +00:00
|
|
|
else if (s_table_override.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::TableOverride;
|
2022-02-14 19:47:17 +00:00
|
|
|
else if (s_current_transaction.ignore(pos, expected))
|
|
|
|
kind = ASTExplainQuery::ExplainKind::CurrentTransaction;
|
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;
|
2022-04-04 08:09:22 +00:00
|
|
|
ParserInsertQuery insert_p(end, allow_settings_after_format_in_insert);
|
2022-04-26 09:24:24 +00:00
|
|
|
ParserSystemQuery system_p;
|
2020-06-23 11:26:06 +00:00
|
|
|
ASTPtr query;
|
2020-12-16 10:00:21 +00:00
|
|
|
if (kind == ASTExplainQuery::ExplainKind::ParsedAST)
|
|
|
|
{
|
2022-04-04 08:09:22 +00:00
|
|
|
ParserQuery p(end, allow_settings_after_format_in_insert);
|
2020-12-16 10:00:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-08-23 09:50:02 +00:00
|
|
|
else if (kind == ASTExplainQuery::ExplainKind::QueryTree)
|
2022-07-14 11:20:16 +00:00
|
|
|
{
|
|
|
|
if (select_p.parse(pos, query, expected))
|
|
|
|
explain_query->setExplainedQuery(std::move(query));
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-14 19:47:17 +00:00
|
|
|
else if (kind == ASTExplainQuery::ExplainKind::CurrentTransaction)
|
|
|
|
{
|
|
|
|
/// Nothing to parse
|
|
|
|
}
|
2022-09-28 12:30:45 +00:00
|
|
|
else if (select_only)
|
|
|
|
{
|
|
|
|
if (select_p.parse(pos, query, expected))
|
|
|
|
explain_query->setExplainedQuery(std::move(query));
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
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) ||
|
2022-04-26 09:24:24 +00:00
|
|
|
insert_p.parse(pos, query, expected) ||
|
|
|
|
system_p.parse(pos, query, expected))
|
2022-09-28 12:30:45 +00:00
|
|
|
{
|
2020-12-04 02:15:44 +00:00
|
|
|
explain_query->setExplainedQuery(std::move(query));
|
2022-09-28 12:30:45 +00:00
|
|
|
}
|
2020-12-04 02:15:44 +00:00
|
|
|
else
|
2022-07-14 11:20:16 +00:00
|
|
|
{
|
2020-06-22 13:26:55 +00:00
|
|
|
return false;
|
2022-07-14 11:20:16 +00:00
|
|
|
}
|
2020-06-22 13:26:55 +00:00
|
|
|
|
|
|
|
node = std::move(explain_query);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|