**Describe what's wrong**

After Moving to 21.11, [ReplacingMergeTree-style Materialized view](https://github.com/tiniumv/clickhouse_bug/blob/main/migrations/add_view.sql) which is getting data from [two other views](https://github.com/tiniumv/clickhouse_bug/blob/main/migrations/basic.sql) based on kafka topics stopped to receive any data.

Same requst ```select * from causing_problems_mv;```
on 21.10
```
┌─field_a─┬─field_b─┬─field_c─┬──max_field_datetime─┐
│ 1       │ type_a  │       1 │ 2021-12-01 14:00:00 │
│ 2       │ type_a  │       2 │ 2021-12-01 13:00:00 │
└─────────┴─────────┴─────────┴─────────────────────┘
```
and on 21.11
```
0 rows in set. Elapsed: 0.002 sec.
```

Moreover, one of the source view (the one from left part of ```LEFT JOIN``` expression) went broken too. That was isolated - I tried to not create final view under 21.11, and it resulted in basic views working normally.

**Does it reproduce on recent release?**

Yes.

**How to reproduce**

Repository with everything needed to replicate bug: https://github.com/tiniumv/clickhouse_bug . There are two branches, main (with 21.10 CH) and 21.11

**Expected behavior**

I was expecting result of provided queries to be identical independently from ClickHouse version.

**Error message and/or stacktrace**

[I have collected all logs](https://raw.githubusercontent.com/tiniumv/clickhouse_bug/21.11/logs/clickhouse-server.err.log)
it says that ```Column `field_a` is not under aggregate function and not in GROUP BY: While processing field_a, field_b, argMax(field_c, field_datetime) AS field_c, max(field_datetime) AS max_field_datetime.```, but it clearly is

**Additional context**

While request ```select * from table_ii;``` returns nothing, ```select * from table_ii_queue;``` spits out all lost messages

select_expr_list->children.push_back(std::make_shared<ASTLiteral>(1u));
        auto select_query = std::make_shared<ASTSelectQuery>();
        select_query->children.push_back(select_expr_list);
        select_query->setExpression(ASTSelectQuery::Expression::SELECT, select_expr_list);
        select_query->setExpression(ASTSelectQuery::Expression::TABLES, tables_in_select);
        ASTPtr limit_length_ast = std::make_shared<ASTLiteral>(Field(UInt64(1)));
        select_query->setExpression(ASTSelectQuery::Expression::LIMIT_LENGTH, std::move(limit_length_ast));
        auto select_with_union_query = std::make_shared<ASTSelectWithUnionQuery>();
        select_with_union_query->list_of_selects = std::make_shared<ASTExpressionList>();
        select_with_union_query->list_of_selects->children.push_back(std::move(select_query));
        select_with_union_query->children.push_back(select_with_union_query->list_of_selects);
        auto new_subquery = std::make_shared<ASTSubquery>();
        new_subquery->children.push_back(select_with_union_query);
        auto function = makeASTFunction("in", std::make_shared<ASTLiteral>(1u), new_subquery);
        func = *function;
    }
};
using ExistsExpressionVisitor = InDepthNodeVisitor<OneTypeMatcher<ExistsExpressionData>, false>;
void translateQualifiedNames(ASTPtr & query, const ASTSelectQuery & select_query, const NameSet & source_columns_set,
                             const TablesWithColumns & tables_with_columns)
{
    LogAST log;
    TranslateQualifiedNamesVisitor::Data visitor_data(source_columns_set, tables_with_columns);
    TranslateQualifiedNamesVisitor visitor(visitor_data, log.stream());
    visitor.visit(query);
    
    if (select_query.select()->children.empty())
        throw Exception("Empty list of columns in SELECT query", ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED);
}
void replaceWithSumCount(String column_name, ASTFunction & func)