Skip to content

Commit f6d8d59

Browse files
fix indexes usage (#12933)
1 parent 95f3cb4 commit f6d8d59

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

ydb/core/tx/columnshard/columnshard_schema.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,15 @@ class TIndexChunkLoadContext {
11221122
return TIndexChunk(Address.GetColumnId(), Address.GetChunkIdx(), RecordsCount, RawBytes, *BlobData);
11231123
}
11241124

1125+
TIndexChunk BuildIndexChunk(const TPortionInfo& portionInfo) const {
1126+
if (BlobData) {
1127+
return BuildIndexChunk();
1128+
} else {
1129+
AFL_VERIFY(!!BlobRange);
1130+
return BuildIndexChunk(portionInfo.GetMeta().GetBlobIdxVerified(BlobRange->BlobId));
1131+
}
1132+
}
1133+
11251134
template <class TSource>
11261135
TIndexChunkLoadContext(const TSource& rowset, const IBlobGroupSelector* dsGroupSelector)
11271136
: PathId(rowset.template GetValue<NColumnShard::Schema::IndexIndexes::PathId>())

ydb/core/tx/columnshard/engines/portions/constructor_accessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void TPortionAccessorConstructor::LoadRecord(TColumnChunkLoadContextV1&& loadCon
121121

122122
void TPortionAccessorConstructor::LoadIndex(TIndexChunkLoadContext&& loadContext) {
123123
if (loadContext.GetBlobRange()) {
124-
const TBlobRangeLink16::TLinkId linkBlobId = RegisterBlobId(loadContext.GetBlobRange()->GetBlobId());
124+
const TBlobRangeLink16::TLinkId linkBlobId = PortionInfo.GetMeta().GetBlobIdxVerified(loadContext.GetBlobRange()->GetBlobId());
125125
AddIndex(loadContext.BuildIndexChunk(linkBlobId));
126126
} else {
127127
AddIndex(loadContext.BuildIndexChunk());
@@ -156,7 +156,7 @@ TPortionDataAccessor TPortionAccessorConstructor::BuildForLoading(
156156
};
157157
bool needSort = false;
158158
for (auto&& i : indexes) {
159-
auto chunk = i.BuildIndexChunk();
159+
auto chunk = i.BuildIndexChunk(*portion);
160160
if (indexChunks.size() && !pred(indexChunks.back(), chunk)) {
161161
needSort = true;
162162
}

ydb/core/tx/columnshard/engines/portions/constructor_meta.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ class TPortionMetaConstructor {
6464
return idx;
6565
}
6666

67+
std::optional<TBlobRangeLink16::TLinkId> GetBlobIdxOptional(const TUnifiedBlobId& blobId) const {
68+
AFL_VERIFY(blobId.IsValid());
69+
TBlobRangeLink16::TLinkId idx = 0;
70+
for (auto&& i : BlobIds) {
71+
if (i == blobId) {
72+
return idx;
73+
}
74+
++idx;
75+
}
76+
return std::nullopt;
77+
}
78+
79+
TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const {
80+
auto result = GetBlobIdxOptional(blobId);
81+
AFL_VERIFY(result);
82+
return *result;
83+
}
84+
6785
void SetCompactionLevel(const ui64 level) {
6886
CompactionLevel = level;
6987
}

ydb/core/tx/columnshard/engines/portions/meta.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ struct TPortionMeta {
6868
CompactionLevel = level;
6969
}
7070

71+
std::optional<TBlobRangeLink16::TLinkId> GetBlobIdxOptional(const TUnifiedBlobId& blobId) const {
72+
AFL_VERIFY(blobId.IsValid());
73+
TBlobRangeLink16::TLinkId idx = 0;
74+
for (auto&& i : BlobIds) {
75+
if (i == blobId) {
76+
return idx;
77+
}
78+
++idx;
79+
}
80+
return std::nullopt;
81+
}
82+
83+
TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const {
84+
auto result = GetBlobIdxOptional(blobId);
85+
AFL_VERIFY(result);
86+
return *result;
87+
}
88+
7189
using EProduced = NPortion::EProduced;
7290

7391
NArrow::TReplaceKey IndexKeyStart;

0 commit comments

Comments
 (0)