**Describe the bug**
`SELECT i FROM generateRandom('i Array(Int8)', 1048575, 10, 1048577) LIMIT 1048575`

Memory limit should be respected.
{
    Block block_to_write;
    time_t current_time = time(nullptr);
    size_t rows = 0;
    size_t bytes = 0;
    time_t time_passed = 0;
    std::unique_lock lock(buffer.mutex, std::defer_lock);
    if (!locked)
        lock.lock();
    block_to_write = buffer.data.cloneEmpty();
    rows = buffer.data.rows();
    bytes = buffer.data.bytes();
    if (buffer.first_write_time)
        time_passed = current_time - buffer.first_write_time;
    if (check_thresholds)
    {
        if (!checkThresholdsImpl(rows, bytes, time_passed))
            return;
    }
    else
    {
        if (rows == 0)
            return;
    }
    buffer.data.swap(block_to_write);
    buffer.first_write_time = 0;
    CurrentMetrics::sub(CurrentMetrics::StorageBufferRows, block_to_write.rows());
    CurrentMetrics::sub(CurrentMetrics::StorageBufferBytes, block_to_write.bytes());