**How to reproduce**
```
CREATE TABLE test_order_by (timestamp DateTime, key UInt32) ENGINE=MergeTree() PARTITION BY toYYYYMM(timestamp) ORDER BY (toDate(timestamp), key);
INSERT INTO test_order_by SELECT now() + toIntervalSecond(number), number % 4 FROM numbers(10000000);
OPTIMIZE TABLE test_order_by FINAL;
Q1: SELECT * FROM test_order_by ORDER BY timestamp LIMIT 10;
Q2: SELECT * FROM test_order_by ORDER BY toDate(timestamp) LIMIT 10;
Q3: SELECT * FROM test_order_by ORDER BY toDate(timestamp), timestamp LIMIT 10;

Q1 works the same on all versions of clickhouse.
Q1: 10 rows in set. Elapsed: 0.060 sec. Processed 10.00 million rows, 80.00 MB (166.87 million rows/s., 1.33 GB/s.)

Clickhouse 20.3.19
Q2: 10 rows in set. Elapsed: 0.013 sec. Processed 655.36 thousand rows, 5.24 MB (50.57 million rows/s., 404.54 MB/s.)
Q3: 10 rows in set. Elapsed: 0.034 sec. Processed 720.90 thousand rows, 5.77 MB (21.15 million rows/s., 169.23 MB/s.)
Clickhouse 20.4.2.9
Q2: Code: 15. DB::Exception: Received from localhost:9000. DB::Exception: Column 'toDate(timestamp)' already exists.
Q3: Code: 15. DB::Exception: Received from localhost:9000. DB::Exception: Column 'toDate(timestamp)' already exists.
Clickhouse 20.5.5.74
Q2: 10 rows in set. Elapsed: 0.020 sec. Processed 1.44 million rows, 11.53 MB (72.88 million rows/s., 583.04 MB/s.)
Q3: 10 rows in set. Elapsed: 0.013 sec. Processed 1.57 million rows, 12.58 MB (121.66 million rows/s., 973.31 MB/s.)
Clickhouse 20.6.8.5
Q2: 10 rows in set. Elapsed: 0.008 sec. Processed 1.05 million rows, 8.39 MB (131.13 million rows/s., 1.05 GB/s.)
Q3: 10 rows in set. Elapsed: 0.011 sec. Processed 1.11 million rows, 8.91 MB (105.19 million rows/s., 841.48 MB/s.)
Clickhouse 20.7.4.11
Q2: 10 rows in set. Elapsed: 0.008 sec. Processed 1.05 million rows, 8.38 MB (130.08 million rows/s., 1.04 GB/s.)
Q3: 10 rows in set. Elapsed: 0.012 sec. Processed 1.11 million rows, 8.91 MB (90.35 million rows/s., 722.80 MB/s.)
Clickhouse 20.8.4.11
Q2: 10 rows in set. Elapsed: 0.046 sec. Processed 10.00 million rows, 80.00 MB (215.31 million rows/s., 1.72 GB/s.)
Q3: 10 rows in set. Elapsed: 0.054 sec. Processed 10.00 million rows, 80.00 MB (185.84 million rows/s., 1.49 GB/s.)
Clickhouse 20.9.3
Q2: 10 rows in set. Elapsed: 0.055 sec. Processed 10.00 million rows, 80.00 MB (181.47 million rows/s., 1.45 GB/s.)
Q3: 10 rows in set. Elapsed: 0.040 sec. Processed 10.00 million rows, 80.00 MB (250.70 million rows/s., 2.01 GB/s.)


```
**Additional context**
It would be a good feature, of clickhouse will use optimize in order with monotonic functions without ORDER BY rewriting.
` SET optimize_monotonous_functions_in_order_by = 1` has no affect on that kind of queries.

const TablesWithColumns & tables, const Aliases & aliases)
{
    const ASTTablesInSelectQueryElement * node = select_query.join();
    if (!node)
        return;
    const auto & table_join = node->table_join->as<ASTTableJoin &>();
    if (table_join.using_expression_list)
    {
        const auto & keys = table_join.using_expression_list->as<ASTExpressionList &>();
        for (const auto & key : keys.children)
            analyzed_join.addUsingKey(key);
    }
    else if (table_join.on_expression)
    {
        bool is_asof = (table_join.strictness == ASTTableJoin::Strictness::Asof);
        CollectJoinOnKeysVisitor::Data data{analyzed_join, tables[0], tables[1], aliases, is_asof};
        CollectJoinOnKeysVisitor(data).visit(table_join.on_expression);
        if (!data.has_some)
            throw Exception("Cannot get JOIN keys from JOIN ON section: " + queryToString(table_join.on_expression),
                            ErrorCodes::INVALID_JOIN_ON_EXPRESSION);
        if (is_asof)
            data.asofToJoinKeys();
    }
}
std::vector<const ASTFunction *> getAggregates(ASTPtr & query, const ASTSelectQuery & select_query)