Skip to content

Commit fca76c5

Browse files
committed
update fix
1 parent ce36e33 commit fca76c5

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

be/src/util/simd/bits.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,24 @@ inline size_t find_zero(const std::vector<uint8_t>& vec, size_t start) {
283283

284284
inline bool contain_one(const uint8_t* __restrict data, size_t size) {
285285
size_t i = 0;
286-
#if defined(__SSE2__)
286+
#if defined(__AVX2__)
287+
{
288+
const __m256i zero = _mm256_setzero_si256();
289+
for (; i + 31 < size; i += 32) {
290+
__m256i chunk = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(data + i));
291+
if (_mm256_movemask_epi8(_mm256_cmpeq_epi8(chunk, zero)) != 0xFFFFFFFF) {
292+
return true;
293+
}
294+
}
295+
}
296+
#elif defined(__SSE2__)
287297
{
288298
const __m128i zero = _mm_setzero_si128();
289-
__m128i acc = zero;
290299
for (; i + 15 < size; i += 16) {
291-
acc = _mm_or_si128(acc, _mm_loadu_si128(reinterpret_cast<const __m128i*>(data + i)));
292-
}
293-
294-
if (_mm_movemask_epi8(_mm_cmpeq_epi8(acc, zero)) != 0xFFFF) {
295-
return true;
300+
__m128i chunk = _mm_loadu_si128(reinterpret_cast<const __m128i*>(data + i));
301+
if (_mm_movemask_epi8(_mm_cmpeq_epi8(chunk, zero)) != 0xFFFF) {
302+
return true;
303+
}
296304
}
297305
}
298306
#endif

be/src/vec/common/hash_table/hash_key_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ inline HashKeyType get_hash_key_type_fixed(const std::vector<vectorized::DataTyp
9494
}
9595
}
9696

97-
size_t bitmap_size = has_null ? vectorized::get_bitmap_size(data_types.size()) : 0;
97+
size_t bitmap_size = has_null ? 1 : 0;
9898
return get_hash_key_type_with_fixed(bitmap_size + key_byte_size);
9999
}
100100

101101
inline HashKeyType get_hash_key_type(const std::vector<vectorized::DataTypePtr>& data_types) {
102-
if (data_types.size() > 1) {
102+
if (data_types.size() > 1 && data_types.size() <= vectorized::BITSIZE) {
103103
return get_hash_key_type_fixed(data_types);
104104
}
105105
if (data_types.empty()) {

be/src/vec/common/hash_table/hash_map_context.h

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ struct MethodSerialized : public MethodBase<TData> {
291291
}
292292
};
293293

294-
inline size_t get_bitmap_size(size_t key_number) {
295-
return (key_number + BITSIZE - 1) / BITSIZE;
296-
}
297-
298294
template <typename TData>
299295
struct MethodStringNoCache : public MethodBase<TData> {
300296
using Base = MethodBase<TData>;
@@ -562,7 +558,7 @@ struct MethodKeysFixed : public MethodBase<TData> {
562558
template <typename T>
563559
void pack_fixeds(size_t row_numbers, const ColumnRawPtrs& key_columns,
564560
const ColumnRawPtrs& nullmap_columns, DorisVector<T>& result) {
565-
size_t bitmap_size = get_bitmap_size(nullmap_columns.size());
561+
size_t bitmap_size = nullmap_columns.empty() ? 0 : 1;
566562
if (bitmap_size) {
567563
// set size to 0 at first, then use resize to call default constructor on index included from [0, row_numbers) to reset all memory
568564
// only need to reset the memory used to bitmap
@@ -590,13 +586,9 @@ struct MethodKeysFixed : public MethodBase<TData> {
590586
bit_offsets.emplace_back(j % BITSIZE);
591587
}
592588
}
593-
for (size_t j = 0, bucket = 0; j < nullmap_datas.size(); j += BITSIZE, bucket++) {
594-
int column_batch = std::min(BITSIZE, (int)(nullmap_datas.size() - j));
595-
constexpr_int_match<1, BITSIZE, PackNullmapsReducer>::run(
596-
column_batch, nullmap_datas.data() + j, bit_offsets.data() + j, row_numbers,
597-
sizeof(T), reinterpret_cast<uint8_t*>(result_data + bucket));
598-
}
599-
589+
constexpr_int_match<1, BITSIZE, PackNullmapsReducer>::run(
590+
int(nullmap_datas.size()), nullmap_datas.data(), bit_offsets.data(), row_numbers,
591+
sizeof(T), reinterpret_cast<uint8_t*>(result_data));
600592
offset += bitmap_size;
601593
}
602594

@@ -657,6 +649,7 @@ struct MethodKeysFixed : public MethodBase<TData> {
657649
void init_serialized_keys(const ColumnRawPtrs& key_columns, uint32_t num_rows,
658650
const uint8_t* null_map = nullptr, bool is_join = false,
659651
bool is_build = false, uint32_t bucket_size = 0) override {
652+
CHECK(key_columns.size() <= BITSIZE);
660653
ColumnRawPtrs actual_columns;
661654
ColumnRawPtrs null_maps;
662655
actual_columns.reserve(key_columns.size());
@@ -694,14 +687,7 @@ struct MethodKeysFixed : public MethodBase<TData> {
694687

695688
void insert_keys_into_columns(std::vector<typename Base::Key>& input_keys,
696689
MutableColumns& key_columns, const uint32_t num_rows) override {
697-
// In any hash key value, column values to be read start just after the bitmap, if it exists.
698690
size_t pos = 0;
699-
for (size_t i = 0; i < key_columns.size(); ++i) {
700-
if (key_columns[i]->is_nullable()) {
701-
pos = get_bitmap_size(key_columns.size());
702-
break;
703-
}
704-
}
705691

706692
for (size_t i = 0; i < key_columns.size(); ++i) {
707693
size_t size = key_sizes[i];
@@ -720,11 +706,8 @@ struct MethodKeysFixed : public MethodBase<TData> {
720706

721707
// The current column is nullable. Check if the value of the
722708
// corresponding key is nullable. Update the null map accordingly.
723-
size_t bucket = i / BITSIZE;
724-
size_t offset = i % BITSIZE;
725709
for (size_t j = 0; j < num_rows; j++) {
726-
nullmap[j] =
727-
(reinterpret_cast<const UInt8*>(&input_keys[j])[bucket] >> offset) & 1;
710+
nullmap[j] = (*reinterpret_cast<const UInt8*>(&input_keys[j]) >> i) & 1;
728711
}
729712
} else {
730713
// key_columns is a mutable element. However, when accessed through get_raw_data().data,

0 commit comments

Comments
 (0)