diff --git a/src/Interpreters/RedundantFunctionsInOrderByVisitor.h b/src/Interpreters/RedundantFunctionsInOrderByVisitor.h index 6e943c83c65..d737e877f01 100644 --- a/src/Interpreters/RedundantFunctionsInOrderByVisitor.h +++ b/src/Interpreters/RedundantFunctionsInOrderByVisitor.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace DB { @@ -75,7 +76,8 @@ public: static bool needChildVisit(const ASTPtr & node, const ASTPtr &) { - return node->as(); + /// Visit functions and their arguments, that are stored in ASTExpressionList. + return node->as() || node->as(); } }; diff --git a/tests/queries/0_stateless/01593_functions_in_order_by.reference b/tests/queries/0_stateless/01593_functions_in_order_by.reference new file mode 100644 index 00000000000..534b29af3e6 --- /dev/null +++ b/tests/queries/0_stateless/01593_functions_in_order_by.reference @@ -0,0 +1,14 @@ +SELECT + msg, + toDateTime(intDiv(ms, 1000)) AS time +FROM +( + SELECT + \'hello\' AS msg, + toUInt64(t) * 1000 AS ms + FROM generateRandom(\'t DateTime\') + LIMIT 10 +) +ORDER BY + msg ASC, + time ASC diff --git a/tests/queries/0_stateless/01593_functions_in_order_by.sql b/tests/queries/0_stateless/01593_functions_in_order_by.sql new file mode 100644 index 00000000000..2d38e45fff7 --- /dev/null +++ b/tests/queries/0_stateless/01593_functions_in_order_by.sql @@ -0,0 +1,11 @@ +EXPLAIN SYNTAX +SELECT msg, toDateTime(intDiv(ms, 1000)) AS time +FROM +( + SELECT + 'hello' AS msg, + toUInt64(t) * 1000 AS ms + FROM generateRandom('t DateTime') + LIMIT 10 +) +ORDER BY msg, time;