diff options
author | Maksim Kita <kitaetoya@gmail.com> | 2023-07-07 09:29:51 +0000 |
---|---|---|
committer | maksim-kita <maksim-kita@yandex-team.com> | 2023-07-07 12:29:51 +0300 |
commit | 69398ecae6c664f0d4a9487fe8885afa23637569 (patch) | |
tree | 05cae992f9793449c8bc317680bd179808db6804 | |
parent | 76a8d10767f44c35f29a333cca2573b090a52a7f (diff) | |
download | ydb-69398ecae6c664f0d4a9487fe8885afa23637569.tar.gz |
Datashard part iterator improve performance
Datashard part iterator improve performance
Pull Request resolved: #294
-rw-r--r-- | ydb/core/tablet_flat/flat_part_iter_multi.h | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/ydb/core/tablet_flat/flat_part_iter_multi.h b/ydb/core/tablet_flat/flat_part_iter_multi.h index ae1e04ca4e5..972b7810095 100644 --- a/ydb/core/tablet_flat/flat_part_iter_multi.h +++ b/ydb/core/tablet_flat/flat_part_iter_multi.h @@ -679,8 +679,6 @@ namespace NTable { , SkipMainVersion(false) , SkipEraseVersion(false) { - Key.reserve(KeyCellDefaults->Size()); - Groups.reserve(Pinout.AltGroups().size()); GroupRemap.resize(Part->Scheme->Groups.size(), Max<ui32>()); @@ -690,6 +688,14 @@ namespace NTable { Groups.emplace_back(Part->GetGroupIndex(groupId), groupId); GroupRemap[group] = idx; } + + size_t KeyCellDefaultsSize = KeyCellDefaults->Size(); + Key.resize(KeyCellDefaultsSize); + + size_t infoSize = Part->Scheme->Groups[0].ColsKeyData.size(); + for (size_t pos = infoSize; pos < KeyCellDefaultsSize; ++pos) { + Key[pos] = (*KeyCellDefaults)[pos]; + } } void ClearBounds() noexcept @@ -1133,7 +1139,7 @@ namespace NTable { private: Y_FORCE_INLINE void ClearKey() noexcept { - Key.clear(); + KeyInitialized = false; SkipMainDeltas = 0; SkipMainVersion = false; SkipEraseVersion = false; @@ -1142,17 +1148,16 @@ namespace NTable { Y_FORCE_INLINE void InitKey() const noexcept { Y_VERIFY_DEBUG(Main.IsValid(), "Attempt to get an invalid key"); + if (KeyInitialized) + return; - if (!Key) { - auto& info = Part->Scheme->Groups[0].ColsKeyData; - - for (size_t pos = 0; pos < info.size(); ++pos) { - Key.push_back(Main.GetRecord()->Cell(info[pos])); - } + KeyInitialized = true; - for (size_t pos = info.size(); pos < KeyCellDefaults->Size(); ++pos) { - Key.push_back((*KeyCellDefaults)[pos]); - } + auto it = Key.begin(); + auto* record = Main.GetRecord(); + for (auto & info : Part->Scheme->Groups[0].ColsKeyData) { + *it = record->Cell(info); + ++it; } } @@ -1247,6 +1252,7 @@ namespace NTable { mutable TSmallVec<TPartGroupRowIt> Groups; // Key is lazily initialized so needs to be mutable + mutable bool KeyInitialized = false; mutable TSmallVec<TCell> Key; // History state is used when we need to position into history data |