2013-11-08 17:43:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Parsers/IAST_fwd.h>
|
2020-01-29 17:44:16 +00:00
|
|
|
#include <Parsers/ASTSelectWithUnionQuery.h>
|
|
|
|
|
2017-07-25 21:07:05 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2020-01-29 17:44:16 +00:00
|
|
|
#include <Storages/StorageInMemoryMetadata.h>
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-03-19 23:48:53 +00:00
|
|
|
class StorageMaterializedView final : public ext::shared_ptr_helper<StorageMaterializedView>, public IStorage
|
2016-08-26 21:25:05 +00:00
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageMaterializedView>;
|
2013-11-08 17:43:03 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "MaterializedView"; }
|
2020-01-24 16:20:36 +00:00
|
|
|
bool isView() const override { return true; }
|
2019-07-09 15:40:21 +00:00
|
|
|
|
2020-01-29 17:44:16 +00:00
|
|
|
ASTPtr getSelectQuery() const { return select->clone(); }
|
2018-06-03 20:39:06 +00:00
|
|
|
ASTPtr getInnerQuery() const { return inner_query->clone(); }
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2017-12-25 21:57:29 +00:00
|
|
|
NameAndTypePair getColumn(const String & column_name) const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool hasColumn(const String & column_name) const override;
|
2014-08-05 10:56:58 +00:00
|
|
|
|
2020-01-29 17:44:16 +00:00
|
|
|
StorageInMemoryMetadata getInMemoryMetadata() const override;
|
|
|
|
|
2017-10-21 20:08:49 +00:00
|
|
|
bool supportsSampling() const override { return getTargetTable()->supportsSampling(); }
|
|
|
|
bool supportsPrewhere() const override { return getTargetTable()->supportsPrewhere(); }
|
|
|
|
bool supportsFinal() const override { return getTargetTable()->supportsFinal(); }
|
|
|
|
bool supportsIndexForIn() const override { return getTargetTable()->supportsIndexForIn(); }
|
2019-02-27 18:26:24 +00:00
|
|
|
bool mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, const Context & query_context) const override
|
|
|
|
{
|
|
|
|
return getTargetTable()->mayBenefitFromIndexForIn(left_in_operand, query_context);
|
|
|
|
}
|
2014-10-07 23:08:56 +00:00
|
|
|
|
2019-02-27 18:26:24 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2019-08-27 20:43:08 +00:00
|
|
|
void drop(TableStructureWriteLockHolder &) override;
|
2018-03-20 13:42:44 +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
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
bool optimize(const ASTPtr & query, const ASTPtr & partition, bool final, bool deduplicate, const Context & context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2020-01-29 17:44:16 +00:00
|
|
|
void alter(const AlterCommands & params, const Context & context, TableStructureWriteLockHolder & table_lock_holder) override;
|
|
|
|
|
|
|
|
void checkAlterIsPossible(const AlterCommands & commands, const Settings & settings) override;
|
|
|
|
|
2018-11-26 14:43:40 +00:00
|
|
|
void alterPartition(const ASTPtr & query, const PartitionCommands & commands, const Context & context) override;
|
2018-11-13 13:48:53 +00:00
|
|
|
|
2018-08-20 16:28:30 +00:00
|
|
|
void mutate(const MutationCommands & commands, const Context & context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2019-08-27 20:43:08 +00:00
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override;
|
2019-05-07 06:54:55 +00:00
|
|
|
|
2017-12-16 01:41:06 +00:00
|
|
|
void shutdown() override;
|
2018-08-01 17:41:18 +00:00
|
|
|
|
2018-08-03 09:39:01 +00:00
|
|
|
void checkTableCanBeDropped() const override;
|
|
|
|
void checkPartitionCanBeDropped(const ASTPtr & partition) override;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum getQueryProcessingStage(const Context & context) const override;
|
|
|
|
|
2018-10-17 14:08:52 +00:00
|
|
|
StoragePtr getTargetTable() const;
|
|
|
|
StoragePtr tryGetTargetTable() const;
|
|
|
|
|
2019-04-08 05:13:16 +00:00
|
|
|
ActionLock getActionLock(StorageActionBlockType type) override;
|
|
|
|
|
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;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2019-04-04 13:13:59 +00:00
|
|
|
Strings getDataPaths() const override;
|
2018-02-21 19:26:59 +00:00
|
|
|
|
2013-11-08 17:43:03 +00:00
|
|
|
private:
|
2019-12-30 18:20:43 +00:00
|
|
|
/// Can be empty if SELECT query doesn't contain table
|
|
|
|
StorageID select_table_id = StorageID::createEmpty();
|
|
|
|
/// Will be initialized in constructor
|
|
|
|
StorageID target_table_id = StorageID::createEmpty();
|
|
|
|
|
2020-01-29 17:44:16 +00:00
|
|
|
ASTPtr select;
|
2017-07-25 21:07:05 +00:00
|
|
|
ASTPtr inner_query;
|
2020-01-29 17:44:16 +00:00
|
|
|
|
2017-10-26 15:39:56 +00:00
|
|
|
Context & global_context;
|
2017-10-21 20:08:49 +00:00
|
|
|
bool has_inner_table = false;
|
2017-07-25 21:07:05 +00:00
|
|
|
|
2018-03-20 13:42:44 +00:00
|
|
|
void checkStatementCanBeForwarded() const;
|
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageMaterializedView(
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
2017-10-26 15:39:56 +00:00
|
|
|
Context & local_context,
|
2017-09-17 18:49:43 +00:00
|
|
|
const ASTCreateQuery & query,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2017-04-01 07:20:54 +00:00
|
|
|
bool attach_);
|
2013-11-08 17:43:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|