

**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 (const auto * function = group_exprs[i]->as<ASTFunction>())
        {
            
            if (possibly_injective_function_names.count(function->name))
            {
                
                if (function->arguments->children.size() < 2)
                {
                    ++i;
                    continue;
                }
                const auto * dict_name_ast = function->arguments->children[0]->as<ASTLiteral>();
                const auto * attr_name_ast = function->arguments->children[1]->as<ASTLiteral>();
                if (!dict_name_ast || !attr_name_ast)
                {
                    ++i;
                    continue;
                }
                const auto & dict_name = dict_name_ast->value.safeGet<String>();
                const auto & attr_name = attr_name_ast->value.safeGet<String>();
                const auto & dict_ptr = context->getExternalDictionariesLoader().getDictionary(dict_name, context);
                if (!dict_ptr->isInjective(attr_name))
                {
                    ++i;
                    continue;
                }
            }
            else if (!function_factory.get(function->name, context)->isInjective({}))
            {