Fix viewExplain, add testcases

This commit is contained in:
vdimir 2023-01-13 12:19:25 +00:00
parent bdb9222736
commit f881a82417
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
4 changed files with 22 additions and 2 deletions

View File

@ -123,8 +123,8 @@ bool ParserSubquery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (explain_query.getTableFunction() || explain_query.getTableOverride())
throw Exception("EXPLAIN in a subquery cannot have a table function or table override", ErrorCodes::BAD_ARGUMENTS);
/// Replace `SELECT * FROM (EXPLAIN <kind> <explain_settings> SELECT ...)`
/// with `SELECT * FROM viewExplain("<kind>", "<explain_settings>", SELECT ...)`
/// Replace subquery `(EXPLAIN <kind> <explain_settings> SELECT ...)`
/// with `(SELECT * FROM viewExplain("<kind>", "<explain_settings>", SELECT ...))`
String kind_str = ASTExplainQuery::toString(explain_query.getKind());

View File

@ -69,6 +69,10 @@ void TableFunctionExplain::parseArguments(const ASTPtr & ast_function, ContextPt
getName(), queryToString(query_arg));
explain_query->setExplainedQuery(query_arg);
}
else if (kind != ASTExplainQuery::ExplainKind::CurrentTransaction)
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function '{}' requires a query argument", getName());
}
query = std::move(explain_query);
}

View File

@ -12,3 +12,5 @@
1
1
1
1
1

View File

@ -17,6 +17,13 @@ SELECT * FROM (
)
) FORMAT Null;
SELECT (EXPLAIN SYNTAX oneline = 1 SELECT 1) == 'SELECT 1';
SELECT * FROM viewExplain('', ''); -- { serverError BAD_ARGUMENTS }
SELECT * FROM viewExplain('EXPLAIN AST', ''); -- { serverError BAD_ARGUMENTS }
SELECT * FROM viewExplain('EXPLAIN AST', '', 1); -- { serverError BAD_ARGUMENTS }
SELECT * FROM viewExplain('EXPLAIN AST', '', ''); -- { serverError BAD_ARGUMENTS }
CREATE TABLE t1 ( a UInt64 ) Engine = MergeTree ORDER BY tuple() AS SELECT number AS a FROM system.numbers LIMIT 100000;
SELECT rows > 1000 FROM (EXPLAIN ESTIMATE SELECT sum(a) FROM t1);
@ -68,4 +75,11 @@ SELECT * FROM (
)
) FORMAT Null;
SELECT (EXPLAIN SYNTAX oneline = 1 SELECT 1) == 'SELECT 1 FROM system.one';
SELECT * FROM viewExplain('', ''); -- { serverError BAD_ARGUMENTS }
SELECT * FROM viewExplain('EXPLAIN AST', ''); -- { serverError BAD_ARGUMENTS }
SELECT * FROM viewExplain('EXPLAIN AST', '', 1); -- { serverError BAD_ARGUMENTS }
SELECT * FROM viewExplain('EXPLAIN AST', '', ''); -- { serverError BAD_ARGUMENTS }
-- EXPLAIN ESTIMATE is not supported in experimental analyzer