**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
{
    ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
    
    auto * expression_step = typeid_cast<ExpressionActionsChain::ExpressionActionsStep *>(&step);
    expression_step->actions_dag = std::move(actions_dag);
    step.required_output.push_back(std::move(column_name));
    step.can_remove_required_output = {true};
    chain.addStep();
}
bool SelectQueryExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, bool only_types)
{
    const auto * select_query = getSelectQuery();
    if (!select_query->where())
        return false;
    ExpressionActionsChain::Step & step = chain.lastStep(columns_after_join);
    getRootActions(select_query->where(), only_types, step.actions());
    auto where_column_name = select_query->where()->getColumnName();
    step.required_output.push_back(where_column_name);
    step.can_remove_required_output = {true};
    auto filter_type = (*step.actions()->getIndex().find(where_column_name))->result_type;
    if (!filter_type->canBeUsedInBooleanContext())
        throw Exception("Invalid type for filter in WHERE: " + filter_type->getName(),
                        ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER);
    return true;
}
bool SelectQueryExpressionAnalyzer::appendGroupBy(ExpressionActionsChain & chain, bool only_types, bool optimize_aggregation_in_order,