Abnormal memory requirements for a query with string filter


Appeared fresh after upgrade to 21.3.2.5 

The table is not big - 480 mb compressed

Getting an error
```
SQL Error [241]: ClickHouse exception, code: 241, host: localhost, port: 8123; Code: 241, e.displayText() = DB::Exception: Memory limit (for query) exceeded: would use 1.00 EiB (attempt to allocate chunk of 1152921504606554384 bytes), maximum: 101.47 GiB: While executing ConvertingAggregatedToChunksTransform (version 21.3.2.5 (official build))

The query is quite plain
SELECT 
       FirstScreen,
       "SessionResult" AS "SessionResult",
       count(*) AS count
FROM
  (SELECT FirstScreen,
          SessionResult,
          LastResponse,
          toDate(LastResponseDateTime),
          WasEligible,
          WasSessionSuccessfull,
          COUNT (*)
   FROM MPTUSSDSESSIONS
   GROUP by FirstScreen,
            SessionResult,
            LastResponse,
            toDate(LastResponseDateTime),
            WasEligible,
            WasSessionSuccessfull) AS expr_qry
WHERE  "SessionResult" NOT IN ('unknown result')
  AND "WasSessionSuccessfull" ='Y'
GROUP BY FirstScreen,  "SessionResult"
ORDER BY count DESC
LIMIT 10000;
```

Most interesting - when line  `AND "WasSessionSuccessfull" ='Y' ` is removed from the query it completes ok.
result_predicate = &actions->addFunction(func_builder_and, args, {}, true, false);
    }
    actions->index.insert(result_predicate);
    return actions;
}
ActionsDAGPtr ActionsDAG::splitActionsForFilter(const std::string & filter_name, bool can_remove_filter, const Names & available_inputs)
{
    Node * predicate;
    {
        auto it = index.begin();
        for (; it != index.end(); ++it)
            if ((*it)->result_name == filter_name)
                break;
        if (it == index.end())
            throw Exception(ErrorCodes::LOGICAL_ERROR,
                            "Index for ActionsDAG does not contain filter column name {}. DAG:\n{}",
                            filter_name, dumpDAG());
        predicate = *it;
    }
    std::unordered_set<const Node *> allowed_nodes;
    
    {
        std::unordered_map<std::string_view, std::list<const Node *>> inputs_map;
        for (const auto & input : inputs)
            inputs_map[input->result_name].emplace_back(input);
        for (const auto & name : available_inputs)
        {
            auto & inputs_list = inputs_map[name];
            if (inputs_list.empty())
                continue;