From 7900d14d250b123cc60fdb6fa3a7b4d8f3216aa1 Mon Sep 17 00:00:00 2001 From: ivanmorozov333 Date: Tue, 24 Dec 2024 21:59:50 +0300 Subject: [PATCH] fix indexes usage (#12933) --- ydb/core/tx/columnshard/columnshard_schema.h | 9 +++++++++ .../engines/portions/constructor_accessor.cpp | 4 ++-- .../engines/portions/constructor_meta.h | 18 ++++++++++++++++++ .../tx/columnshard/engines/portions/meta.h | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/ydb/core/tx/columnshard/columnshard_schema.h b/ydb/core/tx/columnshard/columnshard_schema.h index 646a4409d737..1837c16501b0 100644 --- a/ydb/core/tx/columnshard/columnshard_schema.h +++ b/ydb/core/tx/columnshard/columnshard_schema.h @@ -1122,6 +1122,15 @@ class TIndexChunkLoadContext { return TIndexChunk(Address.GetColumnId(), Address.GetChunkIdx(), RecordsCount, RawBytes, *BlobData); } + TIndexChunk BuildIndexChunk(const TPortionInfo& portionInfo) const { + if (BlobData) { + return BuildIndexChunk(); + } else { + AFL_VERIFY(!!BlobRange); + return BuildIndexChunk(portionInfo.GetMeta().GetBlobIdxVerified(BlobRange->BlobId)); + } + } + template TIndexChunkLoadContext(const TSource& rowset, const IBlobGroupSelector* dsGroupSelector) : PathId(rowset.template GetValue()) diff --git a/ydb/core/tx/columnshard/engines/portions/constructor_accessor.cpp b/ydb/core/tx/columnshard/engines/portions/constructor_accessor.cpp index 380778476fcd..b3d6b778f11c 100644 --- a/ydb/core/tx/columnshard/engines/portions/constructor_accessor.cpp +++ b/ydb/core/tx/columnshard/engines/portions/constructor_accessor.cpp @@ -121,7 +121,7 @@ void TPortionAccessorConstructor::LoadRecord(TColumnChunkLoadContextV1&& loadCon void TPortionAccessorConstructor::LoadIndex(TIndexChunkLoadContext&& loadContext) { if (loadContext.GetBlobRange()) { - const TBlobRangeLink16::TLinkId linkBlobId = RegisterBlobId(loadContext.GetBlobRange()->GetBlobId()); + const TBlobRangeLink16::TLinkId linkBlobId = PortionInfo.GetMeta().GetBlobIdxVerified(loadContext.GetBlobRange()->GetBlobId()); AddIndex(loadContext.BuildIndexChunk(linkBlobId)); } else { AddIndex(loadContext.BuildIndexChunk()); @@ -156,7 +156,7 @@ TPortionDataAccessor TPortionAccessorConstructor::BuildForLoading( }; bool needSort = false; for (auto&& i : indexes) { - auto chunk = i.BuildIndexChunk(); + auto chunk = i.BuildIndexChunk(*portion); if (indexChunks.size() && !pred(indexChunks.back(), chunk)) { needSort = true; } diff --git a/ydb/core/tx/columnshard/engines/portions/constructor_meta.h b/ydb/core/tx/columnshard/engines/portions/constructor_meta.h index 4135e89ff9e6..71f7ae692501 100644 --- a/ydb/core/tx/columnshard/engines/portions/constructor_meta.h +++ b/ydb/core/tx/columnshard/engines/portions/constructor_meta.h @@ -64,6 +64,24 @@ class TPortionMetaConstructor { return idx; } + std::optional GetBlobIdxOptional(const TUnifiedBlobId& blobId) const { + AFL_VERIFY(blobId.IsValid()); + TBlobRangeLink16::TLinkId idx = 0; + for (auto&& i : BlobIds) { + if (i == blobId) { + return idx; + } + ++idx; + } + return std::nullopt; + } + + TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const { + auto result = GetBlobIdxOptional(blobId); + AFL_VERIFY(result); + return *result; + } + void SetCompactionLevel(const ui64 level) { CompactionLevel = level; } diff --git a/ydb/core/tx/columnshard/engines/portions/meta.h b/ydb/core/tx/columnshard/engines/portions/meta.h index 6b2bb00bd49d..7c212fdf00c1 100644 --- a/ydb/core/tx/columnshard/engines/portions/meta.h +++ b/ydb/core/tx/columnshard/engines/portions/meta.h @@ -68,6 +68,24 @@ struct TPortionMeta { CompactionLevel = level; } + std::optional GetBlobIdxOptional(const TUnifiedBlobId& blobId) const { + AFL_VERIFY(blobId.IsValid()); + TBlobRangeLink16::TLinkId idx = 0; + for (auto&& i : BlobIds) { + if (i == blobId) { + return idx; + } + ++idx; + } + return std::nullopt; + } + + TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const { + auto result = GetBlobIdxOptional(blobId); + AFL_VERIFY(result); + return *result; + } + using EProduced = NPortion::EProduced; NArrow::TReplaceKey IndexKeyStart;