Skip to content

Not found column c1 in block. There are only columns: c2 #42399

Closed

Description

@qoega

Setup

CREATE TABLE t0
(
    `c0` String,
    `c1` Int32,
    `c2` String
)
ENGINE = Memory

Error. Should fail fast at least as c1 is not an aggregate function.

SELECT MIN(t0.c2)
FROM t0
GROUP BY t0.c1
HAVING COUNT(t0.c1) AND t0.c1
SETTINGS enable_optimize_predicate_expression = 0

Query id: 7165bf3e-51a7-49b0-8a14-146dd50b172b

[ip-172-31-0-52] 2022.10.17 15:02:56.404532 [ 111763 ] {7165bf3e-51a7-49b0-8a14-146dd50b172b} <Debug> executeQuery: (from 127.0.0.1:42684) SELECT MIN(t0.c2) FROM t0 GROUP BY t0.c1 HAVING (COUNT(t0.c1)) AND (t0.c1) SETTINGS enable_optimize_predicate_expression=0; (stage: Complete)
[ip-172-31-0-52] 2022.10.17 15:02:56.409470 [ 111763 ] {7165bf3e-51a7-49b0-8a14-146dd50b172b} <Trace> ContextAccess (default): Access granted: SELECT(c1, c2) ON database14TLPHaving.t0
[ip-172-31-0-52] 2022.10.17 15:02:56.411033 [ 111763 ] {7165bf3e-51a7-49b0-8a14-146dd50b172b} <Trace> InterpreterSelectQuery: FetchColumns -> Complete
[ip-172-31-0-52] 2022.10.17 15:02:56.458018 [ 111763 ] {7165bf3e-51a7-49b0-8a14-146dd50b172b} <Error> executeQuery: Code: 10. DB::Exception: Not found column c1 in block. There are only columns: c2. (NOT_FOUND_COLUMN_IN_BLOCK) (version 22.10.1.1) (from 127.0.0.1:42684) (in query: SELECT MIN(t0.c2) FROM t0 GROUP BY t0.c1 HAVING (COUNT(t0.c1)) AND (t0.c1) SETTINGS enable_optimize_predicate_expression=0;), Stack trace (when copying this message, always include the lines below):

