**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
{
    /** Find aggregation keys (aggregation_keys), information about aggregate functions (aggregate_descriptions),
     *  as well as a set of columns obtained after the aggregation, if any,
     *  or after all the actions that are usually performed before aggregation (aggregated_columns).
     *
     * Everything below (compiling temporary ExpressionActions) - only for the purpose of query analysis (type output).
     */
    auto * select_query = query->as<ASTSelectQuery>();
    auto temp_actions = std::make_shared<ActionsDAG>(sourceColumns());
    if (select_query)
    {
        NamesAndTypesList array_join_columns;
        columns_after_array_join = sourceColumns();
        bool is_array_join_left;
        if (ASTPtr array_join_expression_list = select_query->arrayJoinExpressionList(is_array_join_left))
        {
            getRootActionsNoMakeSet(array_join_expression_list, true, temp_actions, false);
            auto array_join = addMultipleArrayJoinAction(temp_actions, is_array_join_left);
            auto sample_columns = temp_actions->getResultColumns();
            array_join->prepare(sample_columns);
            temp_actions = std::make_shared<ActionsDAG>(sample_columns);
            NamesAndTypesList new_columns_after_array_join;