**Describe the issue**
The following query worked in 21.1.2, but doesn't work in 21.2.2

```sql
INSERT INTO ztf.dr4_source_obs_02 SELECT
    match.oid1 AS sid,
    obs.oid AS oid,
    obs.filter AS filter,
    obs.fieldid AS fieldid,
    obs.rcid AS rcid,
    coord.ra AS ra,
    coord.dec AS dec,
    obs.mjd AS mjd,
    obs.mag AS mag,
    obs.magerr AS magerr,
    obs.clrcoeff AS clrcoeff
FROM ztf.dr4_obs AS obs
INNER JOIN
(
    SELECT
        oid1,
        oid2
    FROM ztf.dr4_xmatch_02
    WHERE (oid1 <= oid2) AND (oid1 NOT IN
        (
            SELECT oid2
            FROM ztf.dr4_xmatch_02
            WHERE oid1 < oid2 AND (oid2 >= -inf) AND (oid2 < 639110200101898)
        )
    ) AND (oid1 >= -inf) AND (oid1 < 639110200101898)
) AS match ON match.oid2 = obs.oid
INNER JOIN (
    WITH
        (pi() / 180.0) AS deg_to_rad,
        (180.0 / pi()) AS rad_to_deg
    SELECT
        oid1,
        rad_to_deg * atan2(avg(sin(deg_to_rad * ra2)), avg(cos(deg_to_rad * ra2))) AS ra,
        rad_to_deg * atan2(avg(sin(deg_to_rad * dec2)), avg(cos(deg_to_rad * dec2))) AS dec
    FROM ztf.dr4_xmatch_02
    WHERE (oid1 <= oid2) AND (oid1 NOT IN
        (
            SELECT oid2
            FROM ztf.dr4_xmatch_02
            WHERE oid1 < oid2  AND (oid2 >= -inf) AND (oid2 < 639110200101898)
        )
    ) AND (oid1 >= -inf) AND (oid1 < 639110200101898)
    GROUP BY oid1
) AS coord ON match.oid1 = coord.oid1
WHERE (obs.catflags = 0) AND (obs.magerr > 0)
```

(Yes, I know, that it is suboptimal to make these identical sub-sub-queries)


**Error message and/or stacktrace**

```
Different expressions with the same alias _subquery4:
(WITH pi() / 180. AS deg_to_rad, 180. / pi() AS rad_to_deg SELECT oid2 FROM ztf.dr4_xmatch_02 WHERE (oid1 < oid2) AND (oid2 >= -inf) AND (oid2 < 639110200101898)) AS _subquery4
and
(WITH pi() / 180. AS deg_to_rad, 180. / pi() AS rad_to_deg SELECT oid2 FROM ztf.dr4_xmatch_02 WHERE (oid1 < oid2) AND (oid2 >= -inf) AND (oid2 < 639110200101898)) AS _subquery4
: While processing (WITH pi() / 180. AS deg_to_rad, 180. / pi() AS rad_to_deg SELECT oid2 FROM ztf.dr4_xmatch_02 WHERE (oid1 < oid2) AND (oid2 >= -inf) AND (oid2 < 639110200101898)) AS _subquery4. Stack trace:

0. DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>::visitOther(std::__1::shared_ptr<DB::IAST> const&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<DB::IAST>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::shared_ptr<DB::IAST> > > >&) @ 0xedb9fe0 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
1. DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>::visit(DB::ASTSubquery const&, std::__1::shared_ptr<DB::IAST> const&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<DB::IAST>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::shared_ptr<DB::IAST> > > >&) @ 0xedb9270 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
2. DB::InDepthNodeVisitor<DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xedba1fb in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
3. DB::InDepthNodeVisitor<DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xedba17b in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
4. DB::InDepthNodeVisitor<DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xedba17b in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
5. DB::InDepthNodeVisitor<DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xedba17b in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
6. DB::InDepthNodeVisitor<DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xedba17b in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
7. DB::InDepthNodeVisitor<DB::QueryAliasesMatcher<DB::QueryAliasesWithSubqueries>, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xedba17b in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
8. DB::TreeRewriter::normalize(std::__1::shared_ptr<DB::IAST>&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<DB::IAST>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::shared_ptr<DB::IAST> > > >&, DB::Settings const&) @ 0xee81633 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
9. DB::TreeRewriter::analyzeSelect(std::__1::shared_ptr<DB::IAST>&, DB::TreeRewriterResult&&, DB::SelectQueryOptions const&, std::__1::vector<DB::TableWithColumnNamesAndTypes, std::__1::allocator<DB::TableWithColumnNamesAndTypes> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::TableJoin>) const @ 0xee7c416 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
10. ? @ 0xeb9ec7e in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
11. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0xeb9bb42 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
12. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xeb99b4d in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
13. DB::InterpreterSelectWithUnionQuery::buildCurrentChildInterpreter(std::__1::shared_ptr<DB::IAST> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xed46025 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
14. DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xed446e0 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
15. DB::InterpreterSelectWithUnionQuery::getSampleBlock(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&) @ 0xed46bd1 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
16. ? @ 0xeee19be in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
17. DB::getDatabaseAndTablesWithColumns(std::__1::vector<DB::ASTTableExpression const*, std::__1::allocator<DB::ASTTableExpression const*> > const&, DB::Context const&) @ 0xeee27eb in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
18. DB::JoinedTables::resolveTables() @ 0xed7b2f4 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
19. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0xeb9a928 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
20. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xeb99b4d in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
21. DB::InterpreterSelectWithUnionQuery::buildCurrentChildInterpreter(std::__1::shared_ptr<DB::IAST> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xed46025 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
22. DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xed446e0 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
23. DB::InterpreterInsertQuery::execute() @ 0xeb7a3ec in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
24. ? @ 0xeed0ea2 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
25. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool) @ 0xeecf7fc in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
26. DB::TCPHandler::runImpl() @ 0xf5ca265 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
27. DB::TCPHandler::run() @ 0xf5d9ee9 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
28. Poco::Net::TCPServerConnection::start() @ 0x11b76baf in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
29. Poco::Net::TCPServerDispatcher::run() @ 0x11b785c1 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
30. Poco::PooledThread::run() @ 0x11caf669 in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
31. Poco::ThreadImpl::runnableEntry(void*) @ 0x11cab4ca in /projects/caps/uiucsn/ztf_dr/clickhouse/bin/clickhouse
```

