Skip to content

alter table + prewhere: Not found column ... in block #2827

Closed

Description

@den-crane

ClickHouse client version 18.6.0.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 18.6.0 revision 54401.

create table y(a Int64, b Int64, z Date) engine = MergeTree partition by (a,z) order by tuple();
insert into y select 1,number, toDate('2018-01-01') from numbers(1);
insert into y select 2,number, toDate('2018-02-01') from numbers(1);
alter table y add column c Array(Float32);
alter table y add column d Array(Float32);

select c,d from y prewhere a <1000;
Received exception from server (version 18.6.0):
Code: 10. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Not found column c in block. There are only columns: a.

Activity

  1. den-crane commented on Aug 8, 2018

    @den-crane
    ContributorAuthor

    Though

    SELECT *
    FROM y
    PREWHERE a < 1000
    
    ┌─a─┬─b─┬──────────z─┬─c──┬─d──┐
    │ 1 │ 0 │ 2018-01-01 │ [] │ [] │
    └───┴───┴────────────┴────┴────┘
    ┌─a─┬─b─┬──────────z─┬─c──┬─d──┐
    │ 2 │ 0 │ 2018-02-01 │ [] │ [] │
    └───┴───┴────────────┴────┴────┘
    
  2. added
    bug
    on Aug 17, 2018
  3. changed the title [-]DB::Exception: Not found column ... in block[/-] [+]alter table + prewhere: Not found column ... in block[/+] on Aug 17, 2018
  4. 4ertus2 commented on Aug 17, 2018

    @4ertus2
    Contributor

    18.10.3

    drop table if exists t;
    create table t
    (
    a Int32,
    b Int32
    ) engine = MergeTree partition by (a,b) order by (a);

    insert into t values (1, 1);
    alter table t add column c Int32;

    select b from t prewhere a < 1000; -- OK
    select c from t where a < 1000; -- OK
    select c from t prewhere a < 1000;
    -- Block structure mismatch in MergeTreeThread stream: different number of columns:
    -- a Int32 Int32(size = 1)
    -- a Int32 Int32(size = 0), c Int32 Int32(size = 0).

  5. alexey-milovidov commented on Aug 20, 2018

    @alexey-milovidov
    Member

    It is started to work in master.
    This is related to changes in #2226

  6. alexey-milovidov commented on Aug 20, 2018

    @alexey-milovidov
    Member

    Not quite.
    The last query returns empty set while it should return the same result as the previous query.

  7. alexey-milovidov commented on Aug 20, 2018

    @alexey-milovidov
    Member

    Ready test case:

    drop table if exists test.t;
    create table test.t
    (
    a Int32,
    b Int32
    ) engine = MergeTree partition by (a,b) order by (a);
    
    insert into test.t values (1, 1);
    alter table test.t add column c Int32;
    
    select b from test.t prewhere a < 1000;
    select c from test.t where a < 1000;
    select c from test.t prewhere a < 1000;
    
    drop table test.t;
    
  8. wake-up-neo commented on Sep 19, 2018

    @wake-up-neo
    Contributor

    @alexey-milovidov Please take a look

    drop table if exists test.trepl;
    create table test.trepl
    (
    d Date,
    a Int32,
    b Int32
    ) engine = ReplacingMergeTree(d, (a,b), 8192);
    
    
    insert into test.trepl values ('2018-09-19', 1, 1);
    select b from test.trepl FINAL prewhere a < 1000;
    drop table test.trepl;
    

    Received exception from server (version 18.12.17):
    Code: 10. DB::Exception: Received from localhost:9002, 127.0.0.1. DB::Exception: Not found column a in block. There are only columns: b.

  9. wake-up-neo commented on Sep 19, 2018

    @wake-up-neo
    Contributor

    The same for CollapsingMergeTree, and only with FINAL.

    2018.09.19 15:15:56.804624 [ 54 ] {f446cb2b-b4af-4fad-a082-5b2bac65e6cf} executeQuery: Code: 10, e.displayText() = DB::Exception: Not found column a in block. There are only columns: b, sign, e.what() = DB::Exception (from 127.0.0.1:52210) (in query: select b from test.trepl FINAL prewhere a < 1000), Stack trace:

    1. clickhouse-server(StackTrace::StackTrace()+0x16) [0x9491e46]
    2. clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)+0x22) [0x3019952]
    3. clickhouse-server(DB::Block::getPositionByName(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const+0xd5) [0x6963065]
    4. clickhouse-server(DB::MergeTreeDataSelectExecutor::spreadMarkRangesAmongStreamsFinal(std::vector<DB::RangesInDataPart, std::allocatorDB::RangesInDataPart >&&, std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, unsigned long, bool, std::shared_ptrDB::PrewhereInfo const&, std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, DB::Settings const&) const+0x670) [0x7374eb0]
    5. clickhouse-server(DB::MergeTreeDataSelectExecutor::readFromParts(std::vector<std::shared_ptr<DB::MergeTreeDataPart const>, std::allocator<std::shared_ptr<DB::MergeTreeDataPart const> > >, std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, DB::SelectQueryInfo const&, DB::Context const&, unsigned long, unsigned int, long) const+0x3650) [0x737a080]
    6. clickhouse-server(DB::MergeTreeDataSelectExecutor::read(std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, DB::SelectQueryInfo const&, DB::Context const&, unsigned long, unsigned int, long) const+0x6f) [0x737b23f]
    7. clickhouse-server(DB::StorageMergeTree::read(std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, DB::SelectQueryInfo const&, DB::Context const&, DB::QueryProcessingStage::Enum, unsigned long, unsigned int)+0x31) [0x7285d51]
    8. clickhouse-server(DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::InterpreterSelectQuery::Pipeline&, std::shared_ptrDB::PrewhereInfo const&)+0x1734) [0x70ff594]
    9. clickhouse-server(DB::InterpreterSelectQuery::executeImpl(DB::InterpreterSelectQuery::Pipeline&, std::shared_ptrDB::IBlockInputStream const&, bool)+0x3d6) [0x7102476]
    10. clickhouse-server(DB::InterpreterSelectQuery::executeWithMultipleStreams()+0x4e) [0x7104dee]
    11. clickhouse-server(DB::InterpreterSelectWithUnionQuery::executeWithMultipleStreams()+0x6c) [0x710ff1c]
    12. clickhouse-server(DB::InterpreterSelectWithUnionQuery::execute()+0x38) [0x71101e8]
    13. clickhouse-server() [0x71a0727]
    14. clickhouse-server(DB::executeQuery(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum)+0x8a) [0x71a245a]
    15. clickhouse-server(DB::TCPHandler::runImpl()+0x4d9) [0x3027179]
    16. clickhouse-server(DB::TCPHandler::run()+0x2b) [0x302836b]
    17. clickhouse-server(Poco::Net::TCPServerConnection::start()+0xf) [0x96107df]
    18. clickhouse-server(Poco::Net::TCPServerDispatcher::run()+0x16a) [0x9610bba]
    19. clickhouse-server(Poco::PooledThread::run()+0x77) [0x972d6b7]
    20. clickhouse-server(Poco::ThreadImpl::runnableEntry(void*)+0x38) [0x9729228]
    21. clickhouse-server() [0x9e659ef]
    22. /lib/x86_64-linux-gnu/libpthread.so.0(+0x8064) [0x7f83458cf064]
    23. /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f8344ef762d]
  10. added a commit that references this issue on Nov 23, 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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions