From 601d633690cc310b0109ef56aa5bf4eb9fc1afe6 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Fri, 27 Nov 2020 14:29:39 +0300 Subject: [PATCH] fix optimize_redundant_functions_in_order_by --- .../RedundantFunctionsInOrderByVisitor.h | 4 +++- .../01593_functions_in_order_by.reference | 14 ++++++++++++++ .../0_stateless/01593_functions_in_order_by.sql | 11 +++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/01593_functions_in_order_by.reference create mode 100644 tests/queries/0_stateless/01593_functions_in_order_by.sql 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;