0. ./build_docker/../contrib/libcxx/include/exception:133: Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x512255aa in /home/ubuntu/memory-ch/clickhouse
1. ./build_docker/../src/Common/Exception.cpp:0: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x25c62793 in /home/ubuntu/memory-ch/clickhouse
2. ./build_docker/../src/Core/Block.cpp:0: DB::Block::getByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) const @ 0x3d2659a2 in /home/ubuntu/memory-ch/clickhouse
3. ./build_docker/../src/Interpreters/Aggregator.cpp:443: DB::Aggregator::Params::getHeader(DB::Block const&, bool, 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::vector<DB::AggregateDescription, std::__1::allocator<DB::AggregateDescription> > const&, bool) @ 0x3e7bc781 in /home/ubuntu/memory-ch/clickhouse
4. ./build_docker/../src/Processors/QueryPlan/AggregatingStep.cpp:425: DB::AggregatingStep::updateOutputStream() @ 0x4607f1bd in /home/ubuntu/memory-ch/clickhouse
5. ./build_docker/../src/Processors/QueryPlan/ITransformingStep.h:68: DB::ITransformingStep::updateInputStream(DB::DataStream) @ 0x463dadb3 in /home/ubuntu/memory-ch/clickhouse
6. ./build_docker/../src/Processors/QueryPlan/Optimizations/filterPushDown.cpp:114: DB::QueryPlanOptimizations::tryAddNewFilterStep(DB::QueryPlan::Node*, std::__1::list<DB::QueryPlan::Node, std::__1::allocator<DB::QueryPlan::Node> >&, std::__1::shared_ptr<DB::ActionsDAG> const&, bool, unsigned long) @ 0x463e9719 in /home/ubuntu/memory-ch/clickhouse
7. ./build_docker/../contrib/libcxx/include/__memory/shared_ptr.h:702: DB::QueryPlanOptimizations::tryAddNewFilterStep(DB::QueryPlan::Node*, std::__1::list<DB::QueryPlan::Node, std::__1::allocator<DB::QueryPlan::Node> >&, 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&, bool, unsigned long) @ 0x463e46da in /home/ubuntu/memory-ch/clickhouse
8. ./build_docker/../src/Processors/QueryPlan/Optimizations/filterPushDown.cpp:187: DB::QueryPlanOptimizations::tryPushDownFilter(DB::QueryPlan::Node*, std::__1::list<DB::QueryPlan::Node, std::__1::allocator<DB::QueryPlan::Node> >&) @ 0x463e0354 in /home/ubuntu/memory-ch/clickhouse
9. ./build_docker/../src/Processors/QueryPlan/Optimizations/optimizeTree.cpp:0: DB::QueryPlanOptimizations::optimizeTree(DB::QueryPlanOptimizationSettings const&, DB::QueryPlan::Node&, std::__1::list<DB::QueryPlan::Node, std::__1::allocator<DB::QueryPlan::Node> >&) @ 0x463d14d9 in /home/ubuntu/memory-ch/clickhouse
10. ./build_docker/../src/Processors/QueryPlan/QueryPlan.cpp:0: DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&) @ 0x461e6daa in /home/ubuntu/memory-ch/clickhouse
11. ./build_docker/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:370: DB::InterpreterSelectWithUnionQuery::execute() @ 0x41206043 in /home/ubuntu/memory-ch/clickhouse
12. ./build_docker/../src/Interpreters/executeQuery.cpp:697: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x41e32b22 in /home/ubuntu/memory-ch/clickhouse
13. ./build_docker/../src/Interpreters/executeQuery.cpp:1093: 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) @ 0x41e264fd in /home/ubuntu/memory-ch/clickhouse
14. ./build_docker/../src/Server/TCPHandler.cpp:362: DB::TCPHandler::runImpl() @ 0x451f40df in /home/ubuntu/memory-ch/clickhouse
15. ./build_docker/../src/Server/TCPHandler.cpp:1884: DB::TCPHandler::run() @ 0x45232cfe in /home/ubuntu/memory-ch/clickhouse
16. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x50cc40be in /home/ubuntu/memory-ch/clickhouse
17. ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:312: Poco::Net::TCPServerDispatcher::run() @ 0x50cc544f in /home/ubuntu/memory-ch/clickhouse
18. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:0: Poco::PooledThread::run() @ 0x513e1b2c in /home/ubuntu/memory-ch/clickhouse
19. ./build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x513dd582 in /home/ubuntu/memory-ch/clickhouse
20. ./build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:360: Poco::ThreadImpl::runnableEntry(void*) @ 0x513d9469 in /home/ubuntu/memory-ch/clickhouse
21. ? @ 0x7fdeb81b8609 in ?
22. clone @ 0x7fdeb80dd163 in ?

same error

