From 70612a6c718f1afbe501e83e148cbdafbb3fb142 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Fri, 27 Sep 2024 15:08:11 +0000 Subject: [PATCH] Backport #70054 to 24.9: Remove unused columns from actions in FilterStep. --- src/Processors/QueryPlan/FilterStep.cpp | 4 ++++ .../03245_views_and_filter_push_down_bug.reference | 1 + .../0_stateless/03245_views_and_filter_push_down_bug.sql | 1 + 3 files changed, 6 insertions(+) create mode 100644 tests/queries/0_stateless/03245_views_and_filter_push_down_bug.reference create mode 100644 tests/queries/0_stateless/03245_views_and_filter_push_down_bug.sql diff --git a/src/Processors/QueryPlan/FilterStep.cpp b/src/Processors/QueryPlan/FilterStep.cpp index 0c6b71387b7..ee770d1077c 100644 --- a/src/Processors/QueryPlan/FilterStep.cpp +++ b/src/Processors/QueryPlan/FilterStep.cpp @@ -51,6 +51,10 @@ FilterStep::FilterStep( , remove_filter_column(remove_filter_column_) { actions_dag.removeAliasesForFilter(filter_column_name); + /// Removing aliases may result in unneeded ALIAS node in DAG. + /// This should not be an issue by itself, + /// but it might trigger an issue with duplicated names in Block after plan optimizations. + actions_dag.removeUnusedActions(false, false); } void FilterStep::transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings & settings) diff --git a/tests/queries/0_stateless/03245_views_and_filter_push_down_bug.reference b/tests/queries/0_stateless/03245_views_and_filter_push_down_bug.reference new file mode 100644 index 00000000000..12442cadf31 --- /dev/null +++ b/tests/queries/0_stateless/03245_views_and_filter_push_down_bug.reference @@ -0,0 +1 @@ +1 2024-05-02 00:00:00 diff --git a/tests/queries/0_stateless/03245_views_and_filter_push_down_bug.sql b/tests/queries/0_stateless/03245_views_and_filter_push_down_bug.sql new file mode 100644 index 00000000000..be5f27b55de --- /dev/null +++ b/tests/queries/0_stateless/03245_views_and_filter_push_down_bug.sql @@ -0,0 +1 @@ +select * from view(select id, toDateTime(date) as date from view(select 1 as id, '2024-05-02' as date)) where date='2024-05-02';