You have to provide the following information whenever possible.

**Describe the bug**
This query fails with the latest stable version 21.5.5.12. It worked with the last stable version 21.4.7.3.

**Does it reproduce on recent release?**
yes

**How to reproduce**
21.5.5.12

```
SELECT
    label,
    number
FROM
(
    SELECT
        'a' AS label,
        number
    FROM
    (
        SELECT number
        FROM numbers(10)
    )
    UNION ALL
    SELECT
        'b' AS label,
        number
    FROM
    (
        SELECT number
        FROM numbers(10)
    )
)
WHERE number IN
(
    SELECT number
    FROM numbers(5)
)
```

**Expected behavior**
Query should run without errors

**Error message and/or stacktrace**
```
Received exception from server (version 21.5.5):
Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Block structure mismatch in Pipe::unitePipes stream: different names of columns:
label String String(size = 0), number UInt64 UInt64(size = 0), 'b' String Const(size = 0, String(size = 1))
label String String(size = 0), number UInt64 UInt64(size = 0), 'a' String Const(size = 0, String(size = 1)).
```

{
    std::sort(index.begin(), index.end(), [&key_names_pos_map](const Node * lhs, const Node * rhs)
    {
        return key_names_pos_map.find(lhs->result_name)->second < key_names_pos_map.find(rhs->result_name)->second;
    });
}
void ActionsDAG::addAggregatesViaProjection(const Block & aggregates)
{
    for (const auto & aggregate : aggregates)
        index.push_back(&addInput(aggregate));
}
void ActionsDAG::addAliases(const NamesWithAliases & aliases)
{
    std::unordered_map<std::string_view, size_t> names_map;
    for (size_t i = 0; i < index.size(); ++i)
        names_map[index[i]->result_name] = i;
    NodeRawConstPtrs required_nodes;
    required_nodes.reserve(aliases.size());
    for (const auto & item : aliases)
    {
        auto it = names_map.find(item.first);
        if (it == names_map.end())
            throw Exception(ErrorCodes::UNKNOWN_IDENTIFIER,
                            "Unknown column: {}, there are only columns {}", item.first, dumpNames());
        required_nodes.push_back(index[it->second]);