未验证 提交 80e6ad7a 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #20610 from ucasFL/fix-union-distinct-limit

fix subquery with limit
......@@ -784,9 +784,22 @@ static bool hasWithTotalsInAnySubqueryInFromClause(const ASTSelectQuery & query)
{
if (const auto * ast_union = query_table->as<ASTSelectWithUnionQuery>())
{
/// NOTE: Child of subquery can be ASTSelectWithUnionQuery or ASTSelectQuery,
/// and after normalization, the height of the AST tree is at most 2
for (const auto & elem : ast_union->list_of_selects->children)
if (hasWithTotalsInAnySubqueryInFromClause(elem->as<ASTSelectQuery &>()))
return true;
{
if (const auto * child_union = elem->as<ASTSelectWithUnionQuery>())
{
for (const auto & child_elem : child_union->list_of_selects->children)
if (hasWithTotalsInAnySubqueryInFromClause(child_elem->as<ASTSelectQuery &>()))
return true;
}
else
{
if (hasWithTotalsInAnySubqueryInFromClause(elem->as<ASTSelectQuery &>()))
return true;
}
}
}
}
......
SELECT x
FROM
(
SELECT 1 AS x
UNION DISTINCT
SELECT 1
)
LIMIT 1;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册