**Describe the bug**
```
| | | | | | | | | 5    0x000000000e3a5ec1 in DB::executeQueryImpl(char const*, char const*, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool, DB::ReadBuffer*) ()
| | | | | | | | | | 2    0x000000000e3aadc6 in DB::logQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context const&, bool) ()
| | | | | | | | | | | 2    0x000000000887a195 in DB::OwnSplitChannel::log(Poco::Message const&) ()
| | | | | | | | | | | | 2    0x000000000887a7fa in DB::OwnSplitChannel::logSplit(Poco::Message const&) ()
| | | | | | | | | | | | | 2    0x000000000887acb6 in DB::SystemLog<DB::TextLogElement>::add(DB::TextLogElement const&) ()
| | | | | | | | | | | | | | 1    0x0000000011976246 in std::__1::mutex::lock() ()
| | | | | | | | | | | | | | | 1    0x00000000087495a1 in pthread_mutex_lock ()
| | | | | | | | | | | | | | | | 1    0x00007f074da790a3 in __GI___pthread_mutex_lock at ../nptl/pthread_mutex_lock.c:80
| | | | | | | | | | | | | | | | | 1    __lll_lock_wait at lowlevellock.c:52
| | | | | | | | | | | | | 2    0x000000000887ae28 in DB::SystemLog<DB::TextLogElement>::add(DB::TextLogElement const&) ()
| | | | | | | | | | | | | | 1    0x000000000887c62c in void std::__1::vector<DB::TextLogElement, std::__1::allocator<DB::TextLogElement> >::__push_back_slow_path<DB::TextLogElement const&>(DB::TextLogElement const&) ()
| | | | | | | | | | | | | | | 1    0x00000000087156fb in operator new(unsigned long) ()
| | | | | | | | | | | | | | | | 1    0x0000000008727744 in MemoryTracker::alloc(long) ()
| | | | | | | | | | | | | | | | | 1    0x000000000872727c in MemoryTracker::logMemoryUsage(long) const ()
| | | | | | | | | | | | | | | | | | 1    0x000000000887a195 in DB::OwnSplitChannel::log(Poco::Message const&) ()
| | | | | | | | | | | | | | | | | | | 1    0x000000000887a7fa in DB::OwnSplitChannel::logSplit(Poco::Message const&) ()
| | | | | | | | | | | | | | | | | | | | 1    0x000000000887acb6 in DB::SystemLog<DB::TextLogElement>::add(DB::TextLogElement const&) ()
| | | | | | | | | | | | | | | | | | | | | 1    0x0000000011976246 in std::__1::mutex::lock() ()
| | | | | | | | | | | | | | | | | | | | | | 1    0x00000000087495a1 in pthread_mutex_lock ()
| | | | | | | | | | | | | | | | | | | | | | | 1    0x00007f074da790a3 in __GI___pthread_mutex_lock at ../nptl/pthread_mutex_lock.c:80
| | | | | | | | | | | | | | | | | | | | | | | | 1    __lll_lock_wait at lowlevellock.c:52
```

**How to reproduce**
```
clickhouse-benchmark -i 1000000 -c16 --secure --query "SELECT 1"
```
uint64_t requested_flush_before = 0;
    
    uint64_t flushed_before = 0;
    
    uint64_t logged_queue_full_at_index = -1;
    void savingThreadFunction();
    /** Creates new table if it does not exist.
      * Renames old table if its structure is not suitable.
      * This cannot be done in constructor to avoid deadlock while renaming a table under locked Context when SystemLog object is created.
      */
    void prepareTable() override;
    
    void flushImpl(const std::vector<LogElement> & to_flush, uint64_t to_flush_end);
};
template <typename LogElement>
SystemLog<LogElement>::SystemLog(Context & context_,
    const String & database_name_,
    const String & table_name_,
    const String & storage_def_,
    size_t flush_interval_milliseconds_)
    : context(context_)
    , table_id(database_name_, table_name_)
    , storage_def(storage_def_)
    , flush_interval_milliseconds(flush_interval_milliseconds_)
{
    assert(database_name_ == DatabaseCatalog::SYSTEM_DATABASE);
    log = &Poco::Logger::get("SystemLog (" + database_name_ + "." + table_name_ + ")");
}
template <typename LogElement>
void SystemLog<LogElement>::startup()