mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
fix indirect distinct with less columns
This commit is contained in:
parent
9f5538c14d
commit
f4e84d93ba
@ -356,6 +356,7 @@ std::unordered_set<String> getDistinctNames(const ASTSelectQuery & select)
|
||||
|
||||
std::unordered_set<String> names;
|
||||
std::unordered_set<String> implicit_distinct;
|
||||
std::unordered_set<String> used_implicits;
|
||||
|
||||
if (!select.distinct)
|
||||
{
|
||||
@ -382,6 +383,9 @@ std::unordered_set<String> getDistinctNames(const ASTSelectQuery & select)
|
||||
names.insert(name);
|
||||
else
|
||||
names.insert(alias);
|
||||
|
||||
if (!select.distinct)
|
||||
used_implicits.insert(name);
|
||||
}
|
||||
}
|
||||
else if (select.distinct && !alias.empty())
|
||||
@ -391,6 +395,10 @@ std::unordered_set<String> getDistinctNames(const ASTSelectQuery & select)
|
||||
}
|
||||
}
|
||||
|
||||
/// SELECT a FROM (SELECT DISTINCT a, b FROM ...)
|
||||
if (!select.distinct && used_implicits.size() != implicit_distinct.size())
|
||||
return {};
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,18 @@ FROM
|
||||
FROM numbers(100)
|
||||
)
|
||||
)
|
||||
SELECT DISTINCT a
|
||||
FROM
|
||||
(
|
||||
SELECT a
|
||||
FROM
|
||||
(
|
||||
SELECT DISTINCT
|
||||
number % 2 AS a,
|
||||
number % 3 AS b
|
||||
FROM numbers(100)
|
||||
)
|
||||
)
|
||||
SELECT DISTINCT number
|
||||
FROM
|
||||
(
|
||||
|
@ -11,6 +11,7 @@ ANALYZE SELECT DISTINCT a FROM (SELECT DISTINCT a FROM (SELECT DISTINCT number %
|
||||
ANALYZE SELECT DISTINCT a FROM (SELECT DISTINCT a, b FROM (SELECT DISTINCT number % 2 AS a, number % 3 AS b FROM numbers(100)));
|
||||
ANALYZE SELECT DISTINCT a, b FROM (SELECT DISTINCT b, a FROM (SELECT DISTINCT number a, number b FROM numbers(1)));
|
||||
ANALYZE SELECT DISTINCT a, b FROM (SELECT b, a, a + b FROM (SELECT DISTINCT number % 2 AS a, number % 3 AS b FROM numbers(100)));
|
||||
ANALYZE SELECT DISTINCT a FROM (SELECT a FROM (SELECT DISTINCT number % 2 AS a, number % 3 AS b FROM numbers(100)));
|
||||
ANALYZE SELECT DISTINCT number FROM (SELECT DISTINCT number FROM numbers(1)) t1 CROSS JOIN numbers(2) t2;
|
||||
ANALYZE SELECT DISTINCT number FROM (SELECT DISTINCT number FROM numbers(1) t1 CROSS JOIN numbers(2) t2);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user