fix optimize_redundant_functions_in_order_by

This commit is contained in:
Anton Popov 2020-11-27 14:29:39 +03:00
parent 85283b3944
commit 601d633690
3 changed files with 28 additions and 1 deletions

View File

@ -5,6 +5,7 @@
#include <Parsers/ASTIdentifier.h> #include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTOrderByElement.h> #include <Parsers/ASTOrderByElement.h>
#include <Parsers/ASTSelectQuery.h> #include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTExpressionList.h>
namespace DB namespace DB
{ {
@ -75,7 +76,8 @@ public:
static bool needChildVisit(const ASTPtr & node, const ASTPtr &) static bool needChildVisit(const ASTPtr & node, const ASTPtr &)
{ {
return node->as<ASTFunction>(); /// Visit functions and their arguments, that are stored in ASTExpressionList.
return node->as<ASTFunction>() || node->as<ASTExpressionList>();
} }
}; };

View File

@ -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

View File

@ -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;