**How to reproduce**

Query:
```sql
select
	x,
	min(x) as lower,
	max(x)+1 as upper,
	upper-lower as range
from (select arrayJoin([1, 2]) as x)
group by x
with rollup;
```

## 20.4.6
```
┌─x─┬─lower─┬─upper─┬─range─┐
│ 1 │     1 │     2 │     1 │
│ 2 │     2 │     3 │     1 │
└───┴───────┴───────┴───────┘
┌─x─┬─lower─┬─upper─┬─range─┐
│ 0 │     1 │     3 │     2 │
└───┴───────┴───────┴───────┘
```
Summary looks correct.

## 20.9.3
```
┌─x─┬─lower─┬─upper─┬─range─┐
│ 1 │     1 │     2 │     1 │
│ 2 │     2 │     3 │     1 │
└───┴───────┴───────┴───────┘
┌─x─┬─lower─┬─upper─┬─range─┐
│ 0 │     0 │     3 │     2 │
└───┴───────┴───────┴───────┘
```
`lower` is wrong - the minimum should be 1. However, all other "derived" values are correct. For example `range` correctly shows up as 2, even though table would wrongly imply that `upper-lower==3-0==3`.
Note that I only tested 20.4.6 and 20.9.3, so the regression might have been anywhere in between.

## 20.10.2
```
┌─x─┬─lower─┬─upper─┬─range─┐
│ 1 │     1 │     2 │     1 │
│ 2 │     2 │     3 │     1 │
└───┴───────┴───────┴───────┘
┌─x─┬─lower─┬─upper─┬─range─┐
│ 0 │     0 │     1 │     1 │
└───┴───────┴───────┴───────┘
```
All values are wrong.
{
    const auto & order_by = select_query->orderBy();
    if (!order_by)
        return;
    std::unordered_set<String> prev_keys;
    ASTs modified;
    modified.reserve(order_by->children.size());
    for (auto & order_by_element : order_by->children)
    {
        
        ASTPtr & name_or_function = order_by_element->children[0];
        if (name_or_function->as<ASTFunction>())
        {
            if (!prev_keys.empty())
            {
                RedundantFunctionsInOrderByVisitor::Data data{prev_keys, context};
                RedundantFunctionsInOrderByVisitor(data).visit(name_or_function);
                if (data.redundant)
                    continue;
            }
        }
        
        if (auto * identifier = name_or_function->as<ASTIdentifier>())
            prev_keys.emplace(getIdentifierName(identifier));
        modified.push_back(order_by_element);
    }
    if (modified.size() < order_by->children.size())
        order_by->children = std::move(modified);
}
void optimizeLimitBy(const ASTSelectQuery * select_query)