From 12fea33798df7df3c761a1cbdb3f1ac96801ecb8 Mon Sep 17 00:00:00 2001 From: kungasc Date: Mon, 19 Feb 2024 15:23:38 +0300 Subject: [PATCH 1/7] GetPageChannel without page id --- ydb/core/tablet_flat/flat_part_store.h | 3 +-- ydb/core/tablet_flat/flat_stat_part.h | 2 +- ydb/core/tablet_flat/flat_table_part.h | 2 +- ydb/core/tablet_flat/test/libs/table/test_part.h | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ydb/core/tablet_flat/flat_part_store.h b/ydb/core/tablet_flat/flat_part_store.h index 86593682bf15..fdb30e2fe7d3 100644 --- a/ydb/core/tablet_flat/flat_part_store.h +++ b/ydb/core/tablet_flat/flat_part_store.h @@ -85,9 +85,8 @@ class TPartStore : public TPart, public IBundle { return EPage(PageCollections[groupId.Index]->PageCollection->Page(id).Type); } - ui8 GetPageChannel(NPage::TPageId id, NPage::TGroupId groupId) const override + ui8 GetPageChannel(NPage::TGroupId groupId) const override { - Y_UNUSED(id); Y_ABORT_UNLESS(groupId.Index < PageCollections.size()); return PageCollections[groupId.Index]->Id.Channel(); } diff --git a/ydb/core/tablet_flat/flat_stat_part.h b/ydb/core/tablet_flat/flat_stat_part.h index 976da4bff56e..60bc1d7f7bdd 100644 --- a/ydb/core/tablet_flat/flat_stat_part.h +++ b/ydb/core/tablet_flat/flat_stat_part.h @@ -177,7 +177,7 @@ class TStatsScreenedPartIterator { void AddPageSize(TPartDataSize& stats, TPageId pageId, TGroupId groupId) const { // TODO: move to IStatsPartGroupIterator ui64 size = Part->GetPageSize(pageId, groupId); - ui8 channel = Part->GetPageChannel(pageId, groupId); + ui8 channel = Part->GetPageChannel(groupId); stats.Add(size, channel); } diff --git a/ydb/core/tablet_flat/flat_table_part.h b/ydb/core/tablet_flat/flat_table_part.h index 6471aaa69944..15b8dce0b573 100644 --- a/ydb/core/tablet_flat/flat_table_part.h +++ b/ydb/core/tablet_flat/flat_table_part.h @@ -129,7 +129,7 @@ namespace NTable { virtual ui64 BackingSize() const = 0; virtual ui64 GetPageSize(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0; virtual NPage::EPage GetPageType(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0; - virtual ui8 GetPageChannel(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0; + virtual ui8 GetPageChannel(NPage::TGroupId groupId = { }) const = 0; virtual ui8 GetPageChannel(ELargeObj lob, ui64 ref) const = 0; protected: diff --git a/ydb/core/tablet_flat/test/libs/table/test_part.h b/ydb/core/tablet_flat/test/libs/table/test_part.h index 3a133b1af845..ac52104481c9 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_part.h +++ b/ydb/core/tablet_flat/test/libs/table/test_part.h @@ -56,9 +56,8 @@ namespace NTest { return Store->GetPageType(groupId.Index, id); } - ui8 GetPageChannel(NPage::TPageId id, NPage::TGroupId groupId) const override + ui8 GetPageChannel(NPage::TGroupId groupId) const override { - Y_UNUSED(id); Y_UNUSED(groupId); return 0; } From a6c3922b6ef013fa024191c36376e495217bab56 Mon Sep 17 00:00:00 2001 From: kungasc Date: Tue, 20 Feb 2024 00:10:43 +0300 Subject: [PATCH 2/7] screen tests --- .../tablet_flat/test/libs/table/test_make.h | 29 +++++++---- .../tablet_flat/test/libs/table/test_part.h | 51 +++++++++++++++++++ .../ut/ut_btree_index_iter_charge.cpp | 19 +------ ydb/core/tablet_flat/ut/ut_stat.cpp | 21 ++++++++ 4 files changed, 94 insertions(+), 26 deletions(-) diff --git a/ydb/core/tablet_flat/test/libs/table/test_make.h b/ydb/core/tablet_flat/test/libs/table/test_make.h index 96b41719a449..95c3006f0cb9 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_make.h +++ b/ydb/core/tablet_flat/test/libs/table/test_make.h @@ -88,7 +88,7 @@ namespace NTest { return cook.Add(Saved.begin(), Saved.end()).Finish(); } - TAutoPtr Mixed(ui32 frozen, ui32 flatten, THash hash, float history = 0) + TAutoPtr Mixed(ui32 frozen, ui32 flatten, THash hash, float addHistory = 0, ui32 addSlices = 1) { TMersenne rnd(0); TDeque> bands; @@ -104,12 +104,12 @@ namespace NTest { if (const auto slots = bands.size()) { for (auto &row: Saved) { auto &band = bands[hash(row) % slots]; - if (history) { + if (addHistory) { for (ui64 txId = 10; txId; txId--) { band->Ver({0, txId}); // FIXME: change row data? band->Add(row); - if (rnd.GenRandReal4() > history) { + if (rnd.GenRandReal4() > addHistory) { // each row will have from 1 to 10 versions break; } @@ -121,6 +121,7 @@ namespace NTest { } TAutoPtr subset = new TSubset(TEpoch::FromIndex(bands.size()), Scheme); + rnd = {0}; for (auto &one: bands) { if (auto *mem = dynamic_cast(one.Get())) { @@ -131,13 +132,23 @@ namespace NTest { subset->Frozen.emplace_back(std::move(table), table->Immediate()); } else if (auto *part_ = dynamic_cast(one.Get())) { auto eggs = part_->Cook.Finish(); - - if (eggs.Parts.size() != 1) { - Y_Fail("Unexpected " << eggs.Parts.size() << " parts"); + auto part = eggs.Lone(); + TVector slices = *part->Slices; + if (addSlices > 1) { + slices.clear(); + auto pages = IndexTools::CountMainPages(*part); + TSet points; + while (points.size() < addSlices * 2) { + points.insert(rnd.GenRand() % pages); + } + for (auto it = points.begin(); it != points.end(); std::advance(it, 2)) { + slices.push_back(IndexTools::MakeSlice(*part, *it, *next(it) + 1)); + } } - - subset->Flatten.push_back( - { eggs.At(0), nullptr, eggs.At(0)->Slices }); + auto slices_ = MakeIntrusive(slices); + TPartView partView(part, slices_->ToScreen(), slices_); + TOverlay{partView.Screen, partView.Slices}.Validate(); + subset->Flatten.push_back(partView); } else { Y_ABORT("Unknown IBand writer type, internal error"); } diff --git a/ydb/core/tablet_flat/test/libs/table/test_part.h b/ydb/core/tablet_flat/test/libs/table/test_part.h index ac52104481c9..d8c85c72265d 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_part.h +++ b/ydb/core/tablet_flat/test/libs/table/test_part.h @@ -177,6 +177,30 @@ namespace NTest { return index.GetLastRecord(); } + inline TRowId GetRowId(const TPart& part, ui32 pageIndex) { + TTestEnv env; + TPartIndexIt index(&part, &env, { }); + + Y_ABORT_UNLESS(index.Seek(0) == EReady::Data); + for (TPageId p = 0; p < pageIndex; p++) { + Y_ABORT_UNLESS(index.Next() == EReady::Data); + } + + return index.GetRowId(); + } + + inline TRowId GetRowId(const TPart& part, ui32 pageIndex) { + TTestEnv env; + TPartIndexIt index(&part, &env, { }); + + Y_ABORT_UNLESS(index.Seek(0) == EReady::Data); + for (TPageId p = 0; p < pageIndex; p++) { + Y_ABORT_UNLESS(index.Next() == EReady::Data); + } + + return index.GetRowId(); + } + inline const TPartIndexIt::TRecord * GetRecord(const TPart& part, ui32 pageIndex) { TTestEnv env; TPartIndexIt index(&part, &env, { }); @@ -202,6 +226,33 @@ namespace NTest { index.Seek(index.GetEndRowId() - 1); return index.GetPageId(); } + + inline TSlice MakeSlice(const TPartStore& part, ui32 pageIndex1Inclusive, ui32 pageIndex2Exclusive) { + auto mainPagesCount = CountMainPages(part); + Y_ABORT_UNLESS(pageIndex1Inclusive < pageIndex2Exclusive); + Y_ABORT_UNLESS(pageIndex2Exclusive <= mainPagesCount); + auto getKey = [&] (const NPage::TIndex::TRecord* record) { + TSmallVec key; + for (const auto& info : part.Scheme->Groups[0].ColsKeyIdx) { + key.push_back(record->Cell(info)); + } + return TSerializedCellVec(key); + }; + TSlice slice; + slice.FirstInclusive = true; + slice.FirstRowId = IndexTools::GetRowId(part, pageIndex1Inclusive); + slice.FirstKey = pageIndex1Inclusive > 0 + ? getKey(IndexTools::GetRecord(part, pageIndex1Inclusive)) + : part.Slices->begin()->FirstKey; + slice.LastInclusive = false; + slice.LastRowId = pageIndex2Exclusive < mainPagesCount + ? IndexTools::GetRowId(part, pageIndex2Exclusive) + : part.Stat.Rows; + slice.LastKey = pageIndex2Exclusive < mainPagesCount + ? getKey(IndexTools::GetRecord(part, pageIndex2Exclusive)) + : part.Slices->rbegin()->LastKey; + return slice; + } } }}} diff --git a/ydb/core/tablet_flat/ut/ut_btree_index_iter_charge.cpp b/ydb/core/tablet_flat/ut/ut_btree_index_iter_charge.cpp index 53fefde50635..0bb9fc818293 100644 --- a/ydb/core/tablet_flat/ut/ut_btree_index_iter_charge.cpp +++ b/ydb/core/tablet_flat/ut/ut_btree_index_iter_charge.cpp @@ -158,23 +158,8 @@ namespace { if (params.Slices) { TSlices slices; auto partSlices = (TSlices*)part.Slices.Get(); - - auto getKey = [&] (const NPage::TIndex::TRecord* record) { - TSmallVec key; - for (const auto& info : part.Scheme->Groups[0].ColsKeyIdx) { - key.push_back(record->Cell(info)); - } - return TSerializedCellVec(key); - }; - auto add = [&](ui32 pageIndex1 /*inclusive*/, ui32 pageIndex2 /*exclusive*/) { - TSlice slice; - slice.FirstInclusive = true; - slice.FirstRowId = pageIndex1 * 2; - slice.FirstKey = pageIndex1 > 0 ? getKey(IndexTools::GetRecord(part, pageIndex1)) : partSlices->begin()->FirstKey; - slice.LastInclusive = false; - slice.LastRowId = pageIndex2 * 2; - slice.LastKey = pageIndex2 < 20 ? getKey(IndexTools::GetRecord(part, pageIndex2)) : partSlices->begin()->LastKey; - slices.push_back(slice); + auto add = [&](ui32 pageIndex1Inclusive, ui32 pageIndex2Exclusive) { + slices.push_back(IndexTools::MakeSlice(part, pageIndex1Inclusive, pageIndex2Exclusive)); }; add(0, 2); add(3, 4); diff --git a/ydb/core/tablet_flat/ut/ut_stat.cpp b/ydb/core/tablet_flat/ut/ut_stat.cpp index 56f0f6428ee8..734fd9b81891 100644 --- a/ydb/core/tablet_flat/ut/ut_stat.cpp +++ b/ydb/core/tablet_flat/ut/ut_stat.cpp @@ -98,18 +98,39 @@ Y_UNIT_TEST_SUITE(BuildStats) { Check(*subset, 24000, 2106439, 25272); } + Y_UNIT_TEST(Single_Slices) + { + auto subset = TMake(Mass0, PageConf(Mass0.Model->Scheme->Families.size(), false)).Mixed(0, 1, TMixerOne{ }, 0, 13); + subset->Flatten.begin()->Slices->Describe(Cerr); Cerr << Endl; + Check(*subset, 12816, 1121048, 25272); + } + Y_UNIT_TEST(Single_Groups) { auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), false)).Mixed(0, 1, TMixerOne{ }); Check(*subset, 24000, 2460139, 13170); } + Y_UNIT_TEST(Single_Groups_Slices) + { + auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), false)).Mixed(0, 1, TMixerOne{ }, 0, 13); + subset->Flatten.begin()->Slices->Describe(Cerr); Cerr << Endl; + Check(*subset, 10440, 1060798, 13170); + } + Y_UNIT_TEST(Single_Groups_History) { auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), false)).Mixed(0, 1, TMixerOne{ }, 0.3); Check(*subset, 24000, 4054050, 18810); } + Y_UNIT_TEST(Single_Groups_History_Slices) + { + auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), false)).Mixed(0, 1, TMixerOne{ }, 0.3, 13); + subset->Flatten.begin()->Slices->Describe(Cerr); Cerr << Endl; + Check(*subset, 13570, 2277890, 18810); + } + Y_UNIT_TEST(Mixed) { auto subset = TMake(Mass0, PageConf(Mass0.Model->Scheme->Families.size(), false)).Mixed(0, 4, TMixerRnd(4)); From bedcd97f0a693925fa581972c5f3a29f7c34d0da Mon Sep 17 00:00:00 2001 From: kungasc Date: Tue, 20 Feb 2024 13:52:31 +0300 Subject: [PATCH 3/7] code movements --- ydb/core/tablet_flat/flat_stat_part.h | 24 ++-------- .../flat_stat_part_group_iter_iface.h | 44 +++++++++++++------ ydb/core/tablet_flat/flat_stat_table.cpp | 2 +- ydb/core/tablet_flat/flat_stat_table.h | 6 +-- ydb/core/tablet_flat/flat_table_part_ut.cpp | 6 +-- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/ydb/core/tablet_flat/flat_stat_part.h b/ydb/core/tablet_flat/flat_stat_part.h index 60bc1d7f7bdd..e730dde2910f 100644 --- a/ydb/core/tablet_flat/flat_stat_part.h +++ b/ydb/core/tablet_flat/flat_stat_part.h @@ -11,24 +11,6 @@ namespace NKikimr { namespace NTable { -struct TPartDataSize { - ui64 Size = 0; - TVector ByChannel = { }; - - void Add(ui64 size, ui8 channel) { - Size += size; - if (!(channel < ByChannel.size())) { - ByChannel.resize(channel + 1); - } - ByChannel[channel] += size; - } -}; - -struct TPartDataStats { - ui64 RowCount = 0; - TPartDataSize DataSize = { }; -}; - // Iterates over part index and calculates total row count and data size // This iterator skips pages that are screened. Currently the logic is simple: // if page start key is screened then we assume that the whole previous page is screened @@ -82,7 +64,7 @@ class TStatsScreenedPartIterator { return Groups[0]->IsValid(); } - EReady Next(TPartDataStats& stats) { + EReady Next(TDataStats& stats) { Y_ABORT_UNLESS(IsValid()); auto curPageId = Groups[0]->GetPageId(); @@ -174,7 +156,7 @@ class TStatsScreenedPartIterator { return LastRowId; } - void AddPageSize(TPartDataSize& stats, TPageId pageId, TGroupId groupId) const { + void AddPageSize(TChanneledDataSize& stats, TPageId pageId, TGroupId groupId) const { // TODO: move to IStatsPartGroupIterator ui64 size = Part->GetPageSize(pageId, groupId); ui8 channel = Part->GetPageChannel(groupId); @@ -229,7 +211,7 @@ class TStatsScreenedPartIterator { return rowCount; } - void AddBlobsSize(TPartDataSize& stats, const TFrames* frames, ELargeObj lob, ui32 &prevPage) noexcept { + void AddBlobsSize(TChanneledDataSize& stats, const TFrames* frames, ELargeObj lob, ui32 &prevPage) noexcept { const auto row = GetLastRowId(); const auto end = GetCurrentRowId(); diff --git a/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h b/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h index 11aa36eaa675..42907ac40248 100644 --- a/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h +++ b/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h @@ -4,23 +4,41 @@ #include "ydb/core/scheme/scheme_tablecell.h" namespace NKikimr::NTable { - - struct IStatsPartGroupIterator { - virtual EReady Start() = 0; - virtual EReady Next() = 0; - virtual bool IsValid() const = 0; +struct TChanneledDataSize { + ui64 Size = 0; + TVector ByChannel = { }; + + void Add(ui64 size, ui8 channel) { + Size += size; + if (!(channel < ByChannel.size())) { + ByChannel.resize(channel + 1); + } + ByChannel[channel] += size; + } +}; + +struct TDataStats { + ui64 RowCount = 0; + TChanneledDataSize DataSize = { }; +}; + +struct IStatsPartGroupIterator { + virtual EReady Start() = 0; + virtual EReady Next() = 0; + + virtual bool IsValid() const = 0; - virtual TRowId GetEndRowId() const = 0; - virtual TPageId GetPageId() const = 0; - virtual TRowId GetRowId() const = 0; + virtual TRowId GetEndRowId() const = 0; + virtual TPageId GetPageId() const = 0; + virtual TRowId GetRowId() const = 0; - virtual TPos GetKeyCellsCount() const = 0; - virtual TCell GetKeyCell(TPos index) const = 0; + virtual TPos GetKeyCellsCount() const = 0; + virtual TCell GetKeyCell(TPos index) const = 0; - virtual ~IStatsPartGroupIterator() = default; - }; + virtual ~IStatsPartGroupIterator() = default; +}; - THolder CreateStatsPartGroupIterator(const TPart* part, IPages* env, NPage::TGroupId groupId); +THolder CreateStatsPartGroupIterator(const TPart* part, IPages* env, NPage::TGroupId groupId); } diff --git a/ydb/core/tablet_flat/flat_stat_table.cpp b/ydb/core/tablet_flat/flat_stat_table.cpp index da75a4c85c53..ea6dfdbe4632 100644 --- a/ydb/core/tablet_flat/flat_stat_table.cpp +++ b/ydb/core/tablet_flat/flat_stat_table.cpp @@ -9,7 +9,7 @@ namespace NTable { bool BuildStats(const TSubset& subset, TStats& stats, ui64 rowCountResolution, ui64 dataSizeResolution, IPages* env) { stats.Clear(); - TPartDataStats iteratorStats = { }; + TDataStats iteratorStats = { }; TStatsIterator statsIterator(subset.Scheme->Keys); // Make index iterators for all parts diff --git a/ydb/core/tablet_flat/flat_stat_table.h b/ydb/core/tablet_flat/flat_stat_table.h index e89c7455ea74..1da741364baa 100644 --- a/ydb/core/tablet_flat/flat_stat_table.h +++ b/ydb/core/tablet_flat/flat_stat_table.h @@ -26,7 +26,7 @@ class TStatsIterator { Heap.push(iteratorPtr); } - EReady Next(TPartDataStats& stats) { + EReady Next(TDataStats& stats) { ui64 lastRowCount = stats.RowCount; ui64 lastDataSize = stats.DataSize.Size; @@ -100,8 +100,8 @@ using THistogram = TVector; struct TStats { ui64 RowCount = 0; - TPartDataSize DataSize = { }; - TPartDataSize IndexSize = { }; + TChanneledDataSize DataSize = { }; + TChanneledDataSize IndexSize = { }; THistogram RowCountHistogram; THistogram DataSizeHistogram; diff --git a/ydb/core/tablet_flat/flat_table_part_ut.cpp b/ydb/core/tablet_flat/flat_table_part_ut.cpp index a03470d712f5..34f8a400aa36 100644 --- a/ydb/core/tablet_flat/flat_table_part_ut.cpp +++ b/ydb/core/tablet_flat/flat_table_part_ut.cpp @@ -75,7 +75,7 @@ Y_UNIT_TEST_SUITE(TLegacy) { TIntrusiveConstPtr scheme, std::vector& sizes) { - TPartDataStats stats = { }; + TDataStats stats = { }; TTestEnv env; // TScreenedPartIndexIterator without screen previously was TPartIndexIterator TStatsScreenedPartIterator idxIter(TPartView{part, nullptr, nullptr}, &env, scheme->Keys, nullptr, nullptr); @@ -145,7 +145,7 @@ Y_UNIT_TEST_SUITE(TLegacy) { auto fnIterate = [&dbgOut, &typeRegistry] (TIntrusiveConstPtr part, TIntrusiveConstPtr screen, TIntrusiveConstPtr scheme, TIntrusiveConstPtr frames) -> std::pair { - TPartDataStats stats = { }; + TDataStats stats = { }; TTestEnv env; TStatsScreenedPartIterator idxIter(TPartView{part, screen, nullptr}, &env, scheme->Keys, std::move(frames), nullptr); @@ -304,7 +304,7 @@ Y_UNIT_TEST_SUITE(TLegacy) { TScreen::THole(4200, 100000) }); - TPartDataStats stats = { }; + TDataStats stats = { }; TTestEnv env; TStatsIterator stIter(lay2.RowScheme()->Keys); { From e26247cd323b75354b60f563fba8d0e5f0a99040 Mon Sep 17 00:00:00 2001 From: kungasc Date: Tue, 20 Feb 2024 19:56:48 +0300 Subject: [PATCH 4/7] + AddLastDeltaDataSize --- ydb/core/tablet_flat/flat_part_index_iter.h | 9 ++++++ ydb/core/tablet_flat/flat_part_store.h | 2 +- ydb/core/tablet_flat/flat_stat_part.h | 32 ++++++++----------- .../flat_stat_part_group_btree_index.h | 25 +++++++++++++-- .../flat_stat_part_group_iter_iface.h | 1 + ydb/core/tablet_flat/flat_table_part.h | 2 +- .../tablet_flat/test/libs/table/test_part.h | 2 +- ydb/core/tablet_flat/ut/ut_stat.cpp | 21 ++++++++++++ 8 files changed, 70 insertions(+), 24 deletions(-) diff --git a/ydb/core/tablet_flat/flat_part_index_iter.h b/ydb/core/tablet_flat/flat_part_index_iter.h index 475c37cf5f9f..e2d43a5419e2 100644 --- a/ydb/core/tablet_flat/flat_part_index_iter.h +++ b/ydb/core/tablet_flat/flat_part_index_iter.h @@ -97,6 +97,15 @@ class TPartIndexIt : public IIndexIter, public IStatsPartGroupIterator { return bool(Iter); } + void AddLastDeltaDataSize(TChanneledDataSize& dataSize) override { + Y_DEBUG_ABORT_UNLESS(Index); + Y_DEBUG_ABORT_UNLESS(Iter.Off()); + TPageId pageId = (Iter - 1)->GetPageId(); + ui64 delta = Part->GetPageSize(pageId, GroupId); + ui8 channel = Part->GetGroupChannel(GroupId); + dataSize.Add(delta, channel); + } + // for precharge and TForward only TIndex* TryLoadRaw() { return TryGetIndex(); diff --git a/ydb/core/tablet_flat/flat_part_store.h b/ydb/core/tablet_flat/flat_part_store.h index fdb30e2fe7d3..707eea02d2d5 100644 --- a/ydb/core/tablet_flat/flat_part_store.h +++ b/ydb/core/tablet_flat/flat_part_store.h @@ -85,7 +85,7 @@ class TPartStore : public TPart, public IBundle { return EPage(PageCollections[groupId.Index]->PageCollection->Page(id).Type); } - ui8 GetPageChannel(NPage::TGroupId groupId) const override + ui8 GetGroupChannel(NPage::TGroupId groupId) const override { Y_ABORT_UNLESS(groupId.Index < PageCollections.size()); return PageCollections[groupId.Index]->Id.Channel(); diff --git a/ydb/core/tablet_flat/flat_stat_part.h b/ydb/core/tablet_flat/flat_stat_part.h index e730dde2910f..72c6b183d6d0 100644 --- a/ydb/core/tablet_flat/flat_stat_part.h +++ b/ydb/core/tablet_flat/flat_stat_part.h @@ -67,30 +67,31 @@ class TStatsScreenedPartIterator { EReady Next(TDataStats& stats) { Y_ABORT_UNLESS(IsValid()); - auto curPageId = Groups[0]->GetPageId(); LastRowId = Groups[0]->GetRowId(); auto ready = Groups[0]->Next(); if (ready == EReady::Page) { + Y_DEBUG_ABORT_UNLESS(false, "Shouldn't really happen"); return ready; } ui64 rowCount = CountUnscreenedRows(GetLastRowId(), GetCurrentRowId()); stats.RowCount += rowCount; if (rowCount) { - AddPageSize(stats.DataSize, curPageId, TGroupId(0)); + Groups[0]->AddLastDeltaDataSize(stats.DataSize); } TRowId nextRowId = ready == EReady::Data ? Groups[0]->GetRowId() : Max(); for (auto groupIndex : xrange(1, Groups.size())) { while (Groups[groupIndex]->IsValid() && Groups[groupIndex]->GetRowId() < nextRowId) { // eagerly include all data up to the next row id - if (rowCount) { - AddPageSize(stats.DataSize, Groups[groupIndex]->GetPageId(), TGroupId(groupIndex)); - } if (Groups[groupIndex]->Next() == EReady::Page) { + Y_DEBUG_ABORT_UNLESS(false, "Shouldn't really happen"); ready = EReady::Page; break; } + if (rowCount) { + Groups[groupIndex]->AddLastDeltaDataSize(stats.DataSize); + } } } @@ -98,25 +99,27 @@ class TStatsScreenedPartIterator { Y_DEBUG_ABORT_UNLESS(Part->Scheme->HistoryGroup.ColsKeyIdx.size() == 3); while (HistoricGroups[0]->IsValid() && (!HistoricGroups[0]->GetKeyCellsCount() || HistoricGroups[0]->GetKeyCell(0).AsValue() < nextRowId)) { // eagerly include all history up to the next row id - if (rowCount) { - AddPageSize(stats.DataSize, HistoricGroups[0]->GetPageId(), TGroupId(0, true)); - } if (HistoricGroups[0]->Next() == EReady::Page) { + Y_DEBUG_ABORT_UNLESS(false, "Shouldn't really happen"); ready = EReady::Page; break; } + if (rowCount) { + HistoricGroups[0]->AddLastDeltaDataSize(stats.DataSize); + } } TRowId nextHistoryRowId = HistoricGroups[0]->IsValid() ? HistoricGroups[0]->GetRowId() : Max(); for (auto groupIndex : xrange(1, Groups.size())) { while (HistoricGroups[groupIndex]->IsValid() && HistoricGroups[groupIndex]->GetRowId() < nextHistoryRowId) { // eagerly include all data up to the next row id - if (rowCount) { - AddPageSize(stats.DataSize, HistoricGroups[groupIndex]->GetPageId(), TGroupId(groupIndex, true)); - } if (HistoricGroups[groupIndex]->Next() == EReady::Page) { + Y_DEBUG_ABORT_UNLESS(false, "Shouldn't really happen"); ready = EReady::Page; break; } + if (rowCount) { + HistoricGroups[groupIndex]->AddLastDeltaDataSize(stats.DataSize); + } } } } @@ -156,13 +159,6 @@ class TStatsScreenedPartIterator { return LastRowId; } - void AddPageSize(TChanneledDataSize& stats, TPageId pageId, TGroupId groupId) const { - // TODO: move to IStatsPartGroupIterator - ui64 size = Part->GetPageSize(pageId, groupId); - ui8 channel = Part->GetPageChannel(groupId); - stats.Add(size, channel); - } - void FillKey() { CurrentKey.clear(); diff --git a/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h b/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h index 18e39f69d652..1958c452b558 100644 --- a/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h +++ b/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h @@ -25,13 +25,15 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { TCellsIterable EndKey; std::optional Node; std::optional Pos; + ui64 DataSize; - TNodeState(TPageId pageId, TRowId beginRowId, TRowId endRowId, TCellsIterable beginKey, TCellsIterable endKey) + TNodeState(TPageId pageId, TRowId beginRowId, TRowId endRowId, TCellsIterable beginKey, TCellsIterable endKey, ui64 dataSize) : PageId(pageId) , BeginRowId(beginRowId) , EndRowId(endRowId) , BeginKey(beginKey) , EndKey(endKey) + , DataSize(dataSize) { } @@ -72,9 +74,12 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { , GroupInfo(part->Scheme->GetLayout(groupId)) , Meta(groupId.IsHistoric() ? part->IndexPages.BTreeHistoric[groupId.Index] : part->IndexPages.BTreeGroups[groupId.Index]) , State(Reserve(Meta.LevelCount + 1)) + , GroupChannel(Part->GetGroupChannel(GroupId)) + , PrevDataSize(0) + , PrevPrevDataSize(0) { const static TCellsIterable EmptyKey(static_cast(nullptr), TColumns()); - State.emplace_back(Meta.PageId, 0, GetEndRowId(), EmptyKey, EmptyKey); + State.emplace_back(Meta.PageId, 0, GetEndRowId(), EmptyKey, EmptyKey, Meta.DataSize); } EReady Start() override { @@ -84,6 +89,9 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { EReady Next() override { Y_ABORT_UNLESS(!IsExhausted()); + PrevPrevDataSize = PrevDataSize; + PrevDataSize = State.back().DataSize; + if (Meta.LevelCount == 0) { return Exhaust(); } @@ -112,6 +120,13 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { return EReady::Data; } + void AddLastDeltaDataSize(TChanneledDataSize& dataSize) override { + Y_ABORT_UNLESS(IsExhausted() || IsLeaf()); + Y_DEBUG_ABORT_UNLESS(PrevDataSize >= PrevPrevDataSize); + ui64 delta = PrevDataSize - PrevPrevDataSize; + dataSize.Add(delta, GroupChannel); + } + public: bool IsValid() const override { Y_DEBUG_ABORT_UNLESS(IsLeaf() || IsExhausted()); @@ -208,7 +223,9 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { TCellsIterable beginKey = pos ? current.Node->GetKeyCellsIterable(pos - 1, GroupInfo.ColsKeyIdx) : current.BeginKey; TCellsIterable endKey = pos < current.Node->GetKeysCount() ? current.Node->GetKeyCellsIterable(pos, GroupInfo.ColsKeyIdx) : current.EndKey; - State.emplace_back(child.PageId, beginRowId, endRowId, beginKey, endKey); + ui64 dataSize = child.DataSize; + + State.emplace_back(child.PageId, beginRowId, endRowId, beginKey, endKey, dataSize); } bool TryLoad(TNodeState& state) { @@ -231,6 +248,8 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { const TPartScheme::TGroupInfo& GroupInfo; const TBtreeIndexMeta Meta; TVector State; + ui8 GroupChannel; + ui64 PrevDataSize, PrevPrevDataSize; }; } diff --git a/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h b/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h index 42907ac40248..c9ce3e943847 100644 --- a/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h +++ b/ydb/core/tablet_flat/flat_stat_part_group_iter_iface.h @@ -26,6 +26,7 @@ struct TDataStats { struct IStatsPartGroupIterator { virtual EReady Start() = 0; virtual EReady Next() = 0; + virtual void AddLastDeltaDataSize(TChanneledDataSize& dataSize) = 0; virtual bool IsValid() const = 0; diff --git a/ydb/core/tablet_flat/flat_table_part.h b/ydb/core/tablet_flat/flat_table_part.h index 15b8dce0b573..6ba390d99af1 100644 --- a/ydb/core/tablet_flat/flat_table_part.h +++ b/ydb/core/tablet_flat/flat_table_part.h @@ -129,7 +129,7 @@ namespace NTable { virtual ui64 BackingSize() const = 0; virtual ui64 GetPageSize(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0; virtual NPage::EPage GetPageType(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0; - virtual ui8 GetPageChannel(NPage::TGroupId groupId = { }) const = 0; + virtual ui8 GetGroupChannel(NPage::TGroupId groupId = { }) const = 0; virtual ui8 GetPageChannel(ELargeObj lob, ui64 ref) const = 0; protected: diff --git a/ydb/core/tablet_flat/test/libs/table/test_part.h b/ydb/core/tablet_flat/test/libs/table/test_part.h index d8c85c72265d..2fd1898704d8 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_part.h +++ b/ydb/core/tablet_flat/test/libs/table/test_part.h @@ -56,7 +56,7 @@ namespace NTest { return Store->GetPageType(groupId.Index, id); } - ui8 GetPageChannel(NPage::TGroupId groupId) const override + ui8 GetGroupChannel(NPage::TGroupId groupId) const override { Y_UNUSED(groupId); return 0; diff --git a/ydb/core/tablet_flat/ut/ut_stat.cpp b/ydb/core/tablet_flat/ut/ut_stat.cpp index 734fd9b81891..91d1cb7452fe 100644 --- a/ydb/core/tablet_flat/ut/ut_stat.cpp +++ b/ydb/core/tablet_flat/ut/ut_stat.cpp @@ -176,18 +176,39 @@ Y_UNIT_TEST_SUITE(BuildStats) { Check(*subset, 24000, 2106439, 41220); } + Y_UNIT_TEST(Single_Slices_BTreeIndex) + { + auto subset = TMake(Mass0, PageConf(Mass0.Model->Scheme->Families.size(), true)).Mixed(0, 1, TMixerOne{ }, 0, 13); + subset->Flatten.begin()->Slices->Describe(Cerr); Cerr << Endl; + Check(*subset, 12816, 1121048, 41220); + } + Y_UNIT_TEST(Single_Groups_BTreeIndex) { auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), true)).Mixed(0, 1, TMixerOne{ }); Check(*subset, 24000, 2460139, 20485); } + Y_UNIT_TEST(Single_Groups_Slices_BTreeIndex) + { + auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), true)).Mixed(0, 1, TMixerOne{ }, 0, 13); + subset->Flatten.begin()->Slices->Describe(Cerr); Cerr << Endl; + Check(*subset, 10440, 1060798, 20485); + } + Y_UNIT_TEST(Single_Groups_History_BTreeIndex) { auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), true)).Mixed(0, 1, TMixerOne{ }, 0.3); Check(*subset, 24000, 4054050, 29710); } + Y_UNIT_TEST(Single_Groups_History_Slices_BTreeIndex) + { + auto subset = TMake(Mass1, PageConf(Mass1.Model->Scheme->Families.size(), true)).Mixed(0, 1, TMixerOne{ }, 0.3, 13); + subset->Flatten.begin()->Slices->Describe(Cerr); Cerr << Endl; + Check(*subset, 13570, 2277890, 29710); + } + Y_UNIT_TEST(Mixed_BTreeIndex) { auto subset = TMake(Mass0, PageConf(Mass0.Model->Scheme->Families.size(), true)).Mixed(0, 4, TMixerRnd(4)); From 5829e39139f63801e3ed5d37861e6c55e7a6528c Mon Sep 17 00:00:00 2001 From: kungasc Date: Wed, 21 Feb 2024 14:43:31 +0300 Subject: [PATCH 5/7] charge index on start --- .../flat_stat_part_group_btree_index.h | 210 +++++------------- ydb/core/tablet_flat/ut/ut_stat.cpp | 3 +- 2 files changed, 56 insertions(+), 157 deletions(-) diff --git a/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h b/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h index 1958c452b558..1a39e8e20404 100644 --- a/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h +++ b/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h @@ -22,48 +22,16 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { TRowId BeginRowId; TRowId EndRowId; TCellsIterable BeginKey; - TCellsIterable EndKey; - std::optional Node; - std::optional Pos; ui64 DataSize; - TNodeState(TPageId pageId, TRowId beginRowId, TRowId endRowId, TCellsIterable beginKey, TCellsIterable endKey, ui64 dataSize) + TNodeState(TPageId pageId, TRowId beginRowId, TRowId endRowId, TCellsIterable beginKey, ui64 dataSize) : PageId(pageId) , BeginRowId(beginRowId) , EndRowId(endRowId) , BeginKey(beginKey) - , EndKey(endKey) , DataSize(dataSize) { } - - bool IsLastPos() const noexcept { - Y_ABORT_UNLESS(Node); - Y_ABORT_UNLESS(Pos); - return *Pos == Node->GetKeysCount(); - } - - bool IsFirstPos() const noexcept { - Y_ABORT_UNLESS(Node); - Y_ABORT_UNLESS(Pos); - return *Pos == 0; - } - }; - - struct TSeekRowId { - TSeekRowId(TRowId rowId) - : RowId(rowId) - {} - - bool BelongsTo(const TNodeState& state) const noexcept { - return TBtreeIndexNode::Has(RowId, state.BeginRowId, state.EndRowId); - } - - TRecIdx Do(const TNodeState& state) const noexcept { - return state.Node->Seek(RowId, state.Pos); - } - - const TRowId RowId; }; public: @@ -73,55 +41,65 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { , GroupId(groupId) , GroupInfo(part->Scheme->GetLayout(groupId)) , Meta(groupId.IsHistoric() ? part->IndexPages.BTreeHistoric[groupId.Index] : part->IndexPages.BTreeGroups[groupId.Index]) - , State(Reserve(Meta.LevelCount + 1)) , GroupChannel(Part->GetGroupChannel(GroupId)) + , NodeIndex(0) , PrevDataSize(0) , PrevPrevDataSize(0) { - const static TCellsIterable EmptyKey(static_cast(nullptr), TColumns()); - State.emplace_back(Meta.PageId, 0, GetEndRowId(), EmptyKey, EmptyKey, Meta.DataSize); } EReady Start() override { - return DoSeek({0}); - } - - EReady Next() override { - Y_ABORT_UNLESS(!IsExhausted()); + const static TCellsIterable EmptyKey(static_cast(nullptr), TColumns()); - PrevPrevDataSize = PrevDataSize; - PrevDataSize = State.back().DataSize; + bool ready = true; + TVector nextNodes; + Nodes.emplace_back(Meta.PageId, 0, GetEndRowId(), EmptyKey, Meta.DataSize); + + for (ui32 height = 0; height < Meta.LevelCount; height++) { + for (auto &nodeState : Nodes) { + auto page = Env->TryGetPage(Part, nodeState.PageId); + if (!page) { + ready = false; + continue; + } + TBtreeIndexNode node(*page); + + for (TRecIdx pos : xrange(0, node.GetChildrenCount())) { + auto& child = node.GetShortChild(pos); + + TRowId beginRowId = pos ? node.GetShortChild(pos - 1).RowCount : nodeState.BeginRowId; + TRowId endRowId = child.RowCount; + TCellsIterable beginKey = pos ? node.GetKeyCellsIterable(pos - 1, GroupInfo.ColsKeyIdx) : nodeState.BeginKey; + ui64 dataSize = child.DataSize; + + nextNodes.emplace_back(child.PageId, beginRowId, endRowId, beginKey, dataSize); + } + } - if (Meta.LevelCount == 0) { - return Exhaust(); + Nodes.swap(nextNodes); + nextNodes.clear(); } - if (IsLeaf()) { - do { - State.pop_back(); - } while (State.size() > 1 && State.back().IsLastPos()); - if (State.back().IsLastPos()) { - return Exhaust(); - } - PushNextState(*State.back().Pos + 1); + if (!ready) { + Nodes.clear(); // some invalid subset + return EReady::Page; } - for (ui32 level : xrange(State.size() - 1, Meta.LevelCount)) { - if (!TryLoad(State[level])) { - // exiting with an intermediate state - Y_DEBUG_ABORT_UNLESS(!IsLeaf() && !IsExhausted()); - return EReady::Page; - } - PushNextState(0); - } + return DataOrGone(); + } + + EReady Next() override { + Y_ABORT_UNLESS(IsValid()); + + PrevPrevDataSize = PrevDataSize; + PrevDataSize = GetCurrentNode().DataSize; - // State.back() points to the target data page - Y_ABORT_UNLESS(IsLeaf()); - return EReady::Data; + NodeIndex++; + + return DataOrGone(); } void AddLastDeltaDataSize(TChanneledDataSize& dataSize) override { - Y_ABORT_UNLESS(IsExhausted() || IsLeaf()); Y_DEBUG_ABORT_UNLESS(PrevDataSize >= PrevPrevDataSize); ui64 delta = PrevDataSize - PrevPrevDataSize; dataSize.Add(delta, GroupChannel); @@ -129,8 +107,7 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { public: bool IsValid() const override { - Y_DEBUG_ABORT_UNLESS(IsLeaf() || IsExhausted()); - return IsLeaf(); + return NodeIndex < Nodes.size(); } TRowId GetEndRowId() const override { @@ -138,107 +115,29 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { } TPageId GetPageId() const override { - Y_ABORT_UNLESS(IsLeaf()); - return State.back().PageId; + return GetCurrentNode().PageId; } TRowId GetRowId() const override { - Y_ABORT_UNLESS(IsLeaf()); - return State.back().BeginRowId; + return GetCurrentNode().BeginRowId; } TPos GetKeyCellsCount() const override { - Y_ABORT_UNLESS(IsLeaf()); - return State.back().BeginKey.Count(); + return GetCurrentNode().BeginKey.Count(); } TCell GetKeyCell(TPos index) const override { - Y_ABORT_UNLESS(IsLeaf()); - return State.back().BeginKey.Iter().At(index); + return GetCurrentNode().BeginKey.Iter().At(index); } private: - template - EReady DoSeek(TSeek seek) { - while (State.size() > 1 && !seek.BelongsTo(State.back())) { - State.pop_back(); - } - - if (IsExhausted()) { - // don't use exhausted state as an initial one - State[0].Pos = { }; - } - - for (ui32 level : xrange(State.size() - 1, Meta.LevelCount)) { - auto &state = State[level]; - Y_DEBUG_ABORT_UNLESS(seek.BelongsTo(state)); - if (!TryLoad(state)) { - // exiting with an intermediate state - Y_DEBUG_ABORT_UNLESS(!IsLeaf() && !IsExhausted()); - return EReady::Page; - } - auto pos = seek.Do(state); - - PushNextState(pos); - } - - // State.back() points to the target data page - Y_ABORT_UNLESS(IsLeaf()); - Y_DEBUG_ABORT_UNLESS(seek.BelongsTo(State.back())); - return EReady::Data; - } - - bool IsRoot() const noexcept { - return State.size() == 1; - } - - bool IsExhausted() const noexcept { - return State[0].Pos == Max(); + EReady DataOrGone() const { + return IsValid() ? EReady::Data : EReady::Gone; } - bool IsLeaf() const noexcept { - // Note: it is possible to have 0 levels in B-Tree - // so we may have exhausted state with leaf (data) node - return State.size() == Meta.LevelCount + 1 && !IsExhausted(); - } - - EReady Exhaust() { - while (State.size() > 1) { - State.pop_back(); - } - State[0].Pos = Max(); - return EReady::Gone; - } - - void PushNextState(TRecIdx pos) { - TNodeState& current = State.back(); - Y_ABORT_UNLESS(pos < current.Node->GetChildrenCount(), "Should point to some child"); - current.Pos.emplace(pos); - - auto& child = current.Node->GetShortChild(pos); - - TRowId beginRowId = pos ? current.Node->GetShortChild(pos - 1).RowCount : current.BeginRowId; - TRowId endRowId = child.RowCount; - - TCellsIterable beginKey = pos ? current.Node->GetKeyCellsIterable(pos - 1, GroupInfo.ColsKeyIdx) : current.BeginKey; - TCellsIterable endKey = pos < current.Node->GetKeysCount() ? current.Node->GetKeyCellsIterable(pos, GroupInfo.ColsKeyIdx) : current.EndKey; - - ui64 dataSize = child.DataSize; - - State.emplace_back(child.PageId, beginRowId, endRowId, beginKey, endKey, dataSize); - } - - bool TryLoad(TNodeState& state) { - if (state.Node) { - return true; - } - - auto page = Env->TryGetPage(Part, state.PageId); - if (page) { - state.Node.emplace(*page); - return true; - } - return false; + const TNodeState& GetCurrentNode() const { + Y_ABORT_UNLESS(IsValid()); + return Nodes[NodeIndex]; } private: @@ -247,8 +146,9 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { const TGroupId GroupId; const TPartScheme::TGroupInfo& GroupInfo; const TBtreeIndexMeta Meta; - TVector State; ui8 GroupChannel; + ui32 NodeIndex; + TVector Nodes; ui64 PrevDataSize, PrevPrevDataSize; }; diff --git a/ydb/core/tablet_flat/ut/ut_stat.cpp b/ydb/core/tablet_flat/ut/ut_stat.cpp index 91d1cb7452fe..ec0f98477b63 100644 --- a/ydb/core/tablet_flat/ut/ut_stat.cpp +++ b/ydb/core/tablet_flat/ut/ut_stat.cpp @@ -14,8 +14,7 @@ namespace { const TSharedData* TryGetPage(const TPart *part, TPageId id, TGroupId groupId) override { UNIT_ASSERT_C(part->GetPageType(id) == EPage::Index || part->GetPageType(id) == EPage::BTreeIndex, "Shouldn't request non-index pages"); - // TODO: charge b-tree index - if (!Touched[groupId].insert(id).second || part->GetPageType(id) == EPage::BTreeIndex) { + if (!Touched[groupId].insert(id).second) { return NTest::TTestEnv::TryGetPage(part, id, groupId); } return nullptr; From 12ab23439f5d395e31b9fd64b05dd02150bd0092 Mon Sep 17 00:00:00 2001 From: kungasc Date: Wed, 21 Feb 2024 15:15:15 +0300 Subject: [PATCH 6/7] fix rebase --- ydb/core/tablet_flat/test/libs/table/test_part.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ydb/core/tablet_flat/test/libs/table/test_part.h b/ydb/core/tablet_flat/test/libs/table/test_part.h index 2fd1898704d8..80a3dd1f6cb5 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_part.h +++ b/ydb/core/tablet_flat/test/libs/table/test_part.h @@ -189,18 +189,6 @@ namespace NTest { return index.GetRowId(); } - inline TRowId GetRowId(const TPart& part, ui32 pageIndex) { - TTestEnv env; - TPartIndexIt index(&part, &env, { }); - - Y_ABORT_UNLESS(index.Seek(0) == EReady::Data); - for (TPageId p = 0; p < pageIndex; p++) { - Y_ABORT_UNLESS(index.Next() == EReady::Data); - } - - return index.GetRowId(); - } - inline const TPartIndexIt::TRecord * GetRecord(const TPart& part, ui32 pageIndex) { TTestEnv env; TPartIndexIt index(&part, &env, { }); From 1e812e117eb332c17dcd1058694e93c528e4883c Mon Sep 17 00:00:00 2001 From: kungasc Date: Wed, 21 Feb 2024 16:26:18 +0300 Subject: [PATCH 7/7] remove prev size tracking --- .../flat_stat_part_group_btree_index.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h b/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h index 1a39e8e20404..a55eaa2980fd 100644 --- a/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h +++ b/ydb/core/tablet_flat/flat_stat_part_group_btree_index.h @@ -43,8 +43,6 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { , Meta(groupId.IsHistoric() ? part->IndexPages.BTreeHistoric[groupId.Index] : part->IndexPages.BTreeGroups[groupId.Index]) , GroupChannel(Part->GetGroupChannel(GroupId)) , NodeIndex(0) - , PrevDataSize(0) - , PrevPrevDataSize(0) { } @@ -91,18 +89,22 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { EReady Next() override { Y_ABORT_UNLESS(IsValid()); - PrevPrevDataSize = PrevDataSize; - PrevDataSize = GetCurrentNode().DataSize; - NodeIndex++; + + Y_DEBUG_ABORT_UNLESS(NodeIndex == Nodes.size() || Nodes[NodeIndex - 1].EndRowId == Nodes[NodeIndex].BeginRowId); return DataOrGone(); } void AddLastDeltaDataSize(TChanneledDataSize& dataSize) override { - Y_DEBUG_ABORT_UNLESS(PrevDataSize >= PrevPrevDataSize); - ui64 delta = PrevDataSize - PrevPrevDataSize; - dataSize.Add(delta, GroupChannel); + Y_DEBUG_ABORT_UNLESS(NodeIndex); + ui64 delta = Nodes[NodeIndex - 1].DataSize; + if (NodeIndex > 1) { + Y_DEBUG_ABORT_UNLESS(delta >= Nodes[NodeIndex - 2].DataSize); + delta -= Nodes[NodeIndex - 2].DataSize; + } + ui8 channel = Part->GetGroupChannel(GroupId); + dataSize.Add(delta, channel); } public: @@ -149,7 +151,6 @@ class TStatsPartGroupBtreeIndexIterator : public IStatsPartGroupIterator { ui8 GroupChannel; ui32 NodeIndex; TVector Nodes; - ui64 PrevDataSize, PrevPrevDataSize; }; }