* `CREATE TABLE` statements for all tables involved

```sql
CREATE TABLE ztf.dr4_source_obs_02
(
    `sid` UInt64 CODEC(Delta(8), LZ4),
    `oid` UInt64 CODEC(Delta(8), LZ4),
    `filter` UInt8 CODEC(T64, LZ4),
    `fieldid` UInt16 CODEC(T64, LZ4),
    `rcid` UInt8 CODEC(Delta(1), LZ4),
    `ra` Float64 CODEC(Gorilla),
    `dec` Float64 CODEC(Gorilla),
    `h3index10` UInt64 MATERIALIZED geoToH3(ra, dec, 10) CODEC(Delta(8), LZ4),
    `mjd` Float64,
    `mag` Float32,
    `magerr` Float32,
    `clrcoeff` Float32
)
ENGINE = MergeTree
PARTITION BY intDiv(oid, 1000000000000)
PRIMARY KEY h3index10
ORDER BY (h3index10, sid, mjd)
```

```sql
CREATE TABLE ztf.dr4_obs
(
    `oid` UInt64 CODEC(Delta(8), LZ4),
    `nobs` UInt16 CODEC(T64, LZ4),
    `filter` UInt8 CODEC(T64, LZ4),
    `fieldid` UInt16 CODEC(T64, LZ4),
    `rcid` UInt8 CODEC(Delta(1), LZ4),
    `ra` Float64 CODEC(Gorilla),
    `dec` Float64 CODEC(Gorilla),
    `h3index10` UInt64 MATERIALIZED geoToH3(ra, dec, 10) CODEC(Delta(8), LZ4),
    `mjd` Float64,
    `mag` Float32,
    `magerr` Float32,
    `clrcoeff` Float32,
    `catflags` UInt16 CODEC(T64, LZ4)
)
ENGINE = MergeTree
PARTITION BY fieldid
PRIMARY KEY h3index10
ORDER BY (h3index10, oid, mjd)
```

```sql
CREATE TABLE ztf.dr4_xmatch_02
(
    `oid1` UInt64,
    `oid2` UInt64,
    `ra2` Float64,
    `dec2` Float64
)
ENGINE = MergeTree
ORDER BY oid2
```
{
    const auto & [field, type] = evaluateConstantExpression(node, context);
    if (!isColumnedAsNumber(type))
        throw Exception("Illegal type " + type->getName() + " of WITH FILL expression, must be numeric type", ErrorCodes::INVALID_WITH_FILL_EXPRESSION);
    return field;
}
static FillColumnDescription getWithFillDescription(const ASTOrderByElement & order_by_elem, const Context & context)
{
    FillColumnDescription descr;
    if (order_by_elem.fill_from)
        descr.fill_from = getWithFillFieldValue(order_by_elem.fill_from, context);
    if (order_by_elem.fill_to)
        descr.fill_to = getWithFillFieldValue(order_by_elem.fill_to, context);
    if (order_by_elem.fill_step)
        descr.fill_step = getWithFillFieldValue(order_by_elem.fill_step, context);
    else