**Describe the bug**

The query:
```
SELECT
    (current_database = currentDatabase()) AND (type = 0),
    ((current_database = currentDatabase()) AND (type = NULL)) AND (type = NULL) AND ((current_database = currentDatabase()) AND (type = 1048575)) AND (type = NULL) AND (event_date >= yesterday())
FROM system.query_log
ARRAY JOIN ProfileEvents
WHERE ProfileEvents AND (current_database = currentDatabase())
ORDER BY event_time DESC NULLS FIRST
LIMIT 0
```
crashes the server.

Most likely introduced here: #16618
ManyExpressionActions & group_by_elements_actions)
{
    const auto * select_query = getAggregatingQuery();
    if (!select_query->groupBy())
        return false;
    ExpressionActionsChain::Step & step = chain.lastStep(columns_after_join);
    ASTs asts = select_query->groupBy()->children;
    for (const auto & ast : asts)
    {
        step.required_output.emplace_back(ast->getColumnName());
        getRootActions(ast, only_types, step.actions());
    }
    if (optimize_aggregation_in_order)
    {
        for (auto & child : asts)
        {
            auto actions_dag = std::make_shared<ActionsDAG>(columns_after_join);
            getRootActions(child, only_types, actions_dag);
            group_by_elements_actions.emplace_back(std::make_shared<ExpressionActions>(actions_dag));
        }
    }
    return true;
}
void SelectQueryExpressionAnalyzer::appendAggregateFunctionsArguments(ExpressionActionsChain & chain, bool only_types)