```
CREATE DATABASE fuzz;
USE fuzz;

CREATE TABLE test_s64_local (date Date, value Int64) ENGINE = MergeTree(date, date, 8192);
CREATE TABLE test_u64_local (date Date, value UInt64) ENGINE = MergeTree(date, date, 8192);
CREATE TABLE test_s64_distributed AS test_s64_local ENGINE = Distributed('test_shard_localhost', currentDatabase(), test_s64_local, rand());
CREATE TABLE test_u64_distributed AS test_u64_local ENGINE = Distributed('test_shard_localhost', currentDatabase(), test_u64_local, rand());

SELECT * FROM merge(currentDatabase(), '') WHERE value = 1048575

[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.858301 [ 201 ] <Fatal> BaseDaemon: ########################################
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.858807 [ 201 ] <Fatal> BaseDaemon: (version 20.10.1.4614, build id: B4A1B0622B6A7D03) (from thread 97) (query_id: 831c8b30-0013-4edb-a43b-abda6845f302) Received signal Aborted (6)
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.859002 [ 201 ] <Fatal> BaseDaemon: 
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.859195 [ 201 ] <Fatal> BaseDaemon: Stack trace: 0x7f5573666f47 0x7f55736688b1 0x7f557365842a 0x7f55736584a2 0x2122ba21 0x2c130279 0x2c12f983 0x2c12db5e 0x2cbb95cd 0x2b9a6124 0x2b99aaf3 0x2b99445c 0x2b9939a6 0x2bc9e4e8 0x2bc9e7b6 0x2be59a66 0x2be58a2a 0x2c7a6a26 0x2c7adee8 0x304456bc 0x30445ecc 0x30587cd3 0x30584c0d 0x30583a98 0x7f5573e2c6db 0x7f5573749a3f
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.859566 [ 201 ] <Fatal> BaseDaemon: 4. /build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51: raise @ 0x3ef47 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.859865 [ 201 ] <Fatal> BaseDaemon: 5. /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81: __GI_abort @ 0x408b1 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.860117 [ 201 ] <Fatal> BaseDaemon: 6. /build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89: __assert_fail_base @ 0x3042a in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.860575 [ 201 ] <Fatal> BaseDaemon: 7. ? @ 0x304a2 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.860948 [ 201 ] <Fatal> BaseDaemon: 8. /build/obj-x86_64-linux-gnu/../src/Common/Exception.cpp:48: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x2122ba21 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.884484 [ 201 ] <Fatal> BaseDaemon: 9. /build/obj-x86_64-linux-gnu/../src/Storages/StorageMerge.cpp:507: DB::StorageMerge::convertingSourceStream(DB::Block const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::Context const&, std::__1::shared_ptr<DB::IAST>&, DB::Pipe&, DB::QueryProcessingStage::Enum) @ 0x2c130279 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.907480 [ 201 ] <Fatal> BaseDaemon: 10. /build/obj-x86_64-linux-gnu/../src/Storages/StorageMerge.cpp:331: DB::StorageMerge::createSources(std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo const&, DB::QueryProcessingStage::Enum const&, unsigned long, DB::Block const&, std::__1::tuple<std::__1::shared_ptr<DB::IStorage>, std::__1::shared_ptr<DB::RWLockImpl::LockHolderImpl>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > 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> > > >&, std::__1::shared_ptr<DB::Context> const&, unsigned long, bool, bool) @ 0x2c12f983 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.931791 [ 201 ] <Fatal> BaseDaemon: 11. /build/obj-x86_64-linux-gnu/../src/Storages/StorageMerge.cpp:234: DB::StorageMerge::read(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&, DB::SelectQueryInfo const&, DB::Context const&, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0x2c12db5e in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.962385 [ 201 ] <Fatal> BaseDaemon: 12. /build/obj-x86_64-linux-gnu/../src/Processors/QueryPlan/ReadFromStorageStep.cpp:39: DB::ReadFromStorageStep::ReadFromStorageStep(std::__1::shared_ptr<DB::RWLockImpl::LockHolderImpl>, std::__1::shared_ptr<DB::StorageInMemoryMetadata const>&, DB::SelectQueryOptions, std::__1::shared_ptr<DB::IStorage>, 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&, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::Context>, DB::QueryProcessingStage::Enum, unsigned long, unsigned long) @ 0x2cbb95cd in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:25.981633 [ 201 ] <Fatal> BaseDaemon: 13. /build/obj-x86_64-linux-gnu/../contrib/libcxx/include/memory:3028: std::__1::__unique_if<DB::ReadFromStorageStep>::__unique_single std::__1::make_unique<DB::ReadFromStorageStep, std::__1::shared_ptr<DB::RWLockImpl::LockHolderImpl>&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const>&, DB::SelectQueryOptions&, std::__1::shared_ptr<DB::IStorage>&, 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> > > >&, DB::SelectQueryInfo&, std::__1::shared_ptr<DB::Context>&, DB::QueryProcessingStage::Enum&, unsigned long&, unsigned long&>(std::__1::shared_ptr<DB::RWLockImpl::LockHolderImpl>&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const>&, DB::SelectQueryOptions&, std::__1::shared_ptr<DB::IStorage>&, 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> > > >&, DB::SelectQueryInfo&, std::__1::shared_ptr<DB::Context>&, DB::QueryProcessingStage::Enum&, unsigned long&, unsigned long&) @ 0x2b9a6124 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.000202 [ 201 ] <Fatal> BaseDaemon: 14. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:1412: DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::QueryPlan&, std::__1::shared_ptr<DB::PrewhereInfo> 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&) @ 0x2b99aaf3 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.019178 [ 201 ] <Fatal> BaseDaemon: 15. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:810: DB::InterpreterSelectQuery::executeImpl(DB::QueryPlan&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>) @ 0x2b99445c in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.037936 [ 201 ] <Fatal> BaseDaemon: 16. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:471: DB::InterpreterSelectQuery::buildQueryPlan(DB::QueryPlan&) @ 0x2b9939a6 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.057048 [ 201 ] <Fatal> BaseDaemon: 17. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:183: DB::InterpreterSelectWithUnionQuery::buildQueryPlan(DB::QueryPlan&) @ 0x2bc9e4e8 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.075531 [ 201 ] <Fatal> BaseDaemon: 18. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:206: DB::InterpreterSelectWithUnionQuery::execute() @ 0x2bc9e7b6 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.096688 [ 201 ] <Fatal> BaseDaemon: 19. /build/obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:392: DB::executeQueryImpl(char const*, char const*, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool, DB::ReadBuffer*) @ 0x2be59a66 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.119308 [ 201 ] <Fatal> BaseDaemon: 20. /build/obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:679: DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool) @ 0x2be58a2a in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.146743 [ 201 ] <Fatal> BaseDaemon: 21. /build/obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:253: DB::TCPHandler::runImpl() @ 0x2c7a6a26 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.174615 [ 201 ] <Fatal> BaseDaemon: 22. /build/obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:1217: DB::TCPHandler::run() @ 0x2c7adee8 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.208762 [ 201 ] <Fatal> BaseDaemon: 23. /build/obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerConnection.cpp:43: Poco::Net::TCPServerConnection::start() @ 0x304456bc in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.244270 [ 201 ] <Fatal> BaseDaemon: 24. /build/obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerDispatcher.cpp:114: Poco::Net::TCPServerDispatcher::run() @ 0x30445ecc in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.278996 [ 201 ] <Fatal> BaseDaemon: 25. /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/ThreadPool.cpp:199: Poco::PooledThread::run() @ 0x30587cd3 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.314520 [ 201 ] <Fatal> BaseDaemon: 26. /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x30584c0d in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.350760 [ 201 ] <Fatal> BaseDaemon: 27. /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Thread_POSIX.cpp:345: Poco::ThreadImpl::runnableEntry(void*) @ 0x30583a98 in /workspace/clickhouse
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.351062 [ 201 ] <Fatal> BaseDaemon: 28. start_thread @ 0x76db in /lib/x86_64-linux-gnu/libpthread-2.27.so
[linux-ubuntu-14-04-trusty] 2020.09.10 15:31:26.351423 [ 201 ] <Fatal> BaseDaemon: 29. /build/glibc-2ORdQG/glibc-2.27/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:97: __clone @ 0x121a3f in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so
Error on processing query 'SELECT * FROM merge(currentDatabase(), '') WHERE value = 1048575': Code: 32, e.displayText() = DB::Exception: Attempt to read after eof: while receiving packet from localhost:9000, Stack trace (when copying this message, always include the lines below):
```

