Merge pull request #38910 from ClickHouse/explain_ast_after_rewrite

EXPLAIN AST rewrite option
This commit is contained in:
Igor Nikonov 2022-07-07 10:09:55 +02:00 committed by GitHub
commit 01bbfd86ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -146,12 +146,14 @@ namespace
struct QueryASTSettings
{
bool graph = false;
bool rewrite = false;
constexpr static char name[] = "AST";
std::unordered_map<std::string, std::reference_wrapper<bool>> boolean_settings =
{
{"graph", graph},
{"rewrite", rewrite}
};
};
@ -278,6 +280,12 @@ QueryPipeline InterpreterExplainQuery::executeImpl()
case ASTExplainQuery::ParsedAST:
{
auto settings = checkAndGetSettings<QueryASTSettings>(ast.getSettings());
if (settings.rewrite)
{
ExplainAnalyzedSyntaxVisitor::Data data(getContext());
ExplainAnalyzedSyntaxVisitor(data).visit(query);
}
if (settings.graph)
dumpASTInDotFormat(*ast.getExplainedQuery(), buf);
else

View File

@ -0,0 +1,25 @@
-- { echoOn }
EXPLAIN AST rewrite=0 SELECT * FROM numbers(0);
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
SelectQuery (children 2)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
Function numbers (children 1)
ExpressionList (children 1)
Literal UInt64_0
EXPLAIN AST rewrite=1 SELECT * FROM numbers(0);
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
SelectQuery (children 2)
ExpressionList (children 1)
Identifier number
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
Function numbers (children 1)
ExpressionList (children 1)
Literal UInt64_0

View File

@ -0,0 +1,4 @@
-- { echoOn }
EXPLAIN AST rewrite=0 SELECT * FROM numbers(0);
EXPLAIN AST rewrite=1 SELECT * FROM numbers(0);
-- { echoOff }