From 919fa9b84e2726cdebe9eed71441764c2cd7597f Mon Sep 17 00:00:00 2001 From: Igor Nikonov Date: Wed, 21 Dec 2022 12:55:42 +0000 Subject: [PATCH] If aggregation step is in order, - do not remove underneath sorting step --- .../QueryPlan/Optimizations/removeRedundantOrderBy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp b/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp index 10a8c2e5143..e4ad11bc529 100644 --- a/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp +++ b/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp @@ -219,6 +219,9 @@ private: /// (1) aggregation if (const AggregatingStep * parent_aggr = typeid_cast(step_affect_order); parent_aggr) { + if (parent_aggr->inOrder()) + return false; + auto const & aggregates = parent_aggr->getParams().aggregates; for (const auto & aggregate : aggregates) {