From 77c143aa235ce4959d01a0c94ff24eb8c7ff56ee Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Mon, 1 Aug 2022 17:56:27 +0000 Subject: [PATCH] Fix extra column after ARRAY JOIN optimization. --- src/Interpreters/ActionsDAG.cpp | 3 +-- .../queries/0_stateless/01881_union_header_mismatch_bug.sql | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/ActionsDAG.cpp b/src/Interpreters/ActionsDAG.cpp index b91fd7ac5cf..3a2bc830cd5 100644 --- a/src/Interpreters/ActionsDAG.cpp +++ b/src/Interpreters/ActionsDAG.cpp @@ -1513,8 +1513,7 @@ ActionsDAG::SplitResult ActionsDAG::splitActionsBeforeArrayJoin(const NameSet & } auto res = split(split_nodes); - /// Do not remove array joined columns if they are not used. - /// res.first->project_input = false; + res.second->project_input = project_input; return res; } diff --git a/tests/queries/0_stateless/01881_union_header_mismatch_bug.sql b/tests/queries/0_stateless/01881_union_header_mismatch_bug.sql index 9a220ffd49f..bf8749fb046 100644 --- a/tests/queries/0_stateless/01881_union_header_mismatch_bug.sql +++ b/tests/queries/0_stateless/01881_union_header_mismatch_bug.sql @@ -28,3 +28,8 @@ WHERE number IN SELECT number FROM numbers(5) ) order by label, number; + +SELECT NULL FROM +(SELECT [1048575, NULL] AS ax, 2147483648 AS c) t1 ARRAY JOIN ax +INNER JOIN (SELECT NULL AS c) t2 USING (c); +