ClickHouse/dbms/Storages/StorageMemory.h

59 lines
1.6 KiB
C++
Raw Normal View History

2011-10-31 17:55:06 +00:00
#pragma once
#include <mutex>
2017-06-06 17:18:32 +00:00
#include <ext/shared_ptr_helper.h>
#include <Core/NamesAndTypes.h>
#include <Storages/IStorage.h>
#include <DataStreams/IBlockOutputStream.h>
2011-10-31 17:55:06 +00:00
namespace DB
{
2017-04-16 15:00:33 +00:00
/** Implements storage in the RAM.
* Suitable for temporary data.
* It does not support keys.
* Data is stored as a set of blocks and is not stored anywhere else.
2011-10-31 17:55:06 +00:00
*/
class StorageMemory final : public ext::shared_ptr_helper<StorageMemory>, public IStorage
2011-10-31 17:55:06 +00:00
{
friend class MemoryBlockInputStream;
friend class MemoryBlockOutputStream;
2019-08-26 19:07:29 +00:00
friend struct ext::shared_ptr_helper<StorageMemory>;
2011-10-31 17:55:06 +00:00
public:
String getName() const override { return "Memory"; }
2011-10-31 17:55:06 +00:00
size_t getSize() const { return data.size(); }
Pipes read(
const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
2017-06-02 15:54:39 +00:00
unsigned num_streams) override;
2011-10-31 17:55:06 +00:00
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
2011-10-31 17:55:06 +00:00
2019-08-27 20:43:08 +00:00
void drop(TableStructureWriteLockHolder &) override;
2018-04-21 00:35:20 +00:00
2019-08-27 20:43:08 +00:00
void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override;
2018-04-21 00:35:20 +00:00
std::optional<UInt64> totalRows() const override;
std::optional<UInt64> totalBytes() const override;
2011-10-31 17:55:06 +00:00
private:
2017-04-16 15:00:33 +00:00
/// The data itself. `list` - so that when inserted to the end, the existing iterators are not invalidated.
BlocksList data;
mutable std::mutex mutex;
protected:
2019-12-04 16:06:55 +00:00
StorageMemory(const StorageID & table_id_, ColumnsDescription columns_description_, ConstraintsDescription constraints_);
2011-10-31 17:55:06 +00:00
};
}