@@ -22,10 +22,26 @@ std::vector<std::pair<ui64, TOwnedTableRange>> GetRangePartitioning(const TKqpSt
22
22
23
23
YQL_ENSURE (partitionInfo);
24
24
25
+ // Binary search of the index to start with.
26
+ size_t idxStart = 0 ;
27
+ size_t idxFinish = partitionInfo->size ();
28
+ while ((idxFinish - idxStart) > 1 ) {
29
+ size_t idxCur = (idxFinish + idxStart) / 2 ;
30
+ const auto & partCur = (*partitionInfo)[idxCur].Range ->EndKeyPrefix .GetCells ();
31
+ YQL_ENSURE (partCur.size () <= keyColumnTypes.size ());
32
+ int cmp = CompareTypedCellVectors (partCur.data (), range.From .data (), keyColumnTypes.data (),
33
+ std::min (partCur.size (), range.From .size ()));
34
+ if (cmp < 0 ) {
35
+ idxStart = idxCur;
36
+ } else {
37
+ idxFinish = idxCur;
38
+ }
39
+ }
40
+
25
41
std::vector<TCell> minusInf (keyColumnTypes.size ());
26
42
27
43
std::vector<std::pair<ui64, TOwnedTableRange>> rangePartition;
28
- for (size_t idx = 0 ; idx < partitionInfo->size (); ++idx) {
44
+ for (size_t idx = idxStart ; idx < partitionInfo->size (); ++idx) {
29
45
TTableRange partitionRange{
30
46
idx == 0 ? minusInf : (*partitionInfo)[idx - 1 ].Range ->EndKeyPrefix .GetCells (),
31
47
idx == 0 ? true : !(*partitionInfo)[idx - 1 ].Range ->IsInclusive ,
@@ -108,6 +124,12 @@ TKqpStreamLookupWorker::TKqpStreamLookupWorker(NKikimrKqp::TKqpStreamLookupSetti
108
124
column.GetTypeInfo ().GetPgTypeMod ()
109
125
});
110
126
}
127
+
128
+ KeyColumnTypes.resize (KeyColumns.size ());
129
+ for (const auto & [_, columnInfo] : KeyColumns) {
130
+ YQL_ENSURE (columnInfo.KeyOrder < static_cast <i64 >(KeyColumnTypes.size ()));
131
+ KeyColumnTypes[columnInfo.KeyOrder ] = columnInfo.PType ;
132
+ }
111
133
}
112
134
113
135
TKqpStreamLookupWorker::~TKqpStreamLookupWorker () {
@@ -121,16 +143,6 @@ TTableId TKqpStreamLookupWorker::GetTableId() const {
121
143
return TableId;
122
144
}
123
145
124
- std::vector<NScheme::TTypeInfo> TKqpStreamLookupWorker::GetKeyColumnTypes () const {
125
- std::vector<NScheme::TTypeInfo> keyColumnTypes (KeyColumns.size ());
126
- for (const auto & [_, columnInfo] : KeyColumns) {
127
- YQL_ENSURE (columnInfo.KeyOrder < static_cast <i64 >(keyColumnTypes.size ()));
128
- keyColumnTypes[columnInfo.KeyOrder ] = columnInfo.PType ;
129
- }
130
-
131
- return keyColumnTypes;
132
- }
133
-
134
146
class TKqpLookupRows : public TKqpStreamLookupWorker {
135
147
public:
136
148
TKqpLookupRows (NKikimrKqp::TKqpStreamLookupSettings&& settings, const NMiniKQL::TTypeEnvironment& typeEnv,
0 commit comments