1
1
#pragma once
2
2
3
3
#include " flat_part_iface.h"
4
+ #include " flat_part_index_iter.h"
4
5
#include " flat_part_laid.h"
5
6
#include " flat_page_frames.h"
6
7
#include " util_basics.h"
@@ -118,47 +119,69 @@ class TPartDataSizeHelper {
118
119
// if page start key is not screened then the whole previous page is added to stats
119
120
class TScreenedPartIndexIterator {
120
121
public:
121
- TScreenedPartIndexIterator (TPartView partView, TIntrusiveConstPtr<TKeyCellDefaults> keyColumns,
122
+ TScreenedPartIndexIterator (TPartView partView, IPages* env, TIntrusiveConstPtr<TKeyCellDefaults> keyColumns,
122
123
TIntrusiveConstPtr<NPage::TFrames> small, TIntrusiveConstPtr<NPage::TFrames> large)
123
124
: Part(std::move(partView.Part))
125
+ , Pos(Part.Get(), env, {})
124
126
, KeyColumns(std::move(keyColumns))
125
127
, Screen(std::move(partView.Screen))
126
128
, Small(std::move(small))
127
129
, Large(std::move(large))
128
130
, CurrentHole(TScreen::Iter(Screen, CurrentHoleIdx, 0 , 1 ))
129
131
{
130
- Pos = Part->Index ->Begin ();
131
- End = Part->Index ->End ();
132
132
AltGroups.reserve (Part->GroupsCount - 1 );
133
133
for (ui32 group : xrange (size_t (1 ), Part->GroupsCount )) {
134
- AltGroups.emplace_back (Part.Get (), NPage::TGroupId (group));
134
+ AltGroups.emplace_back (Part.Get (), env, NPage::TGroupId (group));
135
135
}
136
- for (ui32 group : xrange (Part->HistoricGroupsCount )) {
137
- HistoryGroups.emplace_back (Part.Get (), NPage::TGroupId (group, true ));
136
+ for (ui32 group : xrange (Part->HistoricIndexes . size () )) {
137
+ HistoryGroups.emplace_back (Part.Get (), env, NPage::TGroupId (group, true ));
138
138
}
139
+ }
140
+
141
+ EReady Start () {
142
+ auto ready = Pos.Seek (0 );
139
143
FillKey ();
144
+
145
+ for (auto & g : AltGroups) {
146
+ if (g.Pos .Seek (0 ) == EReady::Page) {
147
+ ready = EReady::Page;
148
+ }
149
+ }
150
+ for (auto & g : HistoryGroups) {
151
+ if (g.Pos .Seek (0 ) == EReady::Page) {
152
+ ready = EReady::Page;
153
+ }
154
+ }
155
+
156
+ return ready;
140
157
}
141
158
142
159
bool IsValid () const {
143
- return Pos != End ;
160
+ return Pos. IsValid () ;
144
161
}
145
162
146
- void Next (TPartDataStats& stats) {
163
+ EReady Next (TPartDataStats& stats) {
147
164
Y_VERIFY (IsValid ());
148
165
149
- auto curPageId = Pos->GetPageId ();
150
- LastRowId = Pos->GetRowId ();
151
- ++Pos;
166
+ auto curPageId = Pos.GetPageId ();
167
+ LastRowId = Pos.GetRowId ();
168
+ auto ready = Pos.Next ();
169
+ if (ready == EReady::Page) {
170
+ return ready;
171
+ }
152
172
ui64 rowCount = IncludedRows (GetLastRowId (), GetCurrentRowId ());
153
173
stats.RowCount += rowCount;
154
174
155
175
if (rowCount) AddPageSize (stats.DataSize , curPageId);
156
- TRowId nextRowId = Pos ? Pos-> GetRowId () : Max<TRowId>();
176
+ TRowId nextRowId = ready == EReady::Data ? Pos. GetRowId () : Max<TRowId>();
157
177
for (auto & g : AltGroups) {
158
- while (g.Pos && g.Pos -> GetRowId () < nextRowId) {
178
+ while (g.Pos . IsValid () && g.Pos . GetRowId () < nextRowId) {
159
179
// eagerly include all data up to the next row id
160
- if (rowCount) AddPageSize (stats.DataSize , g.Pos ->GetPageId (), g.GroupId );
161
- ++g.Pos ;
180
+ if (rowCount) AddPageSize (stats.DataSize , g.Pos .GetPageId (), g.GroupId );
181
+ if (g.Pos .Next () == EReady::Page) {
182
+ ready = EReady::Page;
183
+ break ;
184
+ }
162
185
}
163
186
}
164
187
@@ -167,18 +190,24 @@ class TScreenedPartIndexIterator {
167
190
auto & h = HistoryGroups[0 ];
168
191
const auto & hscheme = Part->Scheme ->HistoryGroup ;
169
192
Y_VERIFY_DEBUG (hscheme.ColsKeyIdx .size () == 3 );
170
- while (h.Pos && h.Pos ->Cell (hscheme.ColsKeyIdx [0 ]).AsValue <TRowId>() < nextRowId) {
193
+ while (h.Pos . IsValid () && h.Pos . GetRecord () ->Cell (hscheme.ColsKeyIdx [0 ]).AsValue <TRowId>() < nextRowId) {
171
194
// eagerly include all history up to the next row id
172
- if (rowCount) AddPageSize (stats.DataSize , h.Pos ->GetPageId (), h.GroupId );
173
- ++h.Pos ;
195
+ if (rowCount) AddPageSize (stats.DataSize , h.Pos .GetPageId (), h.GroupId );
196
+ if (h.Pos .Next () == EReady::Page) {
197
+ ready = EReady::Page;
198
+ break ;
199
+ }
174
200
}
175
- TRowId nextHistoryRowId = h.Pos ? h.Pos -> GetRowId () : Max<TRowId>();
201
+ TRowId nextHistoryRowId = h.Pos . IsValid () ? h.Pos . GetRowId () : Max<TRowId>();
176
202
for (size_t index = 1 ; index < HistoryGroups.size (); ++index ) {
177
203
auto & g = HistoryGroups[index ];
178
- while (g.Pos && g.Pos -> GetRowId () < nextHistoryRowId) {
204
+ while (g.Pos . IsValid () && g.Pos . GetRowId () < nextHistoryRowId) {
179
205
// eagerly include all data up to the next row id
180
- if (rowCount) AddPageSize (stats.DataSize , g.Pos ->GetPageId (), g.GroupId );
181
- ++g.Pos ;
206
+ if (rowCount) AddPageSize (stats.DataSize , g.Pos .GetPageId (), g.GroupId );
207
+ if (g.Pos .Next () == EReady::Page) {
208
+ ready = EReady::Page;
209
+ break ;
210
+ }
182
211
}
183
212
}
184
213
}
@@ -193,6 +222,7 @@ class TScreenedPartIndexIterator {
193
222
}
194
223
195
224
FillKey ();
225
+ return ready;
196
226
}
197
227
198
228
TDbTupleRef GetCurrentKey () const {
@@ -207,7 +237,7 @@ class TScreenedPartIndexIterator {
207
237
208
238
ui64 GetCurrentRowId () const {
209
239
if (IsValid ()) {
210
- return Pos-> GetRowId ();
240
+ return Pos. GetRowId ();
211
241
}
212
242
if (TRowId endRowId = Part->Index .GetEndRowId (); endRowId != Max<TRowId>()) {
213
243
// This would include the last page rows when known
@@ -233,7 +263,7 @@ class TScreenedPartIndexIterator {
233
263
ui32 keyIdx = 0 ;
234
264
// Add columns that are present in the part
235
265
for (;keyIdx < Part->Scheme ->Groups [0 ].KeyTypes .size (); ++keyIdx) {
236
- CurrentKey.push_back (Pos->Cell (Part->Scheme ->Groups [0 ].ColsKeyIdx [keyIdx]));
266
+ CurrentKey.push_back (Pos. GetRecord () ->Cell (Part->Scheme ->Groups [0 ].ColsKeyIdx [keyIdx]));
237
267
}
238
268
239
269
// Extend with default values if needed
@@ -293,20 +323,19 @@ class TScreenedPartIndexIterator {
293
323
294
324
private:
295
325
struct TGroupState {
296
- NPage::TIndex::TIter Pos;
326
+ TPartIndexIt Pos;
297
327
const NPage::TGroupId GroupId;
298
328
299
- TGroupState (const TPart* part, NPage::TGroupId groupId)
300
- : Pos(part-> GetGroupIndex ( groupId)->Begin() )
329
+ TGroupState (const TPart* part, IPages* env, NPage::TGroupId groupId)
330
+ : Pos(part, env, groupId)
301
331
, GroupId(groupId)
302
332
{ }
303
333
};
304
334
305
335
private:
306
336
TIntrusiveConstPtr<TPart> Part;
337
+ TPartIndexIt Pos;
307
338
TIntrusiveConstPtr<TKeyCellDefaults> KeyColumns;
308
- NPage::TIndex::TIter Pos;
309
- NPage::TIndex::TIter End;
310
339
TSmallVec<TCell> CurrentKey;
311
340
ui64 LastRowId = 0 ;
312
341
TSmallVec<TGroupState> AltGroups;
0 commit comments