@@ -48,8 +48,10 @@ struct HashMethodOneNumber
48
48
using Self = HashMethodOneNumber<Value, Mapped, FieldType, use_cache>;
49
49
using Base = columns_hashing_impl::HashMethodBase<Self, Value, Mapped, use_cache>;
50
50
using KeyHolderType = FieldType;
51
+ using BatchKeyHolderType = KeyHolderType;
51
52
52
53
static constexpr bool is_serialized_key = false ;
54
+ static constexpr bool can_batch_get_key_holder = false ;
53
55
54
56
const FieldType * vec;
55
57
@@ -110,7 +112,7 @@ class KeyStringBatchHandlerBase
110
112
const auto row = batch_row_idx + i;
111
113
const auto last_offset = offsets[row - 1 ];
112
114
// Remove last zero byte.
113
- StringRef key (chars + last_offset, offsets[row] - offsets[row - 1 ] - 1 );
115
+ StringRef key (chars + last_offset, offsets[row] - last_offset - 1 );
114
116
if constexpr (has_collator)
115
117
key = derived_collator->sortKey (key.data , key.size , sort_key_containers[i]);
116
118
@@ -121,15 +123,12 @@ class KeyStringBatchHandlerBase
121
123
122
124
void santityCheck () const
123
125
{
124
- // Make sure init() has called.
126
+ // Make sure init() has been called.
125
127
assert (sort_key_containers.size () == batch_rows.size () && !sort_key_containers.empty ());
126
128
}
127
129
128
130
protected:
129
- bool inited () const
130
- {
131
- return !sort_key_containers.empty ();
132
- }
131
+ bool inited () const { return !sort_key_containers.empty (); }
133
132
134
133
void init (size_t start_row, size_t max_batch_size)
135
134
{
@@ -149,20 +148,20 @@ class KeyStringBatchHandlerBase
149
148
150
149
if likely (collator)
151
150
{
152
- #define M (VAR_PREFIX, COLLATOR_NAME, IMPL_TYPE, COLLATOR_ID ) \
153
- case (COLLATOR_ID): \
154
- { \
155
- return prepareNextBatchType<IMPL_TYPE, true >(chars, offsets, cur_batch_size, collator); \
156
- break ; \
157
- }
151
+ #define M (VAR_PREFIX, COLLATOR_NAME, IMPL_TYPE, COLLATOR_ID ) \
152
+ case (COLLATOR_ID): \
153
+ { \
154
+ return prepareNextBatchType<IMPL_TYPE, true >(chars, offsets, cur_batch_size, collator); \
155
+ break ; \
156
+ }
158
157
159
158
switch (collator->getCollatorId ())
160
159
{
161
160
APPLY_FOR_COLLATOR_TYPES (M)
162
- default :
163
- {
164
- throw Exception (fmt::format (" unexpected collator: {}" , collator->getCollatorId ()));
165
- }
161
+ default :
162
+ {
163
+ throw Exception (fmt::format (" unexpected collator: {}" , collator->getCollatorId ()));
164
+ }
166
165
};
167
166
#undef M
168
167
}
@@ -172,6 +171,7 @@ class KeyStringBatchHandlerBase
172
171
}
173
172
}
174
173
174
+ public:
175
175
// NOTE: i is the index of mini batch, it's not the row index of Column.
176
176
ALWAYS_INLINE inline ArenaKeyHolder getKeyHolderBatch (size_t i, Arena * pool) const
177
177
{
@@ -195,6 +195,8 @@ struct HashMethodString
195
195
using BatchHandlerBase = KeyStringBatchHandlerBase;
196
196
197
197
static constexpr bool is_serialized_key = false ;
198
+ // todo
199
+ static constexpr bool can_batch_get_key_holder = false ;
198
200
199
201
const IColumn::Offset * offsets;
200
202
const UInt8 * chars;
@@ -213,11 +215,6 @@ struct HashMethodString
213
215
collator = collators[0 ];
214
216
}
215
217
216
- bool batchGetkeyHolder () override
217
- {
218
- return BatchHandlerBase::inited ();
219
- }
220
-
221
218
void initBatchHandler (size_t start_row, size_t max_batch_size)
222
219
{
223
220
assert (!BatchHandlerBase::inited ());
@@ -260,6 +257,7 @@ struct HashMethodStringBin
260
257
using BatchKeyHolderType = KeyHolderType;
261
258
262
259
static constexpr bool is_serialized_key = false ;
260
+ static constexpr bool can_batch_get_key_holder = false ;
263
261
264
262
const IColumn::Offset * offsets;
265
263
const UInt8 * chars;
@@ -461,6 +459,7 @@ struct HashMethodFastPathTwoKeysSerialized
461
459
using BatchKeyHolderType = KeyHolderType;
462
460
463
461
static constexpr bool is_serialized_key = true ;
462
+ static constexpr bool can_batch_get_key_holder = false ;
464
463
465
464
Key1Desc key_1_desc;
466
465
Key2Desc key_2_desc;
@@ -499,6 +498,7 @@ struct HashMethodFixedString
499
498
using BatchKeyHolderType = KeyHolderType;
500
499
501
500
static constexpr bool is_serialized_key = false ;
501
+ static constexpr bool can_batch_get_key_holder = false ;
502
502
503
503
size_t n;
504
504
const ColumnFixedString::Chars_t * chars;
@@ -548,6 +548,7 @@ struct HashMethodKeysFixed
548
548
using BatchKeyHolderType = KeyHolderType;
549
549
550
550
static constexpr bool is_serialized_key = false ;
551
+ static constexpr bool can_batch_get_key_holder = false ;
551
552
static constexpr bool has_nullable_keys = has_nullable_keys_;
552
553
553
554
Sizes key_sizes;
@@ -713,10 +714,7 @@ class KeySerializedBatchHandlerBase
713
714
}
714
715
715
716
protected:
716
- bool inited () const
717
- {
718
- return !byte_size.empty ();
719
- }
717
+ bool inited () const { return !byte_size.empty (); }
720
718
721
719
void init (size_t start_row, const ColumnRawPtrs & key_columns, const TiDB::TiDBCollators & collators)
722
720
{
@@ -756,7 +754,7 @@ class KeySerializedBatchHandlerBase
756
754
pos,
757
755
batch_row_idx,
758
756
cur_batch_size,
759
- false ,
757
+ nullptr ,
760
758
collators.empty () ? nullptr : collators[i],
761
759
&sort_key_container);
762
760
@@ -768,6 +766,7 @@ class KeySerializedBatchHandlerBase
768
766
return mem_size;
769
767
}
770
768
769
+ public:
771
770
// NOTE: i is the index of mini batch, it's not the row index of Column.
772
771
ALWAYS_INLINE inline ArenaKeyHolder getKeyHolderBatch (size_t i, Arena * pool) const
773
772
{
@@ -790,10 +789,12 @@ struct HashMethodSerialized
790
789
using Self = HashMethodSerialized<Value, Mapped>;
791
790
using Base = columns_hashing_impl::HashMethodBase<Self, Value, Mapped, false >;
792
791
using BatchHandlerBase = KeySerializedBatchHandlerBase;
793
- static constexpr bool is_serialized_key = true ;
794
792
using KeyHolderType = SerializedKeyHolder;
795
793
using BatchKeyHolderType = ArenaKeyHolder;
796
794
795
+ static constexpr bool is_serialized_key = true ;
796
+ static constexpr bool can_batch_get_key_holder = true ;
797
+
797
798
ColumnRawPtrs key_columns;
798
799
size_t keys_size;
799
800
TiDB::TiDBCollators collators;
@@ -807,11 +808,6 @@ struct HashMethodSerialized
807
808
, collators(collators_)
808
809
{}
809
810
810
- bool batchGetkeyHolder () override
811
- {
812
- return BatchHandlerBase::inited ();
813
- }
814
-
815
811
void initBatchHandler (size_t start_row, size_t /* max_batch_size */ )
816
812
{
817
813
assert (!BatchHandlerBase::inited ());
@@ -849,6 +845,7 @@ struct HashMethodHashed
849
845
using BatchKeyHolderType = KeyHolderType;
850
846
851
847
static constexpr bool is_serialized_key = false ;
848
+ static constexpr bool can_batch_get_key_holder = false ;
852
849
853
850
ColumnRawPtrs key_columns;
854
851
TiDB::TiDBCollators collators;
0 commit comments