@@ -130,12 +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) -> bool {
135+ return l.GetAddress () < r.GetAddress ();
136+ };
137+ bool needSort = false ;
138+ for (auto && i : records) {
139+ TColumnRecord chunk (i);
140+ if (recordChunks.size () && !pred (recordChunks.back (), chunk)) {
141+ needSort = true ;
142+ }
143+ recordChunks.emplace_back (std::move (chunk));
144+ }
145+ if (needSort) {
146+ std::sort (recordChunks.begin (), recordChunks.end (), pred);
147+ }
135148 }
136149 std::vector<TIndexChunk> indexChunks;
137- for (auto && i : indexes) {
138- indexChunks.emplace_back (i.BuildIndexChunk ());
150+ {
151+
152+ const auto pred = [](const TIndexChunk& l, const TIndexChunk& r) ->bool {
153+ return l.GetAddress () < r.GetAddress ();
154+ };
155+ bool needSort = false ;
156+ for (auto && i : indexes) {
157+ auto chunk = i.BuildIndexChunk ();
158+ if (indexChunks.size () && !pred (indexChunks.back (), chunk)) {
159+ needSort = true ;
160+ }
161+ indexChunks.emplace_back (std::move (chunk));
162+ }
163+ if (needSort) {
164+ std::sort (indexChunks.begin (), indexChunks.end (), pred);
165+ }
139166 }
140167 return TPortionDataAccessor (portion, std::move (recordChunks), std::move (indexChunks), true );
141168}
0 commit comments