Skip to content

Commit 77d45e0

Browse files
Merge 14a4376 into 481ccad
2 parents 481ccad + 14a4376 commit 77d45e0

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,39 @@ TPortionDataAccessor TPortionAccessorConstructor::BuildForLoading(
130130
const TPortionInfo::TConstPtr& portion, std::vector<TColumnChunkLoadContextV1>&& records, std::vector<TIndexChunkLoadContext>&& indexes) {
131131
AFL_VERIFY(portion);
132132
std::vector<TColumnRecord> recordChunks;
133-
for (auto&& i : records) {
134-
recordChunks.emplace_back(TColumnRecord(i));
133+
{
134+
const auto pred = [](const TColumnRecord& l, const TColumnRecord& r) {
135+
return l.GetAddress() < r.GetAddress();
136+
};
137+
bool needSort = false;
138+
for (auto&& i : records) {
139+
if (recordChunks.size() && !pred(recordChunks.back(), i)) {
140+
needSort = true;
141+
}
142+
recordChunks.emplace_back(TColumnRecord(i));
143+
}
144+
if (needSort) {
145+
std::sort(recordChunks.begin(), recordChunks.end(), pred);
146+
}
135147
}
136148
std::vector<TIndexChunk> indexChunks;
137-
for (auto&& i : indexes) {
138-
indexChunks.emplace_back(i.BuildIndexChunk());
149+
{
150+
151+
const auto pred = [](const TIndexChunk& l, const TIndexChunk& r) {
152+
return l.GetAddress() < r.GetAddress();
153+
};
154+
bool needSort = false;
155+
for (auto&& i : indexes) {
156+
if (indexChunks.size() && !pred(indexChunks.back(), i)) {
157+
needSort = true;
158+
}
159+
indexChunks.emplace_back(i.BuildIndexChunk());
160+
}
161+
if (needSort) {
162+
std::sort(indexChunks.begin(), indexChunks.end(), pred);
163+
}
139164
}
165+
std::sort(indexChunks.begin(), indexChunks.end(), pred);
140166
return TPortionDataAccessor(portion, std::move(recordChunks), std::move(indexChunks), true);
141167
}
142168

0 commit comments

Comments
 (0)