

**How to reproduce**

```sql
CREATE TABLE t_local
(
    `d` DateTime,
    `v` UInt32
)
ENGINE = MergeTree
ORDER BY toStartOfHour(d);

CREATE TABLE t_dist AS t_local
ENGINE = Distributed(test_shard_localhost, currentDatabase(), t_local);

INSERT INTO t_local VALUES (now(), 1);
```

```sql

EXPLAIN PIPELINE
SELECT v
FROM t_dist
ORDER BY
    toStartOfHour(d) ASC,
    v ASC
SETTINGS optimize_monotonous_functions_in_order_by = 0

┌─explain────────────────────────────┐
│ (SettingQuotaAndLimits)            │
│   (Expression)                     │
│   ExpressionTransform              │
│     (Sorting)                      │
│  -> FinishSortingTransform <-      │
│       PartialSortingTransform      │
│         (Expression)               │
│         ExpressionTransform        │
│           (SettingQuotaAndLimits)  │
│             (ReadFromMergeTree)    │
│             MergeTreeInOrder 0 → 1 │
└────────────────────────────────────┘

EXPLAIN PIPELINE
SELECT v
FROM t_dist
ORDER BY
    toStartOfHour(d) ASC,
    v ASC
SETTINGS optimize_monotonous_functions_in_order_by = 1

┌─explain──────────────────────────────┐
│ (SettingQuotaAndLimits)              │
│   (Expression)                       │
│   ExpressionTransform                │
│     (Sorting)                        │
│  -> MergeSortingTransform   <-            │
│       LimitsCheckingTransform        │
│         PartialSortingTransform      │
│           (Expression)               │
│           ExpressionTransform        │
│             (SettingQuotaAndLimits)  │
│               (ReadFromMergeTree)    │
│               MergeTreeInOrder 0 → 1 │
└──────────────────────────────────────┘

EXPLAIN SYNTAX
SELECT v
FROM t_dist
ORDER BY
    toStartOfHour(d) ASC,
    v ASC
SETTINGS optimize_monotonous_functions_in_order_by = 1

Query id: 1add8abb-1f3c-4f50-82df-cadcf162358d

┌─explain────────────────────────────────────────────────┐
│ SELECT v                                               │
│ FROM t_dist                                            │
│ ORDER BY                                               │
│     d ASC,                                             │
│     v ASC                                              │
│ SETTINGS optimize_monotonous_functions_in_order_by = 1 │
└────────────────────────────────────────────────────────┘
```
It happens, because `optimize_monotonous_functions_in_order_by` eliminates monotonous function from `ORDER BY`, while it is used for matching the prefix of primary key and `optimize_read_in_order` doesn't work.
{
    if (!select_query->join())
        return;
    const auto * table_join = select_query->join()->table_join->as<ASTTableJoin>();
    if (!(table_join && table_join->using_expression_list))
        return;
    ASTs & expression_list = table_join->using_expression_list->children;
    ASTs uniq_expressions_list;
    std::set<String> expressions_names;
    for (const auto & expression : expression_list)
    {
        auto expression_name = expression->getAliasOrColumnName();
        if (expressions_names.find(expression_name) == expressions_names.end())
        {
            uniq_expressions_list.push_back(expression);
            expressions_names.insert(expression_name);
        }
    }
    if (uniq_expressions_list.size() < expression_list.size())
        expression_list = uniq_expressions_list;
}
void optimizeAggregationFunctions(ASTPtr & query)
{
    
    ArithmeticOperationsInAgrFuncVisitor::Data data;
    ArithmeticOperationsInAgrFuncVisitor(data).visit(query);
}
void optimizeAnyFunctions(ASTPtr & query)