Skip to content

Commit

Permalink
Merge pull request #61591 from ClickHouse/backport/24.2/61458
Browse files Browse the repository at this point in the history
Backport #61458 to 24.2: fix issue of actions dag split
  • Loading branch information
robot-ch-test-poll1 committed Mar 19, 2024
2 parents 85d4cb1 + 8f8e0f8 commit ab4ba58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Processors/QueryPlan/Optimizations/liftUpFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const DB::DataStream & getChildOutputStream(DB::QueryPlan::Node & node)
namespace DB::QueryPlanOptimizations
{

/// This is a check that output columns does not have the same name
/// This is a check that nodes columns does not have the same name
/// This is ok for DAG, but may introduce a bug in a SotringStep cause columns are selected by name.
static bool areOutputsConvertableToBlock(const ActionsDAG::NodeRawConstPtrs & outputs)
static bool areNodesConvertableToBlock(const ActionsDAG::NodeRawConstPtrs & nodes)
{
std::unordered_set<std::string_view> names;
for (const auto & output : outputs)
for (const auto & node : nodes)
{
if (!names.emplace(output->result_name).second)
if (!names.emplace(node->result_name).second)
return false;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ size_t tryExecuteFunctionsAfterSorting(QueryPlan::Node * parent_node, QueryPlan:
if (unneeded_for_sorting->trivial())
return 0;

if (!areOutputsConvertableToBlock(needed_for_sorting->getOutputs()))
if (!areNodesConvertableToBlock(needed_for_sorting->getOutputs()) || !areNodesConvertableToBlock(unneeded_for_sorting->getInputs()))
return 0;

// Sorting (parent_node) -> Expression (child_node)
Expand Down
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/03010_view_prewhere_in.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1
2
3
17 changes: 17 additions & 0 deletions tests/queries/0_stateless/03010_view_prewhere_in.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DROP TABLE IF EXISTS v;
CREATE VIEW v (`date` UInt32,`value` UInt8) AS
WITH
data AS (SELECT '' id LIMIT 0),
r AS (SELECT'' as id, 1::UInt8 as value)
SELECT
now() as date,
value AND (data.id IN (SELECT '' as d from system.one)) AS value
FROM data
LEFT JOIN r ON data.id = r.id;

SELECT 1;
SELECT date, value FROM v;
SELECT 2;
SELECT date, value FROM v ORDER BY date;
SELECT 3;
DROP TABLE v;

0 comments on commit ab4ba58

Please sign in to comment.