```sql
SELECT toStartOfHour(time) AS timex, id, count()
FROM
(
    SELECT
        concat('id', toString(number % 3)) AS id,
        toDateTime('2020-01-01') + (number * 60) AS time
    FROM numbers(100)
)
GROUP BY
    GROUPING SETS ( (timex, id), (timex))
ORDER BY timex ASC;

Received exception from server (version 22.5.1):
Code: 215. DB::Exception: Received from localhost:9000. 
DB::Exception: Column `time` is not under aggregate function and not in GROUP BY: 
While processing time ASC. (NOT_AN_AGGREGATE)
```
{
    if (!select_query->groupBy())
        return;
    auto group_by = select_query->groupBy();
    const auto & group_by_keys = group_by->children;
    ASTs modified; 
    GroupByKeysInfo group_by_keys_data = getGroupByKeysInfo(group_by_keys);
    if (!group_by_keys_data.has_function)
        return;
    GroupByFunctionKeysVisitor::Data visitor_data{group_by_keys_data.key_names};
    GroupByFunctionKeysVisitor(visitor_data).visit(group_by);
    modified.reserve(group_by_keys.size());
    
    for (const auto & group_key : group_by_keys)
        if (group_by_keys_data.key_names.contains(group_key->getColumnName()))
            modified.push_back(group_key);
    
    group_by->children = modified;
}
void optimizeAggregateFunctionsOfGroupByKeys(ASTSelectQuery * select_query, ASTPtr & node)