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

Memory limit should be respected.
: SourceWithProgress(
            metadata_snapshot->getSampleBlockForColumns(column_names_, storage.getVirtuals(), storage.getStorageID()))
        , column_names(column_names_.begin(), column_names_.end())
        , buffer(buffer_) {}
    String getName() const override { return "Buffer"; }
protected:
    Chunk generate() override
    {
        Chunk res;
        if (has_been_read)
            return res;
        has_been_read = true;
        std::lock_guard lock(buffer.mutex);
        if (!buffer.data.rows())
            return res;
        Columns columns;
        columns.reserve(column_names.size());
        for (const auto & name : column_names)
            columns.push_back(buffer.data.getByName(name).column);
        UInt64 size = columns.at(0)->size();
        res.setColumns(std::move(columns), size);
        return res;
    }
private:
    Names column_names;
    StorageBuffer::Buffer & buffer;
    bool has_been_read = false;
};
QueryProcessingStage::Enum StorageBuffer::getQueryProcessingStage(const Context & context, QueryProcessingStage::Enum to_stage, const ASTPtr & query_ptr) const