From 7e5fc0d61dadde80ab655e5c847c57d9310e4531 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Mon, 13 May 2024 18:05:59 +0000 Subject: [PATCH] Fix #63653 --- src/Storages/VirtualColumnUtils.cpp | 9 ++++++--- .../0_stateless/01115_prewhere_array_join.reference | 1 + tests/queries/0_stateless/01115_prewhere_array_join.sql | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Storages/VirtualColumnUtils.cpp b/src/Storages/VirtualColumnUtils.cpp index e3cbff5f01b..cec55cefda2 100644 --- a/src/Storages/VirtualColumnUtils.cpp +++ b/src/Storages/VirtualColumnUtils.cpp @@ -219,7 +219,7 @@ void addRequestedPathFileAndSizeVirtualsToChunk( } } -static bool canEvaluateSubtree(const ActionsDAG::Node * node, const Block & allowed_inputs) +static bool canEvaluateSubtree(const ActionsDAG::Node * node, const Block * allowed_inputs) { std::stack nodes; nodes.push(node); @@ -228,7 +228,10 @@ static bool canEvaluateSubtree(const ActionsDAG::Node * node, const Block & allo const auto * cur = nodes.top(); nodes.pop(); - if (cur->type == ActionsDAG::ActionType::INPUT && !allowed_inputs.has(cur->result_name)) + if (cur->type == ActionsDAG::ActionType::ARRAY_JOIN) + return false; + + if (cur->type == ActionsDAG::ActionType::INPUT && allowed_inputs && !allowed_inputs->has(cur->result_name)) return false; for (const auto * child : cur->children) @@ -336,7 +339,7 @@ static const ActionsDAG::Node * splitFilterNodeForAllowedInputs( } } - if (allowed_inputs && !canEvaluateSubtree(node, *allowed_inputs)) + if (!canEvaluateSubtree(node, allowed_inputs)) return nullptr; return node; diff --git a/tests/queries/0_stateless/01115_prewhere_array_join.reference b/tests/queries/0_stateless/01115_prewhere_array_join.reference index e69de29bb2d..573541ac970 100644 --- a/tests/queries/0_stateless/01115_prewhere_array_join.reference +++ b/tests/queries/0_stateless/01115_prewhere_array_join.reference @@ -0,0 +1 @@ +0 diff --git a/tests/queries/0_stateless/01115_prewhere_array_join.sql b/tests/queries/0_stateless/01115_prewhere_array_join.sql index e614bdf402b..6ff86636d1d 100644 --- a/tests/queries/0_stateless/01115_prewhere_array_join.sql +++ b/tests/queries/0_stateless/01115_prewhere_array_join.sql @@ -5,3 +5,9 @@ INSERT INTO prewhere SELECT 0, randomPrintableASCII(10000) FROM numbers(10000); SELECT arrayJoin([light]) != 0 AS cond, length(heavy) FROM prewhere WHERE light != 0 AND cond != 0; DROP TABLE prewhere; + +DROP TABLE IF EXISTS testtable; +CREATE TABLE testtable (DT Datetime, Label1 String, Value UInt64) ENGINE = MergeTree() PARTITION BY DT ORDER BY Label1; +INSERT INTO testtable (*) Values (now(), 'app', 1); +SELECT arrayJoin([0, 1]) AS arrayIdx FROM testtable WHERE arrayIdx = 0; +DROP TABLE testtable;