From d0f3da77e6c59a1f8597c829185acaf70506fb3e Mon Sep 17 00:00:00 2001 From: ivanmorozov333 Date: Wed, 30 Oct 2024 20:15:47 +0300 Subject: [PATCH 1/2] precalculate storage ids for index info --- .../tx/columnshard/engines/scheme/index_info.cpp | 10 ++++++++++ ydb/core/tx/columnshard/engines/scheme/index_info.h | 12 +++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ydb/core/tx/columnshard/engines/scheme/index_info.cpp b/ydb/core/tx/columnshard/engines/scheme/index_info.cpp index 3c687bfa4c1b..ef267d8fb86e 100644 --- a/ydb/core/tx/columnshard/engines/scheme/index_info.cpp +++ b/ydb/core/tx/columnshard/engines/scheme/index_info.cpp @@ -282,6 +282,7 @@ bool TIndexInfo::DeserializeFromProto(const NKikimrSchemeOp::TColumnTableSchema& } Version = schema.GetVersion(); + Precalculate(); Validate(); return true; } @@ -550,10 +551,19 @@ TIndexInfo::TIndexInfo(const TIndexInfo& original, const TSchemaDiffView& diff, if (diff.GetCompressionOptions()) { DeserializeDefaultCompressionFromProto(*diff.GetCompressionOptions()); } + Precalculate(); Validate(); } +void TIndexInfo::Precalculate() { + UsedStorageIds = std::make_shared>(); + for (auto&& i : ColumnFeatures) { + UsedStorageIds->emplace(i->GetOperator()->GetStorageId()); + } +} + void TIndexInfo::Validate() const { + AFL_VERIFY(!!UsedStorageIds); AFL_VERIFY(ColumnFeatures.size() == SchemaColumnIdsWithSpecials.size()); AFL_VERIFY(ColumnFeatures.size() == (ui32)SchemaWithSpecials->num_fields()); AFL_VERIFY(ColumnFeatures.size() == (ui32)Schema->num_fields() + IIndexInfo::SpecialColumnsCount); diff --git a/ydb/core/tx/columnshard/engines/scheme/index_info.h b/ydb/core/tx/columnshard/engines/scheme/index_info.h index fcea496b720f..ed1a0f489cf4 100644 --- a/ydb/core/tx/columnshard/engines/scheme/index_info.h +++ b/ydb/core/tx/columnshard/engines/scheme/index_info.h @@ -98,6 +98,7 @@ struct TIndexInfo: public IIndexInfo { std::vector> ColumnFeatures; THashMap Indexes; + std::shared_ptr> UsedStorageIds; bool SchemeNeedActualization = false; std::shared_ptr CompactionPlannerConstructor; @@ -149,6 +150,7 @@ struct TIndexInfo: public IIndexInfo { const std::shared_ptr& cache) const; void Validate() const; + void Precalculate(); bool DeserializeFromProto(const NKikimrSchemeOp::TColumnTableSchema& schema, const std::shared_ptr& operators, const std::shared_ptr& cache); @@ -227,16 +229,12 @@ struct TIndexInfo: public IIndexInfo { return SchemeNeedActualization; } - std::set GetUsedStorageIds(const TString& portionTierName) const { - std::set result; + const std::set& GetUsedStorageIds(const TString& portionTierName) const { if (portionTierName && portionTierName != IStoragesManager::DefaultStorageId) { - result.emplace(portionTierName); + return { portionTierName }; } else { - for (auto&& i : ColumnFeatures) { - result.emplace(i->GetOperator()->GetStorageId()); - } + return *UsedStorageIds; } - return result; } const THashMap& GetIndexes() const { From c27620d42073bc7ae23b7422aeab43dd57f80c7d Mon Sep 17 00:00:00 2001 From: ivanmorozov333 Date: Wed, 30 Oct 2024 20:32:41 +0300 Subject: [PATCH 2/2] fix build --- ydb/core/tx/columnshard/engines/scheme/index_info.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ydb/core/tx/columnshard/engines/scheme/index_info.h b/ydb/core/tx/columnshard/engines/scheme/index_info.h index ed1a0f489cf4..b9004b743b5a 100644 --- a/ydb/core/tx/columnshard/engines/scheme/index_info.h +++ b/ydb/core/tx/columnshard/engines/scheme/index_info.h @@ -229,7 +229,7 @@ struct TIndexInfo: public IIndexInfo { return SchemeNeedActualization; } - const std::set& GetUsedStorageIds(const TString& portionTierName) const { + std::set GetUsedStorageIds(const TString& portionTierName) const { if (portionTierName && portionTierName != IStoragesManager::DefaultStorageId) { return { portionTierName }; } else {