From b0a73589b0f50a468b99e21744a72a0dd5325d83 Mon Sep 17 00:00:00 2001 From: alesapin Date: Thu, 23 Apr 2020 18:07:19 +0300 Subject: [PATCH 1/2] Remove virtual columns as separate field from IStorage --- src/Storages/IStorage.cpp | 11 ++++------- src/Storages/IStorage.h | 2 -- src/Storages/MergeTree/StorageFromMergeTreeDataPart.h | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Storages/IStorage.cpp b/src/Storages/IStorage.cpp index 91065fbf893..02925ab1818 100644 --- a/src/Storages/IStorage.cpp +++ b/src/Storages/IStorage.cpp @@ -31,7 +31,7 @@ namespace ErrorCodes extern const int DEADLOCK_AVOIDED; } -IStorage::IStorage(StorageID storage_id_, ColumnsDescription virtuals_) : storage_id(std::move(storage_id_)), virtuals(std::move(virtuals_)) +IStorage::IStorage(StorageID storage_id_, ColumnsDescription virtuals_) : storage_id(std::move(storage_id_)), columns(std::move(virtuals_)) { } @@ -40,11 +40,6 @@ const ColumnsDescription & IStorage::getColumns() const return columns; } -const ColumnsDescription & IStorage::getVirtuals() const -{ - return virtuals; -} - const IndicesDescription & IStorage::getIndices() const { return indices; @@ -296,9 +291,11 @@ void IStorage::setColumns(ColumnsDescription columns_) { if (columns_.getOrdinary().empty()) throw Exception("Empty list of columns passed", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED); + ColumnsDescription old_virtuals(columns.getVirtuals(), true); + columns = std::move(columns_); - for (const auto & column : virtuals) + for (const auto & column : old_virtuals) { if (!columns.has(column.name)) columns.add(column); diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index 5a7f71828ef..2ece1744e65 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -144,7 +144,6 @@ public: public: /// thread-unsafe part. lockStructure must be acquired virtual const ColumnsDescription & getColumns() const; /// returns combined set of columns virtual void setColumns(ColumnsDescription columns_); /// sets only real columns, possibly overwrites virtual ones. - const ColumnsDescription & getVirtuals() const; const IndicesDescription & getIndices() const; const ConstraintsDescription & getConstraints() const; @@ -191,7 +190,6 @@ private: StorageID storage_id; mutable std::mutex id_mutex; ColumnsDescription columns; /// combined real and virtual columns - const ColumnsDescription virtuals = {}; IndicesDescription indices; ConstraintsDescription constraints; diff --git a/src/Storages/MergeTree/StorageFromMergeTreeDataPart.h b/src/Storages/MergeTree/StorageFromMergeTreeDataPart.h index 4d799522920..b8ae3faf9a7 100644 --- a/src/Storages/MergeTree/StorageFromMergeTreeDataPart.h +++ b/src/Storages/MergeTree/StorageFromMergeTreeDataPart.h @@ -58,7 +58,7 @@ public: protected: StorageFromMergeTreeDataPart(const MergeTreeData::DataPartPtr & part_) - : IStorage(getIDFromPart(part_), part_->storage.getVirtuals()) + : IStorage(getIDFromPart(part_), ColumnsDescription(part_->storage.getColumns().getVirtuals(), true)) , part(part_) { setColumns(part_->storage.getColumns()); From 5ae25b68e47ecf817be0e023e9745e45a5e0fadc Mon Sep 17 00:00:00 2001 From: alesapin Date: Thu, 23 Apr 2020 18:18:33 +0300 Subject: [PATCH 2/2] Remove redundant virtual from function --- src/Storages/IStorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index 2ece1744e65..2585a779ce4 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -183,7 +183,7 @@ protected: /// still thread-unsafe part. /// Returns whether the column is virtual - by default all columns are real. /// Initially reserved virtual column name may be shadowed by real column. - virtual bool isVirtualColumn(const String & column_name) const; + bool isVirtualColumn(const String & column_name) const; private: