mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Do not optimize any(arrayJoin()) -> arrayJoin() under optimize_move_functions_out_of_any
Otherwise the following query will be optimized incorrectly: SELECT *, any(arrayJoin([[], []])) FROM numbers(1) GROUP BY number And the result will be: ┌─number─┬─arrayJoin(array(array(), array()))─┐ │ 0 │ [] │ │ 0 │ [] │ └────────┴────────────────────────────────────┘ While should be: ┌─number─┬─any(arrayJoin(array(array(), array())))─┐ │ 0 │ [] │ └────────┴─────────────────────────────────────────┘
This commit is contained in:
parent
604b918d44
commit
17b27b6c28
@ -20,6 +20,21 @@ bool extractIdentifiers(const ASTFunction & func, std::unordered_set<ASTPtr *> &
|
||||
{
|
||||
if (const auto * arg_func = arg->as<ASTFunction>())
|
||||
{
|
||||
/// arrayJoin() is special and should not be optimized (think about
|
||||
/// it as a an aggregate function), otherwise wrong result will be
|
||||
/// produced:
|
||||
/// SELECT *, any(arrayJoin([[], []])) FROM numbers(1) GROUP BY number
|
||||
/// ┌─number─┬─arrayJoin(array(array(), array()))─┐
|
||||
/// │ 0 │ [] │
|
||||
/// │ 0 │ [] │
|
||||
/// └────────┴────────────────────────────────────┘
|
||||
/// While should be:
|
||||
/// ┌─number─┬─any(arrayJoin(array(array(), array())))─┐
|
||||
/// │ 0 │ [] │
|
||||
/// └────────┴─────────────────────────────────────────┘
|
||||
if (arg_func->name == "arrayJoin")
|
||||
return false;
|
||||
|
||||
if (arg_func->name == "lambda")
|
||||
return false;
|
||||
|
||||
|
@ -28,3 +28,5 @@ SELECT
|
||||
x
|
||||
FROM numbers(1, 2)
|
||||
6 6
|
||||
arrayJoin
|
||||
0 []
|
||||
|
@ -30,3 +30,6 @@ ANALYZE SELECT anyLast(number * 3) AS x, x FROM numbers(1, 2);
|
||||
SELECT anyLast(number * 3) AS x, x FROM numbers(1, 2);
|
||||
|
||||
SELECT any(anyLast(number)) FROM numbers(1); -- { serverError 184 }
|
||||
|
||||
SELECT 'arrayJoin';
|
||||
SELECT *, any(arrayJoin([[], []])) FROM numbers(1) GROUP BY number;
|
||||
|
Loading…
Reference in New Issue
Block a user