Hello, there. Run into the problem with DISTINCT expression. It works incorrectly on the main query if it was already applied to one of the subqueries bond with UNION ALL.

**How to reproduce**
Server version: 20.5.4.40. 19.17.6.36 was free of the bug.
Using Datagrip for running queries.
Non-default settings:
```
input_format_defaults_for_omitted_fields: 1
decimal_check_overflow: 0
joined_subquery_requires_alias: 0
```

Consider following query
```
select distinct number
from ((select number from numbers(10)) union all (select number from numbers(20)));
```
It works fine, returning 20 rows as expected.

But if we add distinct to subqueries (it doesn't matter to the first, the second or both)
```
select distinct number
from ((select distinct number from numbers(10)) union all (select distinct number from numbers(20)));
```

Then in 20.5.4.40 we'll see 30 rows with numbers from 0 to 9 duplicated.
However, `count(distinct number)` returns the correct number of rows.

modified.push_back(group_key);
            continue;
        }
        if (auto * group_key_ident = group_key->as<ASTIdentifier>())
        {
            if (group_by_keys_data.key_names.count(group_key_ident->shortName()))
                modified.push_back(group_key);
            continue;
        }
        else
        {
            if (group_by_keys_data.key_names.count(group_key->getColumnName()))
                modified.push_back(group_key);
        }
    }
    
    grp_by->children = modified;
}
void optimizeAggregateFunctionsOfGroupByKeys(ASTSelectQuery * select_query)
{
    if (!select_query->groupBy())
        return;
    auto grp_by = select_query->groupBy();
    auto & group_keys = grp_by->children;
    GroupByKeysInfo group_by_keys_data = getGroupByKeysInfo(group_keys);
    auto select = select_query->select();
    SelectAggregateFunctionOfGroupByKeysVisitor::Data visitor_data{group_by_keys_data.key_names};
    SelectAggregateFunctionOfGroupByKeysVisitor(visitor_data).visit(select);
}
void optimizeDuplicatesInOrderBy(const ASTSelectQuery * select_query)