**Describe the bug**
Reported here https://github.com/ClickHouse/ClickHouse/pull/44856#issuecomment-1369774957

Stacktrace:
```
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:24:26.939633 [ 16775 ] {e8a70e3e-4974-4b69-9aac-0b3ed28e8c99} <Fatal> : Logical error: 'column->size() == num_rows'.
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.372458 [ 30508 ] {} <Fatal> BaseDaemon: ########################################
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.372724 [ 30508 ] {} <Fatal> BaseDaemon: (version 22.13.1.1, build id: 74A4889C2922DC5D162A4F4A73419B679934A6AA) (from thread 16775) (query_id: e8a70e3e-4974-4b69-9aac-0b3ed28e8c99) (query: SELECT uniq(SearchPhrase), max(URL), max(Title), count() AS c, uniq(UserID) FROM test.hits_s3 WHERE Title LIKE '%Яндекс%' AND URL NOT LIKE '%.yandex.%' AND SearchPhrase != '' GROUP BY SearchPhrase ORDER BY c DESC LIMIT 10;) Received signal Aborted (6)
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.373025 [ 30508 ] {} <Fatal> BaseDaemon: 
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.373286 [ 30508 ] {} <Fatal> BaseDaemon: Stack trace: 0x7f3d0e0bf00b 0x7f3d0e09e859 0x210404f6 0x2b9295b2 0x2b934278 0x2b934255 0x2b92e2b5 0x2b92d3a9 0x2b9327de 0x2b930cb8 0x2b92fa12 0x2b9135c6 0x2b913e71 0x2b912519 0x2b95c9d7 0x2b225b0b 0x2b266683 0x2b266386 0x2b244fa1 0x2b2452b7 0x2b246878 0x2b2467d5 0x2b2467b9 0x2b24671d 0x2b246622 0x2b246595 0x2b246575 0x2b246555 0x2b246520 0x21094276 0x21090175 0x2117d3bc 0x211840a4 0x21184055 0x21183f7d 0x21183a62 0x7f3d0e276609 0x7f3d0e19b133
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.373491 [ 30508 ] {} <Fatal> BaseDaemon: 4. raise @ 0x7f3d0e0bf00b in ?
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.373636 [ 30508 ] {} <Fatal> BaseDaemon: 5. abort @ 0x7f3d0e09e859 in ?
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.677873 [ 30508 ] {} <Fatal> BaseDaemon: 6. /build/build_docker/../src/Common/Exception.cpp:41: DB::abortOnFailedAssertion(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) @ 0x210404f6 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:01.983076 [ 30508 ] {} <Fatal> BaseDaemon: 7. /build/build_docker/../src/Storages/MergeTree/MergeTreeRangeReader.cpp:384: DB::MergeTreeRangeReader::ReadResult::checkInternalConsistency() const @ 0x2b9295b2 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.159296 [ 30508 ] {} <Fatal> BaseDaemon: 8. /build/build_docker/../src/Storages/MergeTree/MergeTreeRangeReader.cpp:519: DB::MergeTreeRangeReader::ReadResult::optimize(DB::FilterWithCachedCount const&, bool)::$_0::operator()() const @ 0x2b934278 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.303253 [ 30508 ] {} <Fatal> BaseDaemon: 9. /build/build_docker/../base/base/scope_guard.h:100: BasicScopeGuard<DB::MergeTreeRangeReader::ReadResult::optimize(DB::FilterWithCachedCount const&, bool)::$_0>::invoke() @ 0x2b934255 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.425763 [ 30508 ] {} <Fatal> BaseDaemon: 10. /build/build_docker/../base/base/scope_guard.h:48: BasicScopeGuard<DB::MergeTreeRangeReader::ReadResult::optimize(DB::FilterWithCachedCount const&, bool)::$_0>::~BasicScopeGuard() @ 0x2b92e2b5 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.536338 [ 30508 ] {} <Fatal> BaseDaemon: 11. /build/build_docker/../src/Storages/MergeTree/MergeTreeRangeReader.cpp:617: DB::MergeTreeRangeReader::ReadResult::optimize(DB::FilterWithCachedCount const&, bool) @ 0x2b92d3a9 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.659802 [ 30508 ] {} <Fatal> BaseDaemon: 12. /build/build_docker/../src/Storages/MergeTree/MergeTreeRangeReader.cpp:1348: DB::MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(DB::MergeTreeRangeReader::ReadResult&) const @ 0x2b9327de in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.772166 [ 30508 ] {} <Fatal> BaseDaemon: 13. /build/build_docker/../src/Storages/MergeTree/MergeTreeRangeReader.cpp:1035: DB::MergeTreeRangeReader::read(unsigned long, std::__1::deque<DB::MarkRange, std::__1::allocator<DB::MarkRange>>&) @ 0x2b930cb8 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:02.880526 [ 30508 ] {} <Fatal> BaseDaemon: 14. /build/build_docker/../src/Storages/MergeTree/MergeTreeRangeReader.cpp:934: DB::MergeTreeRangeReader::read(unsigned long, std::__1::deque<DB::MarkRange, std::__1::allocator<DB::MarkRange>>&) @ 0x2b92fa12 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.160150 [ 30508 ] {} <Fatal> BaseDaemon: 15. /build/build_docker/../src/Storages/MergeTree/MergeTreeBaseSelectProcessor.cpp:404: DB::IMergeTreeSelectAlgorithm::readFromPartImpl() @ 0x2b9135c6 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.380608 [ 30508 ] {} <Fatal> BaseDaemon: 16. /build/build_docker/../src/Storages/MergeTree/MergeTreeBaseSelectProcessor.cpp:447: DB::IMergeTreeSelectAlgorithm::readFromPart() @ 0x2b913e71 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.581704 [ 30508 ] {} <Fatal> BaseDaemon: 17. /build/build_docker/../src/Storages/MergeTree/MergeTreeBaseSelectProcessor.cpp:224: DB::IMergeTreeSelectAlgorithm::read() @ 0x2b912519 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.662453 [ 30508 ] {} <Fatal> BaseDaemon: 18. /build/build_docker/../src/Storages/MergeTree/MergeTreeSource.cpp:214: DB::MergeTreeSource::tryGenerate() @ 0x2b95c9d7 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.740527 [ 30508 ] {} <Fatal> BaseDaemon: 19. /build/build_docker/../src/Processors/ISource.cpp:94: DB::ISource::work() @ 0x2b225b0b in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.781994 [ 30508 ] {} <Fatal> BaseDaemon: 20. /build/build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:47: DB::executeJob(DB::ExecutingGraph::Node*, DB::ReadProgressCallback*) @ 0x2b266683 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.815764 [ 30508 ] {} <Fatal> BaseDaemon: 21. /build/build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:92: DB::ExecutionThreadContext::executeTask() @ 0x2b266386 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:03.922886 [ 30508 ] {} <Fatal> BaseDaemon: 22. /build/build_docker/../src/Processors/Executors/PipelineExecutor.cpp:229: DB::PipelineExecutor::executeStepImpl(unsigned long, std::__1::atomic<bool>*) @ 0x2b244fa1 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.029655 [ 30508 ] {} <Fatal> BaseDaemon: 23. /build/build_docker/../src/Processors/Executors/PipelineExecutor.cpp:195: DB::PipelineExecutor::executeSingleThread(unsigned long) @ 0x2b2452b7 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.124007 [ 30508 ] {} <Fatal> BaseDaemon: 24. /build/build_docker/../src/Processors/Executors/PipelineExecutor.cpp:320: DB::PipelineExecutor::spawnThreads()::$_0::operator()() const @ 0x2b246878 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.233330 [ 30508 ] {} <Fatal> BaseDaemon: 25. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/invoke.h:394: decltype(std::declval<DB::PipelineExecutor::spawnThreads()::$_0&>()()) std::__1::__invoke[abi:v15000]<DB::PipelineExecutor::spawnThreads()::$_0&>(DB::PipelineExecutor::spawnThreads()::$_0&) @ 0x2b2467d5 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.350015 [ 30508 ] {} <Fatal> BaseDaemon: 26. /build/build_docker/../contrib/llvm-project/libcxx/include/tuple:1789: decltype(auto) std::__1::__apply_tuple_impl[abi:v15000]<DB::PipelineExecutor::spawnThreads()::$_0&, std::__1::tuple<>&>(DB::PipelineExecutor::spawnThreads()::$_0&, std::__1::tuple<>&, std::__1::__tuple_indices<>) @ 0x2b2467b9 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.456974 [ 30508 ] {} <Fatal> BaseDaemon: 27. /build/build_docker/../contrib/llvm-project/libcxx/include/tuple:1798: decltype(auto) std::__1::apply[abi:v15000]<DB::PipelineExecutor::spawnThreads()::$_0&, std::__1::tuple<>&>(DB::PipelineExecutor::spawnThreads()::$_0&, std::__1::tuple<>&) @ 0x2b24671d in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.546170 [ 30508 ] {} <Fatal> BaseDaemon: 28. /build/build_docker/../src/Common/ThreadPool.h:196: ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PipelineExecutor::spawnThreads()::$_0>(DB::PipelineExecutor::spawnThreads()::$_0&&)::'lambda'()::operator()() @ 0x2b246622 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.654787 [ 30508 ] {} <Fatal> BaseDaemon: 29. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/invoke.h:394: decltype(std::declval<DB::PipelineExecutor::spawnThreads()::$_0>()()) std::__1::__invoke[abi:v15000]<ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PipelineExecutor::spawnThreads()::$_0>(DB::PipelineExecutor::spawnThreads()::$_0&&)::'lambda'()&>(DB::PipelineExecutor::spawnThreads()::$_0&&) @ 0x2b246595 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.771892 [ 30508 ] {} <Fatal> BaseDaemon: 30. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/invoke.h:480: void std::__1::__invoke_void_return_wrapper<void, true>::__call<ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PipelineExecutor::spawnThreads()::$_0>(DB::PipelineExecutor::spawnThreads()::$_0&&)::'lambda'()&>(ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PipelineExecutor::spawnThreads()::$_0>(DB::PipelineExecutor::spawnThreads()::$_0&&)::'lambda'()&) @ 0x2b246575 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:04.882821 [ 30508 ] {} <Fatal> BaseDaemon: 31. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/function.h:235: std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PipelineExecutor::spawnThreads()::$_0>(DB::PipelineExecutor::spawnThreads()::$_0&&)::'lambda'(), void ()>::operator()[abi:v15000]() @ 0x2b246555 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.002626 [ 30508 ] {} <Fatal> BaseDaemon: 32. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/function.h:716: void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::PipelineExecutor::spawnThreads()::$_0>(DB::PipelineExecutor::spawnThreads()::$_0&&)::'lambda'(), void ()>>(std::__1::__function::__policy_storage const*) @ 0x2b246520 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.062907 [ 30508 ] {} <Fatal> BaseDaemon: 33. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/function.h:848: std::__1::__function::__policy_func<void ()>::operator()[abi:v15000]() const @ 0x21094276 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.114927 [ 30508 ] {} <Fatal> BaseDaemon: 34. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/function.h:1187: std::__1::function<void ()>::operator()() const @ 0x21090175 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.187246 [ 30508 ] {} <Fatal> BaseDaemon: 35. /build/build_docker/../src/Common/ThreadPool.cpp:295: ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0x2117d3bc in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.281199 [ 30508 ] {} <Fatal> BaseDaemon: 36. /build/build_docker/../src/Common/ThreadPool.cpp:144: void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, long, std::__1::optional<unsigned long>, bool)::'lambda0'()::operator()() const @ 0x211840a4 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.366690 [ 30508 ] {} <Fatal> BaseDaemon: 37. /build/build_docker/../contrib/llvm-project/libcxx/include/__functional/invoke.h:394: decltype(std::declval<void>()()) std::__1::__invoke[abi:v15000]<void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, long, std::__1::optional<unsigned long>, bool)::'lambda0'()>(void&&) @ 0x21184055 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.448964 [ 30508 ] {} <Fatal> BaseDaemon: 38. /build/build_docker/../contrib/llvm-project/libcxx/include/thread:285: void std::__1::__thread_execute[abi:v15000]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, long, std::__1::optional<unsigned long>, bool)::'lambda0'()>(std::__1::tuple<void, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, long, std::__1::optional<unsigned long>, bool)::'lambda0'()>&, std::__1::__tuple_indices<>) @ 0x21183f7d in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.err.log:2023.01.03 08:26:05.549886 [ 30508 ] {} <Fatal> BaseDaemon: 39. /build/build_docker/../contrib/llvm-project/libcxx/include/thread:295: void* std::__1::__thread_proxy[abi:v15000]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, long, std::__1::optional<unsigned long>, bool)::'lambda0'()>>(void*) @ 0x21183a62 in /usr/bin/clickhouse
```

**How to reproduce**
Try to reproduce the report and copy the tables and queries involved.

{
    size_t num_rows_before_current_mark = index_granularity->getMarkStartingRow(current_mark);
    return num_rows_before_current_mark + current_offset + num_delayed_rows;
}
size_t MergeTreeRangeReader::DelayedStream::readRows(Columns & columns, size_t num_rows)
{
    if (num_rows)
    {
        size_t rows_read = merge_tree_reader->readRows(
            current_mark, current_task_last_mark, continue_reading, num_rows, columns);
        continue_reading = true;
        
        
        
        
        if (0 < rows_read && rows_read < num_rows)
            is_finished = true;
        return rows_read;
    }
    return 0;
}
size_t MergeTreeRangeReader::DelayedStream::read(Columns & columns, size_t from_mark, size_t offset, size_t num_rows)