2013-11-08 17:43:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Parsers/IAST_fwd.h>
|
2020-01-29 17:44:16 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2022-05-03 06:43:28 +00:00
|
|
|
class StorageMaterializedView final : public IStorage, WithMutableContext
|
2016-08-26 21:25:05 +00:00
|
|
|
{
|
2013-11-08 17:43:03 +00:00
|
|
|
public:
|
2022-04-19 20:47:29 +00:00
|
|
|
StorageMaterializedView(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
ContextPtr local_context,
|
|
|
|
const ASTCreateQuery & query,
|
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
bool attach_,
|
|
|
|
const String & comment);
|
|
|
|
|
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-04-10 01:35:37 +00:00
|
|
|
bool hasInnerTable() const { return has_inner_table; }
|
2013-11-08 17:43:03 +00:00
|
|
|
|
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(); }
|
2020-04-04 17:33:51 +00:00
|
|
|
bool supportsParallelInsert() const override { return getTargetTable()->supportsParallelInsert(); }
|
2020-12-22 16:40:53 +00:00
|
|
|
bool supportsSubcolumns() const override { return getTargetTable()->supportsSubcolumns(); }
|
2022-01-31 22:27:55 +00:00
|
|
|
bool supportsTransactions() const override { return getTargetTable()->supportsTransactions(); }
|
2021-04-10 23:33:54 +00:00
|
|
|
bool mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, ContextPtr query_context, const StorageMetadataPtr & /* metadata_snapshot */) const override
|
2019-02-27 18:26:24 +00:00
|
|
|
{
|
2020-06-17 09:38:47 +00:00
|
|
|
auto target_table = getTargetTable();
|
|
|
|
auto metadata_snapshot = target_table->getInMemoryMetadataPtr();
|
|
|
|
return target_table->mayBenefitFromIndexForIn(left_in_operand, query_context, metadata_snapshot);
|
2019-02-27 18:26:24 +00:00
|
|
|
}
|
2014-10-07 23:08:56 +00:00
|
|
|
|
2021-07-23 19:33:59 +00:00
|
|
|
SinkToStoragePtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, ContextPtr context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2020-01-22 11:30:11 +00:00
|
|
|
void drop() override;
|
2022-06-23 07:59:13 +00:00
|
|
|
void dropInnerTableIfAny(bool sync, ContextPtr local_context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void truncate(const ASTPtr &, const StorageMetadataPtr &, ContextPtr, TableExclusiveLockHolder &) override;
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2020-06-17 13:39:26 +00:00
|
|
|
bool optimize(
|
|
|
|
const ASTPtr & query,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
|
|
|
const ASTPtr & partition,
|
|
|
|
bool final,
|
|
|
|
bool deduplicate,
|
2020-12-01 09:10:12 +00:00
|
|
|
const Names & deduplicate_by_columns,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2021-10-25 17:49:49 +00:00
|
|
|
void alter(const AlterCommands & params, ContextPtr context, AlterLockHolder & table_lock_holder) override;
|
2020-01-29 17:44:16 +00:00
|
|
|
|
2021-02-25 10:07:48 +00:00
|
|
|
void checkMutationIsPossible(const MutationCommands & commands, const Settings & settings) const override;
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void checkAlterIsPossible(const AlterCommands & commands, ContextPtr context) const override;
|
2020-01-29 17:44:16 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
Pipe alterPartition(const StorageMetadataPtr & metadata_snapshot, const PartitionCommands & commands, ContextPtr context) override;
|
2018-11-13 13:48:53 +00:00
|
|
|
|
2020-07-14 08:19:39 +00:00
|
|
|
void checkAlterPartitionIsPossible(const PartitionCommands & commands, const StorageMetadataPtr & metadata_snapshot, const Settings & settings) const override;
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void mutate(const MutationCommands & commands, ContextPtr context) override;
|
2018-03-20 13:42:44 +00:00
|
|
|
|
2020-04-07 14:05:51 +00:00
|
|
|
void renameInMemory(const StorageID & new_table_id) override;
|
2019-05-07 06:54:55 +00:00
|
|
|
|
2022-05-16 09:04:37 +00:00
|
|
|
void startup() override;
|
2017-12-16 01:41:06 +00:00
|
|
|
void shutdown() override;
|
2018-08-01 17:41:18 +00:00
|
|
|
|
2021-04-22 13:32:17 +00:00
|
|
|
QueryProcessingStage::Enum
|
2021-07-09 03:15:41 +00:00
|
|
|
getQueryProcessingStage(ContextPtr, QueryProcessingStage::Enum, const StorageSnapshotPtr &, SelectQueryInfo &) const override;
|
2018-04-19 14:47:09 +00:00
|
|
|
|
2018-10-17 14:08:52 +00:00
|
|
|
StoragePtr getTargetTable() const;
|
|
|
|
StoragePtr tryGetTargetTable() const;
|
|
|
|
|
2022-01-10 07:53:41 +00:00
|
|
|
/// Get the virtual column of the target table;
|
|
|
|
NamesAndTypesList getVirtuals() const override;
|
|
|
|
|
2019-04-08 05:13:16 +00:00
|
|
|
ActionLock getActionLock(StorageActionBlockType type) override;
|
|
|
|
|
2020-09-29 16:21:58 +00:00
|
|
|
void read(
|
|
|
|
QueryPlan & query_plan,
|
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2020-11-10 12:02:22 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-09-29 16:21:58 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2019-04-04 13:13:59 +00:00
|
|
|
Strings getDataPaths() const override;
|
2018-02-21 19:26:59 +00:00
|
|
|
|
2022-05-31 09:33:23 +00:00
|
|
|
void backupData(BackupEntriesCollector & backup_entries_collector, const String & data_path_in_backup, const std::optional<ASTs> & partitions) override;
|
|
|
|
void restoreDataFromBackup(RestorerFromBackup & restorer, const String & data_path_in_backup, const std::optional<ASTs> & partitions) override;
|
2022-02-22 17:05:52 +00:00
|
|
|
|
2022-05-02 22:01:11 +00:00
|
|
|
std::optional<UInt64> totalRows(const Settings & settings) const override;
|
|
|
|
std::optional<UInt64> totalBytes(const Settings & settings) const override;
|
|
|
|
|
2013-11-08 17:43:03 +00:00
|
|
|
private:
|
2019-12-30 18:20:43 +00:00
|
|
|
/// Will be initialized in constructor
|
|
|
|
StorageID target_table_id = StorageID::createEmpty();
|
|
|
|
|
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;
|
2013-11-08 17:43:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|