https://clickhouse-test-reports.s3.yandex.net/14563/20b3823770f60feefcd73306141bc25875d87f9a/fuzzer/report.html#fail1
if (!where_expression)
        return;
    if (processed_stage > QueryProcessingStage::FetchColumns)
    {
        for (size_t column_index : collections::range(0, header.columns()))
        {
            ColumnWithTypeAndName header_column = header.getByPosition(column_index);
            ColumnWithTypeAndName before_column = before_block_header.getByName(header_column.name);
            
            
            
            if (!header_column.type->equals(*before_column.type.get()))
            {
                NamesAndTypesList source_columns = metadata_snapshot->getSampleBlock().getNamesAndTypesList();
                auto virtual_column = *storage_merge->getVirtuals().tryGetByName("_table");
                source_columns.emplace_back(NameAndTypePair{virtual_column.name, virtual_column.type});
                auto syntax_result = TreeRewriter(local_context).analyze(where_expression, source_columns);
                ExpressionActionsPtr actions = ExpressionAnalyzer{where_expression, syntax_result, local_context}.getActions(false, false);
                Names required_columns = actions->getRequiredColumns();
                for (const auto & required_column : required_columns)
                {
                    if (required_column == header_column.name)
                        throw Exception("Block structure mismatch in Merge Storage: different types:\n" + before_block_header.dumpStructure()
                                        + "\n" + header.dumpStructure(), ErrorCodes::LOGICAL_ERROR);
                }
            }
        }
    }
}
IStorage::ColumnSizeByName StorageMerge::getColumnSizes() const