Skip to content

Commit 3354b7f

Browse files
committed
case ok
Signed-off-by: guo-shaoge <shaoge1994@163.com>
1 parent e2bdc81 commit 3354b7f

File tree

4 files changed

+293
-208
lines changed

4 files changed

+293
-208
lines changed

dbms/src/Common/ColumnsHashing.h

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ struct HashMethodOneNumber
4848
using Self = HashMethodOneNumber<Value, Mapped, FieldType, use_cache>;
4949
using Base = columns_hashing_impl::HashMethodBase<Self, Value, Mapped, use_cache>;
5050
using KeyHolderType = FieldType;
51+
using BatchKeyHolderType = KeyHolderType;
5152

5253
static constexpr bool is_serialized_key = false;
54+
static constexpr bool can_batch_get_key_holder = false;
5355

5456
const FieldType * vec;
5557

@@ -110,7 +112,7 @@ class KeyStringBatchHandlerBase
110112
const auto row = batch_row_idx + i;
111113
const auto last_offset = offsets[row - 1];
112114
// 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);
114116
if constexpr (has_collator)
115117
key = derived_collator->sortKey(key.data, key.size, sort_key_containers[i]);
116118

@@ -121,15 +123,12 @@ class KeyStringBatchHandlerBase
121123

122124
void santityCheck() const
123125
{
124-
// Make sure init() has called.
126+
// Make sure init() has been called.
125127
assert(sort_key_containers.size() == batch_rows.size() && !sort_key_containers.empty());
126128
}
127129

128130
protected:
129-
bool inited() const
130-
{
131-
return !sort_key_containers.empty();
132-
}
131+
bool inited() const { return !sort_key_containers.empty(); }
133132

134133
void init(size_t start_row, size_t max_batch_size)
135134
{
@@ -149,20 +148,20 @@ class KeyStringBatchHandlerBase
149148

150149
if likely (collator)
151150
{
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+
}
158157

159158
switch (collator->getCollatorId())
160159
{
161160
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+
}
166165
};
167166
#undef M
168167
}
@@ -172,6 +171,7 @@ class KeyStringBatchHandlerBase
172171
}
173172
}
174173

174+
public:
175175
// NOTE: i is the index of mini batch, it's not the row index of Column.
176176
ALWAYS_INLINE inline ArenaKeyHolder getKeyHolderBatch(size_t i, Arena * pool) const
177177
{
@@ -195,6 +195,8 @@ struct HashMethodString
195195
using BatchHandlerBase = KeyStringBatchHandlerBase;
196196

197197
static constexpr bool is_serialized_key = false;
198+
// todo
199+
static constexpr bool can_batch_get_key_holder = false;
198200

199201
const IColumn::Offset * offsets;
200202
const UInt8 * chars;
@@ -213,11 +215,6 @@ struct HashMethodString
213215
collator = collators[0];
214216
}
215217

216-
bool batchGetkeyHolder() override
217-
{
218-
return BatchHandlerBase::inited();
219-
}
220-
221218
void initBatchHandler(size_t start_row, size_t max_batch_size)
222219
{
223220
assert(!BatchHandlerBase::inited());
@@ -260,6 +257,7 @@ struct HashMethodStringBin
260257
using BatchKeyHolderType = KeyHolderType;
261258

262259
static constexpr bool is_serialized_key = false;
260+
static constexpr bool can_batch_get_key_holder = false;
263261

264262
const IColumn::Offset * offsets;
265263
const UInt8 * chars;
@@ -461,6 +459,7 @@ struct HashMethodFastPathTwoKeysSerialized
461459
using BatchKeyHolderType = KeyHolderType;
462460

463461
static constexpr bool is_serialized_key = true;
462+
static constexpr bool can_batch_get_key_holder = false;
464463

465464
Key1Desc key_1_desc;
466465
Key2Desc key_2_desc;
@@ -499,6 +498,7 @@ struct HashMethodFixedString
499498
using BatchKeyHolderType = KeyHolderType;
500499

501500
static constexpr bool is_serialized_key = false;
501+
static constexpr bool can_batch_get_key_holder = false;
502502

503503
size_t n;
504504
const ColumnFixedString::Chars_t * chars;
@@ -548,6 +548,7 @@ struct HashMethodKeysFixed
548548
using BatchKeyHolderType = KeyHolderType;
549549

550550
static constexpr bool is_serialized_key = false;
551+
static constexpr bool can_batch_get_key_holder = false;
551552
static constexpr bool has_nullable_keys = has_nullable_keys_;
552553

553554
Sizes key_sizes;
@@ -713,10 +714,7 @@ class KeySerializedBatchHandlerBase
713714
}
714715

715716
protected:
716-
bool inited() const
717-
{
718-
return !byte_size.empty();
719-
}
717+
bool inited() const { return !byte_size.empty(); }
720718

721719
void init(size_t start_row, const ColumnRawPtrs & key_columns, const TiDB::TiDBCollators & collators)
722720
{
@@ -756,7 +754,7 @@ class KeySerializedBatchHandlerBase
756754
pos,
757755
batch_row_idx,
758756
cur_batch_size,
759-
false,
757+
nullptr,
760758
collators.empty() ? nullptr : collators[i],
761759
&sort_key_container);
762760

@@ -768,6 +766,7 @@ class KeySerializedBatchHandlerBase
768766
return mem_size;
769767
}
770768

769+
public:
771770
// NOTE: i is the index of mini batch, it's not the row index of Column.
772771
ALWAYS_INLINE inline ArenaKeyHolder getKeyHolderBatch(size_t i, Arena * pool) const
773772
{
@@ -790,10 +789,12 @@ struct HashMethodSerialized
790789
using Self = HashMethodSerialized<Value, Mapped>;
791790
using Base = columns_hashing_impl::HashMethodBase<Self, Value, Mapped, false>;
792791
using BatchHandlerBase = KeySerializedBatchHandlerBase;
793-
static constexpr bool is_serialized_key = true;
794792
using KeyHolderType = SerializedKeyHolder;
795793
using BatchKeyHolderType = ArenaKeyHolder;
796794

795+
static constexpr bool is_serialized_key = true;
796+
static constexpr bool can_batch_get_key_holder = true;
797+
797798
ColumnRawPtrs key_columns;
798799
size_t keys_size;
799800
TiDB::TiDBCollators collators;
@@ -807,11 +808,6 @@ struct HashMethodSerialized
807808
, collators(collators_)
808809
{}
809810

810-
bool batchGetkeyHolder() override
811-
{
812-
return BatchHandlerBase::inited();
813-
}
814-
815811
void initBatchHandler(size_t start_row, size_t /* max_batch_size */)
816812
{
817813
assert(!BatchHandlerBase::inited());
@@ -849,6 +845,7 @@ struct HashMethodHashed
849845
using BatchKeyHolderType = KeyHolderType;
850846

851847
static constexpr bool is_serialized_key = false;
848+
static constexpr bool can_batch_get_key_holder = false;
852849

853850
ColumnRawPtrs key_columns;
854851
TiDB::TiDBCollators collators;

dbms/src/Common/ColumnsHashingImpl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ class HashMethodBase
129129
using Cache = LastElementCache<Value, consecutive_keys_optimization>;
130130
using Derived = TDerived;
131131

132-
bool batchGetKeyHolder() const override
133-
{
134-
return false;
135-
}
136-
137132
template <typename Data>
138133
ALWAYS_INLINE inline EmplaceResult emplaceKey(
139134
Data & data,

0 commit comments

Comments
 (0)