SELECT MIN(t0.c2) FROM t0 GROUP BY t0.c1 HAVING (t0.c1) AND (t0.c1) SETTINGS 
enable_optimize_predicate_expression=0;```

Activity

  1. added
    fuzz
    sqlancer
    on Oct 17, 2022
  2. alexey-milovidov commented on Oct 21, 2022

    @alexey-milovidov
    Member
  3. qoega commented on Oct 21, 2022

    @qoega
    MemberAuthor

    Unknown column: t1.c0, there are only columns c0. (UNKNOWN_IDENTIFIER)

    Similar problems with identifiers. We can say that t1.c0 is not under aggregate function or not a group by column.

    SELECT t1.c0
    FROM t3, t1
    GROUP BY t3.c0
    
    Query id: aa153bba-1a60-41fc-a455-292d8ee58efd
    
    
    0 rows in set. Elapsed: 0.014 sec.
    
    Received exception from server (version 22.10.1):
    Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown column: t1.c0, there are only columns c0. (UNKNOWN_IDENTIFIER)
    
    ip-172-31-0-52 :) desc t1
                      ;
    
    DESCRIBE TABLE t1
    
    Query id: 54af37e5-cc15-4d14-b0a0-3a51c2f8ff42
    
    ┌─name─┬─type───┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
    │ c0   │ String │              │                    │         │                  │                │
    └──────┴────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘
    
  4. qoega commented on Oct 21, 2022

    @qoega
    MemberAuthor
    DROP DATABASE IF EXISTS database0TLPWhere_TLPGroupBy;
    CREATE DATABASE IF NOT EXISTS database0TLPWhere_TLPGroupBy;
    USE database0TLPWhere_TLPGroupBy;
    CREATE TABLE IF NOT EXISTS database0TLPWhere_TLPGroupBy.t0 (c0 Int32) ENGINE = Memory() ;
    CREATE TABLE database0TLPWhere_TLPGroupBy.t1 (c0 Int32, c1 Int32, c2 Int32) ENGINE = Memory() ;
    CREATE TABLE database0TLPWhere_TLPGroupBy.t2 (c0 String, c1 String MATERIALIZED (c2), c2 Int32) ENGINE = Memory() ;
    CREATE TABLE database0TLPWhere_TLPGroupBy.t3 (c0 String, c1 String, c2 String) ENGINE = Log() ;
    CREATE TABLE IF NOT EXISTS database0TLPWhere_TLPGroupBy.t4 (c0 Int32) ENGINE = Log() ;
    SELECT t3.c1, t3.c2, t1.c1, t1.c0, t2.c2, t0.c0, t1.c2, t2.c1, t4.c0 FROM t3, t0, t1, t2, t4;
    
    Code: 10. DB::Exception: Received from localhost:9000. DB::Exception: Not found column c1 in block. Stack trace:
    
    0. ./build_docker/../contrib/libcxx/include/exception:133: Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x512255aa in /home/ubuntu/memory-ch/clickhouse
    1. ./build_docker/../src/Common/Exception.cpp:0: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x25c62793 in /home/ubuntu/memory-ch/clickhouse
    2. DB::Exception::Exception<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(int, fmt::v8::basic_format_string<char, fmt::v8::type_identity<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>::type>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0xd137ded in /home/ubuntu/memory-ch/clickhouse
    3. ./build_docker/../src/Interpreters/ActionsDAG.cpp:565: DB::ActionsDAG::updateHeader(DB::Block) const @ 0x3e4a2f7a in /home/ubuntu/memory-ch/clickhouse
    4. ./build_docker/../src/Core/Block.h:25: DB::ExpressionTransform::transformHeader(DB::Block, DB::ActionsDAG const&) @ 0x45bdc062 in /home/ubuntu/memory-ch/clickhouse
    5. ./build_docker/../contrib/libcxx/include/__memory/shared_ptr.h:816: DB::ExpressionStep::ExpressionStep(DB::DataStream const&, std::__1::shared_ptr<DB::ActionsDAG> const&) @ 0x4613d25b in /home/ubuntu/memory-ch/clickhouse
    6. ./build_docker/../contrib/libcxx/include/string:1476: DB::InterpreterSelectQuery::executeProjection(DB::QueryPlan&, std::__1::shared_ptr<DB::ActionsDAG> const&) @ 0x41119e7e in /home/ubuntu/memory-ch/clickhouse
    7. ./build_docker/../src/Interpreters/InterpreterSelectQuery.cpp:0: DB::InterpreterSelectQuery::executeImpl(DB::QueryPlan&, std::__1::optional<DB::Pipe>) @ 0x410df428 in /home/ubuntu/memory-ch/clickhouse
    8. ./build_docker/../contrib/libcxx/include/optional:237: DB::InterpreterSelectQuery::buildQueryPlan(DB::QueryPlan&) @ 0x410d8656 in /home/ubuntu/memory-ch/clickhouse
    9. ./build_docker/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:294: DB::InterpreterSelectWithUnionQuery::buildQueryPlan(DB::QueryPlan&) @ 0x412026ad in /home/ubuntu/memory-ch/clickhouse
    10. ./build_docker/../src/Interpreters/InterpreterSelectQuery.cpp:0: DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::QueryPlan&) @ 0x410f9028 in /home/ubuntu/memory-ch/clickhouse
    11. ./build_docker/../src/Interpreters/InterpreterSelectQuery.cpp:1297: DB::InterpreterSelectQuery::executeImpl(DB::QueryPlan&, std::__1::optional<DB::Pipe>) @ 0x410dae49 in /home/ubuntu/memory-ch/clickhouse
    12. ./build_docker/../contrib/libcxx/include/optional:237: DB::InterpreterSelectQuery::buildQueryPlan(DB::QueryPlan&) @ 0x410d8656 in /home/ubuntu/memory-ch/clickhouse
    13. ./build_docker/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:294: DB::InterpreterSelectWithUnionQuery::buildQueryPlan(DB::QueryPlan&) @ 0x412026ad in /home/ubuntu/memory-ch/clickhouse
    14. ./build_docker/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:0: DB::InterpreterSelectWithUnionQuery::execute() @ 0x41205dd3 in /home/ubuntu/memory-ch/clickhouse
    15. ./build_docker/../src/Interpreters/executeQuery.cpp:697: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x41e32b22 in /home/ubuntu/memory-ch/clickhouse
    16. ./build_docker/../src/Interpreters/executeQuery.cpp:1093: 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) @ 0x41e264fd in /home/ubuntu/memory-ch/clickhouse
    17. ./build_docker/../src/Server/TCPHandler.cpp:362: DB::TCPHandler::runImpl() @ 0x451f40df in /home/ubuntu/memory-ch/clickhouse
    18. ./build_docker/../src/Server/TCPHandler.cpp:1884: DB::TCPHandler::run() @ 0x45232cfe in /home/ubuntu/memory-ch/clickhouse
    19. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x50cc40be in /home/ubuntu/memory-ch/clickhouse
    20. ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:312: Poco::Net::TCPServerDispatcher::run() @ 0x50cc544f in /home/ubuntu/memory-ch/clickhouse
    21. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:0: Poco::PooledThread::run() @ 0x513e1b2c in /home/ubuntu/memory-ch/clickhouse
    22. ./build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x513dd582 in /home/ubuntu/memory-ch/clickhouse
    23. ./build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:360: Poco::ThreadImpl::runnableEntry(void*) @ 0x513d9469 in /home/ubuntu/memory-ch/clickhouse
    24. ? @ 0x7fdeb81b8609 in ?
    25. clone @ 0x7fdeb80dd163 in ?
    . (NOT_FOUND_COLUMN_IN_BLOCK)
    
  5. qoega commented on Mar 7, 2023

    @qoega
    MemberAuthor

    Analyzer will fix this

    DROP DATABASE IF EXISTS database0TLPWhere_TLPGroupBy;
                      CREATE DATABASE IF NOT EXISTS database0TLPWhere_TLPGroupBy;
                      USE database0TLPWhere_TLPGroupBy;
                      CREATE TABLE IF NOT EXISTS database0TLPWhere_TLPGroupBy.t0 (c0 Int32) ENGINE = Memory() ;
                      CREATE TABLE database0TLPWhere_TLPGroupBy.t1 (c0 Int32, c1 Int32, c2 Int32) ENGINE = Memory() ;
                      CREATE TABLE database0TLPWhere_TLPGroupBy.t2 (c0 String, c1 String MATERIALIZED (c2), c2 Int32) ENGINE = Memory() ;
                      CREATE TABLE database0TLPWhere_TLPGroupBy.t3 (c0 String, c1 String, c2 String) ENGINE = Log() ;
                      CREATE TABLE IF NOT EXISTS database0TLPWhere_TLPGroupBy.t4 (c0 Int32) ENGINE = Log() ;
                      SELECT t3.c1, t3.c2, t1.c1, t1.c0, t2.c2, t0.c0, t1.c2, t2.c1, t4.c0 FROM t3, t0, t1, t2, t4 SETTINGS allow_experimental_analyzer=1;
    
    Ok.
    
    0 rows in set. Elapsed: 0.055 sec.
  6. added a commit that references this issue on Apr 2, 2024
  7. removed
    sqlancer
    on Jul 13, 2026
  8. added
    comp-query-optimizer
    on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-query-optimizerfuzz

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions