```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 (settings.optimize_redundant_functions_in_order_by)
        optimizeRedundantFunctionsInOrderBy(select_query, context);
    
    if (settings.optimize_monotonous_functions_in_order_by)
        optimizeMonotonousFunctionsInOrderBy(select_query, context, tables_with_columns, result);
    
    
    
    optimizeDuplicatesInOrderBy(select_query);
    
    if (settings.optimize_if_transform_strings_to_enum)
        transformIfStringsIntoEnum(query);
    
    optimizeLimitBy(select_query);
    
    optimizeUsing(select_query);
    if (settings.optimize_syntax_fuse_functions)
        optimizeFuseQuantileFunctions(query);
    if (settings.optimize_or_like_chain
        && settings.allow_hyperscan
        && settings.max_hyperscan_regexp_length == 0
        && settings.max_hyperscan_regexp_total_length == 0)
    {
        optimizeOrLikeChain(query);
    }
}
}