**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
NameSet added_columns;
            for (auto & column : temp_actions->getResultColumns())
            {
                if (syntax->array_join_result_to_source.count(column.name))
                {
                    new_columns_after_array_join.emplace_back(column.name, column.type);
                    added_columns.emplace(column.name);
                }
            }
            for (auto & column : columns_after_array_join)
                if (added_columns.count(column.name) == 0)
                    new_columns_after_array_join.emplace_back(column.name, column.type);
            columns_after_array_join.swap(new_columns_after_array_join);
        }
        columns_after_array_join.insert(columns_after_array_join.end(), array_join_columns.begin(), array_join_columns.end());
        const ASTTablesInSelectQueryElement * join = select_query->join();
        if (join)
        {
            getRootActionsNoMakeSet(analyzedJoin().leftKeysList(), true, temp_actions, false);
            auto sample_columns = temp_actions->getResultColumns();
            analyzedJoin().addJoinedColumnsAndCorrectNullability(sample_columns);
            temp_actions = std::make_shared<ActionsDAG>(sample_columns);
        }
        columns_after_join = columns_after_array_join;
        const auto & added_by_join = analyzedJoin().columnsAddedByJoin();
        columns_after_join.insert(columns_after_join.end(), added_by_join.begin(), added_by_join.end());
    }
    has_aggregation = makeAggregateDescriptions(temp_actions);
    if (select_query && (select_query->groupBy() || select_query->having()))
        has_aggregation = true;