diff --git a/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp b/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp index d8ddeca636b..0cfdb7da0c5 100644 --- a/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp +++ b/src/Processors/QueryPlan/Optimizations/removeRedundantOrderBy.cpp @@ -171,8 +171,8 @@ private: chassert(typeid_cast(sorting_node->children.front()->step.get())); chassert(!sorting_node->children.front()->children.empty()); - /// need to remove sorting and its expression from plan - parent_node->children.front() = sorting_node->children.front()->children.front(); + /// need to remove sorting + parent_node->children.front() = sorting_node->children.front(); return true; } diff --git a/tests/queries/0_stateless/02496_remove_redundant_order_by.reference b/tests/queries/0_stateless/02496_remove_redundant_order_by.reference index 3bb23a2afd9..6ab3e963d5c 100644 --- a/tests/queries/0_stateless/02496_remove_redundant_order_by.reference +++ b/tests/queries/0_stateless/02496_remove_redundant_order_by.reference @@ -22,7 +22,7 @@ Expression (Project names) Header: number UInt64 Sorting (Sorting for ORDER BY) Header: number_0 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers))))))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))))))) Header: number_0 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -40,7 +40,7 @@ Header: number UInt64 Header: number_1 UInt64 Sorting (Sorting for ORDER BY) Header: number_1 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))) Header: number_1 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -57,7 +57,7 @@ Header: number UInt64 Header: number_1 UInt64 Sorting (Sorting for ORDER BY) Header: number_1 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))) Header: number_1 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -72,7 +72,7 @@ Header: t1.number UInt64 Header: t1.number_0 UInt64 Sorting (Sorting for ORDER BY) Header: number_2 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))) Header: number_2 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -80,7 +80,7 @@ Header: t1.number UInt64 Header: t2.number_1 UInt64 Sorting (Sorting for ORDER BY) Header: number_4 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))) Header: number_4 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -97,11 +97,11 @@ Header: t1.number UInt64 Join (JOIN FillRightFirst) Header: t1.number_0 UInt64 t2.number_1 UInt64 - Expression ((Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers))))))) + Expression ((Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))))) Header: t1.number_0 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 - Expression ((Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers))))))) + Expression ((Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))))) Header: t2.number_1 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -111,7 +111,7 @@ Header: sum(number) UInt64 Aggregating Header: number_0 UInt64 sum(number_0) UInt64 - Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))))) + Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers)))))))))) Header: number_0 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -125,7 +125,7 @@ Header: any(number) UInt64 Header: number_0 UInt64 Sorting (Sorting for ORDER BY) Header: number_1 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))) Header: number_1 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -140,7 +140,7 @@ Header: a UInt64 Aggregating Header: number_1 UInt64 sum(number_1) UInt64 - Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers))))) + Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers)))))) Header: number_1 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -174,7 +174,7 @@ Header: a UInt64 Header: number_1 UInt64 Sorting (Sorting for ORDER BY) Header: number_2 UInt64 - Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))) + Expression ((Before ORDER BY + (Projection + (Change column names to column identifiers + (Project names + (Before ORDER BY + (Projection + Change column names to column identifiers))))))) Header: number_2 UInt64 ReadFromStorage (SystemNumbers) Header: number UInt64 @@ -198,6 +198,7 @@ Expression (Project names) Expression (Projection) Expression (Change column names to column identifiers) Expression (Project names) - Expression (Projection) - Expression (Change column names to column identifiers) - ReadFromStorage (SystemNumbers) + Expression (Before ORDER BY) + Expression (Projection) + Expression (Change column names to column identifiers) + ReadFromStorage (SystemNumbers)