```
WITH
    a AS
    (
        SELECT
            t1.number AS n1,
            t2.number AS n2
        FROM numbers(1) AS t1, numbers(1) AS t2
    ),
    b AS
    (
        SELECT sum(n1) AS s
        FROM a
    )
SELECT *
FROM a AS l, b AS r
SETTINGS allow_experimental_analyzer = 1

Query id: 3e4256ae-2d4a-413a-8af0-b1d6cd645bfc


0 rows in set. Elapsed: 0.001 sec.

Received exception from server (version 22.12.1):
Code: 60. DB::Exception: Received from localhost:9000. DB::Exception: Table default.a doesn't exist. Stack trace:

0. ./build_docker/../src/Common/Exception.cpp:77: DB::Exception::Exception(DB::Exception::MessageMasked const&, int, bool) @ 0xe469f1a in /usr/bin/clickhouse
1. ./build_docker/../contrib/libcxx/include/string:1499: DB::Exception& std::__1::optional<DB::Exception>::emplace[abi:v15003]<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, int const&, void>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&&, int const&) @ 0x1375a8c2 in /usr/bin/clickhouse
2. ./build_docker/../contrib/libcxx/include/string:1499: DB::DatabaseCatalog::getTableImpl(DB::StorageID const&, std::__1::shared_ptr<DB::Context const>, std::__1::optional<DB::Exception>*) const @ 0x137d0568 in /usr/bin/clickhouse
3. ./build_docker/../contrib/libcxx/include/__memory/shared_ptr.h:801: DB::DatabaseCatalog::getTable(DB::StorageID const&, std::__1::shared_ptr<DB::Context const>) const @ 0x137d826a in /usr/bin/clickhouse
4. ./build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2027: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifier(DB::(anonymous namespace)::IdentifierLookup const&, DB::(anonymous namespace)::IdentifierResolveScope&, DB::(anonymous namespace)::IdentifierResolveSettings) @ 0x13d79ff6 in /usr/bin/clickhouse
5. ./build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:0: DB::(anonymous namespace)::QueryAnalyzer::resolveQuery(std::__1::shared_ptr<DB::IQueryTreeNode> const&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x13d60eca in /usr/bin/clickhouse
6. ./build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:5419: DB::(anonymous namespace)::QueryAnalyzer::resolveQueryJoinTreeNode(std::__1::shared_ptr<DB::IQueryTreeNode>&, DB::(anonymous namespace)::IdentifierResolveScope&, DB::(anonymous namespace)::QueryExpressionsAliasVisitor&) @ 0x13d70951 in /usr/bin/clickhouse
7. ./build_docker/../contrib/libcxx/include/vector:1457: DB::(anonymous namespace)::QueryAnalyzer::resolveQueryJoinTreeNode(std::__1::shared_ptr<DB::IQueryTreeNode>&, DB::(anonymous namespace)::IdentifierResolveScope&, DB::(anonymous namespace)::QueryExpressionsAliasVisitor&) @ 0x13d6fce3 in /usr/bin/clickhouse
8. ./build_docker/../contrib/libcxx/include/vector:1457: DB::(anonymous namespace)::QueryAnalyzer::resolveQuery(std::__1::shared_ptr<DB::IQueryTreeNode> const&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x13d61921 in /usr/bin/clickhouse
9. ./build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:989: DB::QueryAnalysisPass::run(std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::shared_ptr<DB::Context const>) @ 0x13d5f820 in /usr/bin/clickhouse
10. ./build_docker/../src/Analyzer/QueryTreePassManager.cpp:97: DB::QueryTreePassManager::run(std::__1::shared_ptr<DB::IQueryTreeNode>) @ 0x13d5e245 in /usr/bin/clickhouse
11. ./build_docker/../contrib/libcxx/include/vector:434: DB::InterpreterSelectQueryAnalyzer::InterpreterSelectQueryAnalyzer(std::__1::shared_ptr<DB::IAST> const&, DB::SelectQueryOptions const&, std::__1::shared_ptr<DB::Context const>) @ 0x13e6a8ba in /usr/bin/clickhouse
12. ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:0: DB::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>, DB::SelectQueryOptions const&) @ 0x13de2c2a in /usr/bin/clickhouse
13. ./build_docker/../src/Interpreters/executeQuery.cpp:0: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x141c1da0 in /usr/bin/clickhouse
14. ./build_docker/../src/Interpreters/executeQuery.cpp:1082: DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x141bf68d in /usr/bin/clickhouse
15. ./build_docker/../src/Server/TCPHandler.cpp:0: DB::TCPHandler::runImpl() @ 0x14e76fee in /usr/bin/clickhouse
16. ./build_docker/../src/Server/TCPHandler.cpp:1904: DB::TCPHandler::run() @ 0x14e8a4f9 in /usr/bin/clickhouse
17. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x17ce03b4 in /usr/bin/clickhouse
18. ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:48: Poco::Net::TCPServerDispatcher::run() @ 0x17ce1d5b in /usr/bin/clickhouse
19. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:213: Poco::PooledThread::run() @ 0x17e70b67 in /usr/bin/clickhouse
20. ./build_docker/../contrib/poco/Foundation/include/Poco/SharedPtr.h:277: Poco::ThreadImpl::runnableEntry(void*) @ 0x17e6e59d in /usr/bin/clickhouse
21. ? @ 0x7fea26f61609 in ?
22. __clone @ 0x7fea26e86133 in ?
. (UNKNOWN_TABLE)

ip-172-31-16-30.us-east-2.compute.internal :) WITH a AS
                                              (
                                              SELECT t1.number as n1, t2.number as n2
                                              FROM numbers(1) as t1, numbers(1) as t2
                                              ),
                                              b AS
                                              (
                                              SELECT sum(n1) as s
                                              FROM a
                                              )
                                              SELECT *
                                              FROM a l, b r
                                              SETTINGS allow_experimental_analyzer = 0

WITH
    a AS
    (
        SELECT
            t1.number AS n1,
            t2.number AS n2
        FROM numbers(1) AS t1, numbers(1) AS t2
    ),
    b AS
    (
        SELECT sum(n1) AS s
        FROM a
    )
SELECT *
FROM a AS l, b AS r
SETTINGS allow_experimental_analyzer = 0

Query id: 09e947a7-e32a-4a23-9161-39582b0f86b0

┌─n1─┬─n2─┬─s─┐
│  0 │  0 │ 0 │
└────┴────┴───┘

1 row in set. Elapsed: 0.028 sec.
```
* in function context.
  *
  * If there are no information of identifier context rules are following:
  * 1. Try to resolve identifier in expression context.
  * 2. Try to resolve identifier in function context, if it is allowed. Example: SELECT func(arguments); Here func identifier cannot be resolved in function context
  * because query projection does not support that.
  * 3. Try to resolve identifier in table context, if it is allowed. Example: SELECT table; Here table identifier cannot be resolved in function context
  * because query projection does not support that.
  *
  * TODO: This does not supported properly before, because matchers could not be resolved from aliases.
  *
  * Identifiers are resolved with following resules:
  * Resolution starts with current scope.
  * 1. Try to resolve identifier from expression scope arguments. Lambda expression arguments are greatest priority.
  * 2. Try to resolve identifier from aliases.
  * 3. Try to resolve identifier from join tree if scope is query, or if there are registered table columns in scope.
  * Steps 2 and 3 can be changed using prefer_column_name_to_alias setting.
  * 4. If it is table lookup, try to resolve identifier from CTE.
  * If identifier could not be resolved in current scope, resolution must be continued in parent scopes.
  * 5. Try to resolve identifier from parent scopes.
  *
  * Additional rules about aliases and scopes.
  * 1. Parent scope cannot refer alias from child scope.
  * 2. Child scope can refer to alias in parent scope.
  *
  * Example: SELECT arrayMap(x -> x + 1 AS a, [1,2,3]), a; Identifier a is unknown in parent scope.
  * Example: SELECT a FROM (SELECT 1 as a); Here we do not refer to alias a from child query scope. But we query it projection result, similar to tables.
  * Example: WITH 1 as a SELECT (SELECT a) as b; Here in child scope identifier a is resolved using alias from parent scope.
  *
  * Additional rules about identifier binding.