2011-10-31 17:55:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-05-28 10:15:36 +00:00
|
|
|
#include <mutex>
|
2012-11-30 04:28:13 +00:00
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#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
|
|
|
*/
|
2020-03-19 23:48:53 +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:
|
2019-07-09 15:40:21 +00:00
|
|
|
String getName() const override { return "Memory"; }
|
2011-10-31 17:55:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t getSize() const { return data.size(); }
|
2014-03-19 15:07:29 +00:00
|
|
|
|
2020-02-19 16:07:28 +00:00
|
|
|
Pipes read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2017-07-15 03:48:36 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
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
|
|
|
|
2019-02-27 18:26:24 +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
|
|
|
|
2020-03-29 08:02:35 +00:00
|
|
|
std::optional<UInt64> totalRows() const override;
|
2020-03-29 08:52:10 +00:00
|
|
|
std::optional<UInt64> totalBytes() const override;
|
2020-03-29 08:02:35 +00:00
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
BlocksList data;
|
2012-11-30 04:28:13 +00:00
|
|
|
|
2020-03-29 08:02:35 +00:00
|
|
|
mutable std::mutex mutex;
|
2014-10-26 00:01:36 +00:00
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|