https://s3.amazonaws.com/clickhouse-test-reports/43667/32079f51d96ea7d71778ccce17a031f52411348d/fuzzer_astfuzzerdebug//report.html


```
2022.11.27 22:32:54.283394 [ 147 ] {} <Trace> BaseDaemon: Received signal 11
2022.11.27 22:32:54.283843 [ 431 ] {} <Fatal> BaseDaemon: ########################################
2022.11.27 22:32:54.284265 [ 431 ] {} <Fatal> BaseDaemon: (version 22.12.1.1, build id: FE62F188D8CDA4E2B5DEA4EAAE3100699FE5D30D) (from thread 149) (query_id: 24e657e4-c7d7-4237-b568-4b1d7158d3e3) (query: SELECT fields.name, fields.value FROM (SELECT fields.name FROM LOG_T__fuzz_6)) Received signal Segmentation fault (11)
2022.11.27 22:32:54.284455 [ 431 ] {} <Fatal> BaseDaemon: Address: NULL pointer. Access: read. Address not mapped to object.
2022.11.27 22:32:54.284658 [ 431 ] {} <Fatal> BaseDaemon: Stack trace: 0x28dd70dd 0x28de3abc 0x28de30bd 0x28de0d53 0x28dd2cc7 0x28dd202b 0x28dc78db 0x28dc6ee1 0x28dce6a7 0x28dc2abe 0x28dc1225 0x28dc0f3e 0x28db55b7 0x28f34466 0x28f340fd 0x28e5c05c 0x28e5a20e 0x2944c40f 0x29448c04 0x2a606f94 0x2a6172a5 0x2f183099 0x2f1838dc 0x2f3d2e14 0x2f3cfbba 0x2f3ce99e 0x7f4789b4e609 0x7f4789a73133
2022.11.27 22:32:54.957233 [ 431 ] {} <Fatal> BaseDaemon: 4. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2048: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifierFromCompoundExpression(DB::Identifier const&, unsigned long, std::__1::shared_ptr<DB::IQueryTreeNode> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x28dd70dd in /workspace/clickhouse
2022.11.27 22:32:55.703951 [ 431 ] {} <Fatal> BaseDaemon: 5. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2478: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifierFromTableExpression(DB::(anonymous namespace)::IdentifierLookup const&, std::__1::shared_ptr<DB::IQueryTreeNode> const&, DB::(anonymous namespace)::IdentifierResolveScope&)::$_1::operator()(unsigned long) const @ 0x28de3abc in /workspace/clickhouse
2022.11.27 22:32:56.447822 [ 431 ] {} <Fatal> BaseDaemon: 6. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2559: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifierFromTableExpression(DB::(anonymous namespace)::IdentifierLookup const&, std::__1::shared_ptr<DB::IQueryTreeNode> const&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x28de30bd in /workspace/clickhouse
2022.11.27 22:32:57.183627 [ 431 ] {} <Fatal> BaseDaemon: 7. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2783: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifierFromJoinTreeNode(DB::(anonymous namespace)::IdentifierLookup const&, std::__1::shared_ptr<DB::IQueryTreeNode> const&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x28de0d53 in /workspace/clickhouse
2022.11.27 22:32:57.844803 [ 431 ] {} <Fatal> BaseDaemon: 8. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2824: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifierFromJoinTree(DB::(anonymous namespace)::IdentifierLookup const&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x28dd2cc7 in /workspace/clickhouse
2022.11.27 22:32:58.499143 [ 431 ] {} <Fatal> BaseDaemon: 9. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:2994: DB::(anonymous namespace)::QueryAnalyzer::tryResolveIdentifier(DB::(anonymous namespace)::IdentifierLookup const&, DB::(anonymous namespace)::IdentifierResolveScope&, DB::(anonymous namespace)::IdentifierResolveSettings) @ 0x28dd202b in /workspace/clickhouse
2022.11.27 22:32:59.136568 [ 431 ] {} <Fatal> BaseDaemon: 10. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:4669: DB::(anonymous namespace)::QueryAnalyzer::resolveExpressionNode(std::__1::shared_ptr<DB::IQueryTreeNode>&, DB::(anonymous namespace)::IdentifierResolveScope&, bool, bool) @ 0x28dc78db in /workspace/clickhouse
2022.11.27 22:32:59.775610 [ 431 ] {} <Fatal> BaseDaemon: 11. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:4914: DB::(anonymous namespace)::QueryAnalyzer::resolveExpressionNodeList(std::__1::shared_ptr<DB::IQueryTreeNode>&, DB::(anonymous namespace)::IdentifierResolveScope&, bool, bool) @ 0x28dc6ee1 in /workspace/clickhouse
2022.11.27 22:33:00.419173 [ 431 ] {} <Fatal> BaseDaemon: 12. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:5086: DB::(anonymous namespace)::QueryAnalyzer::resolveProjectionExpressionNodeList(std::__1::shared_ptr<DB::IQueryTreeNode>&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x28dce6a7 in /workspace/clickhouse
2022.11.27 22:33:01.055306 [ 431 ] {} <Fatal> BaseDaemon: 13. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:5922: DB::(anonymous namespace)::QueryAnalyzer::resolveQuery(std::__1::shared_ptr<DB::IQueryTreeNode> const&, DB::(anonymous namespace)::IdentifierResolveScope&) @ 0x28dc2abe in /workspace/clickhouse
2022.11.27 22:33:01.689116 [ 431 ] {} <Fatal> BaseDaemon: 14. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:989: DB::(anonymous namespace)::QueryAnalyzer::resolve(std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::shared_ptr<DB::IQueryTreeNode> const&, std::__1::shared_ptr<DB::Context const>) @ 0x28dc1225 in /workspace/clickhouse
2022.11.27 22:33:02.324275 [ 431 ] {} <Fatal> BaseDaemon: 15. /build/build_docker/../src/Analyzer/Passes/QueryAnalysisPass.cpp:6242: DB::QueryAnalysisPass::run(std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::shared_ptr<DB::Context const>) @ 0x28dc0f3e in /workspace/clickhouse
2022.11.27 22:33:02.472253 [ 431 ] {} <Fatal> BaseDaemon: 16. /build/build_docker/../src/Analyzer/QueryTreePassManager.cpp:99: DB::QueryTreePassManager::run(std::__1::shared_ptr<DB::IQueryTreeNode>) @ 0x28db55b7 in /workspace/clickhouse
2022.11.27 22:33:02.631865 [ 431 ] {} <Fatal> BaseDaemon: 17. /build/build_docker/../src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:54: DB::(anonymous namespace)::buildQueryTreeAndRunPasses(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context const> const&) @ 0x28f34466 in /workspace/clickhouse
2022.11.27 22:33:02.781826 [ 431 ] {} <Fatal> BaseDaemon: 18. /build/build_docker/../src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:67: DB::InterpreterSelectQueryAnalyzer::InterpreterSelectQueryAnalyzer(std::__1::shared_ptr<DB::IAST> const&, DB::SelectQueryOptions const&, std::__1::shared_ptr<DB::Context const>) @ 0x28f340fd in /workspace/clickhouse
2022.11.27 22:33:02.968215 [ 431 ] {} <Fatal> BaseDaemon: 19. /build/build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:714: std::__1::__unique_if<DB::InterpreterSelectQueryAnalyzer>::__unique_single std::__1::make_unique[abi:v15003]<DB::InterpreterSelectQueryAnalyzer, std::__1::shared_ptr<DB::IAST>&, DB::SelectQueryOptions const&, std::__1::shared_ptr<DB::Context>&>(std::__1::shared_ptr<DB::IAST>&, DB::SelectQueryOptions const&, std::__1::shared_ptr<DB::Context>&) @ 0x28e5c05c in /workspace/clickhouse
2022.11.27 22:33:03.134163 [ 431 ] {} <Fatal> BaseDaemon: 20. /build/build_docker/../src/Interpreters/InterpreterFactory.cpp:134: DB::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>, DB::SelectQueryOptions const&) @ 0x28e5a20e in /workspace/clickhouse
2022.11.27 22:33:03.538065 [ 431 ] {} <Fatal> BaseDaemon: 21. /build/build_docker/../src/Interpreters/executeQuery.cpp:639: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x2944c40f in /workspace/clickhouse
2022.11.27 22:33:03.961152 [ 431 ] {} <Fatal> BaseDaemon: 22. /build/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) @ 0x29448c04 in /workspace/clickhouse
2022.11.27 22:33:04.381238 [ 431 ] {} <Fatal> BaseDaemon: 23. /build/build_docker/../src/Server/TCPHandler.cpp:374: DB::TCPHandler::runImpl() @ 0x2a606f94 in /workspace/clickhouse
2022.11.27 22:33:04.836520 [ 431 ] {} <Fatal> BaseDaemon: 24. /build/build_docker/../src/Server/TCPHandler.cpp:1902: DB::TCPHandler::run() @ 0x2a6172a5 in /workspace/clickhouse
2022.11.27 22:33:04.946979 [ 431 ] {} <Fatal> BaseDaemon: 25. /build/build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:43: Poco::Net::TCPServerConnection::start() @ 0x2f183099 in /workspace/clickhouse
2022.11.27 22:33:05.067263 [ 431 ] {} <Fatal> BaseDaemon: 26. /build/build_docker/../contrib/poco/Net/src/TCPServerDispatcher.cpp:115: Poco::Net::TCPServerDispatcher::run() @ 0x2f1838dc in /workspace/clickhouse
2022.11.27 22:33:05.194629 [ 431 ] {} <Fatal> BaseDaemon: 27. /build/build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:199: Poco::PooledThread::run() @ 0x2f3d2e14 in /workspace/clickhouse
2022.11.27 22:33:05.318314 [ 431 ] {} <Fatal> BaseDaemon: 28. /build/build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x2f3cfbba in /workspace/clickhouse
2022.11.27 22:33:05.439991 [ 431 ] {} <Fatal> BaseDaemon: 29. /build/build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:345: Poco::ThreadImpl::runnableEntry(void*) @ 0x2f3ce99e in /workspace/clickhouse
2022.11.27 22:33:05.440206 [ 431 ] {} <Fatal> BaseDaemon: 30. ? @ 0x7f4789b4e609 in ?
2022.11.27 22:33:05.440387 [ 431 ] {} <Fatal> BaseDaemon: 31. __clone @ 0x7f4789a73133 in ?
2022.11.27 22:33:05.440528 [ 431 ] {} <Fatal> BaseDaemon: Integrity check of the executable skipped because the reference checksum could not be read.
```
{
    bool initial_scope_is_query = scope.scope_node->getNodeType() == QueryTreeNodeType::QUERY;
    bool initial_scope_is_expression = !initial_scope_is_query;
    IdentifierResolveSettings identifier_resolve_settings;
    identifier_resolve_settings.allow_to_check_parent_scopes = false;
    identifier_resolve_settings.allow_to_check_database_catalog = false;
    IdentifierResolveScope * scope_to_check = scope.parent_scope;
    if (initial_scope_is_expression)
    {
        while (scope_to_check != nullptr)
        {
            auto resolve_result = tryResolveIdentifier(identifier_lookup, *scope_to_check, identifier_resolve_settings);
            if (resolve_result.resolved_identifier)
                return resolve_result;
            bool scope_was_query = scope_to_check->scope_node->getNodeType() == QueryTreeNodeType::QUERY;
            scope_to_check = scope_to_check->parent_scope;
            if (scope_was_query)
                break;
        }
    }
    while (scope_to_check != nullptr)
    {
        auto lookup_result = tryResolveIdentifier(identifier_lookup, *scope_to_check, identifier_resolve_settings);
        const auto & resolved_identifier = lookup_result.resolved_identifier;
        scope_to_check = scope_to_check->parent_scope;
        if (resolved_identifier)
        {
            bool is_cte = resolved_identifier->as<QueryNode>() && resolved_identifier->as<QueryNode>()->isCTE();
            /** From parent scopes we can resolve table identifiers only as CTE.
              * Example: SELECT (SELECT 1 FROM a) FROM test_table AS a;