**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
{
    const auto * select_query = getAggregatingQuery();
    ExpressionActionsChain::Step & step = chain.lastStep(columns_after_join);
    for (const auto & desc : aggregate_descriptions)
        for (const auto & name : desc.argument_names)
            step.required_output.emplace_back(name);
    
    
    
    GetAggregatesVisitor::Data data;
    GetAggregatesVisitor(data).visit(select_query->select());
    if (select_query->having())
        GetAggregatesVisitor(data).visit(select_query->having());
    if (select_query->orderBy())
        GetAggregatesVisitor(data).visit(select_query->orderBy());
    
    for (const ASTFunction * node : data.aggregates)
        if (node->arguments)
            for (auto & argument : node->arguments->children)
                getRootActions(argument, only_types, step.actions());
}
void SelectQueryExpressionAnalyzer::appendWindowFunctionsArguments(