Skip to content

Commit

Permalink
fix indexes usage (ydb-platform#12933)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored and zverevgeny committed Jan 5, 2025
1 parent c8ee433 commit 7900d14
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ydb/core/tx/columnshard/columnshard_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class TSource>
TIndexChunkLoadContext(const TSource& rowset, const IBlobGroupSelector* dsGroupSelector)
: PathId(rowset.template GetValue<NColumnShard::Schema::IndexIndexes::PathId>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions ydb/core/tx/columnshard/engines/portions/constructor_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ class TPortionMetaConstructor {
return idx;
}

std::optional<TBlobRangeLink16::TLinkId> 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;
}
Expand Down
18 changes: 18 additions & 0 deletions ydb/core/tx/columnshard/engines/portions/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ struct TPortionMeta {
CompactionLevel = level;
}

std::optional<TBlobRangeLink16::TLinkId> 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;
Expand Down

0 comments on commit 7900d14

Please sign in to comment.