Skip to content

Commit 56aeb36

Browse files
committed
opt for pack_fixeds
1 parent e3e0590 commit 56aeb36

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <utility>
2323

2424
#include "common/compiler_util.h"
25+
#include "util/simd/bits.h"
2526
#include "vec/columns/column_array.h"
2627
#include "vec/columns/column_nullable.h"
2728
#include "vec/common/arena.h"
@@ -502,42 +503,50 @@ struct MethodKeysFixed : public MethodBase<TData> {
502503
result.clear();
503504
result.resize(row_numbers);
504505

506+
auto* __restrict result_data = reinterpret_cast<char*>(result.data());
507+
505508
size_t offset = 0;
506509
if (bitmap_size > 0) {
507510
for (size_t j = 0; j < nullmap_columns.size(); j++) {
508511
if (!nullmap_columns[j]) {
509512
continue;
510513
}
511-
size_t bucket = j / BITSIZE;
512-
size_t local_offset = j % BITSIZE;
513-
const auto& data =
514+
const auto* __restrict data =
514515
assert_cast<const ColumnUInt8&>(*nullmap_columns[j]).get_data().data();
516+
517+
size_t null_count =
518+
row_numbers - simd::count_zero_num((const int8_t*)data, row_numbers);
519+
if (0 == null_count) {
520+
continue;
521+
}
522+
523+
size_t bucket = j / BITSIZE;
524+
size_t local_offset = j - bucket * BITSIZE;
525+
const auto mask = uint8_t(1 << local_offset);
526+
auto* __restrict current = result_data + bucket;
515527
for (size_t i = 0; i < row_numbers; ++i) {
516-
*((char*)(&result[i]) + bucket) |= data[i] << local_offset;
528+
*(current) |= data[i] * mask;
529+
current += sizeof(T);
517530
}
518531
}
519532
offset += bitmap_size;
520533
}
521534

522535
for (size_t j = 0; j < key_columns.size(); ++j) {
523-
const char* data = key_columns[j]->get_raw_data().data;
536+
const char* __restrict data = key_columns[j]->get_raw_data().data;
524537

525538
auto foo = [&]<typename Fixed>(Fixed zero) {
526539
CHECK_EQ(sizeof(Fixed), key_sizes[j]);
527540
if (!nullmap_columns.empty() && nullmap_columns[j]) {
528-
const auto& nullmap =
541+
const auto* nullmap =
529542
assert_cast<const ColumnUInt8&>(*nullmap_columns[j]).get_data().data();
530-
for (size_t i = 0; i < row_numbers; ++i) {
531-
// make sure null cell is filled by 0x0
532-
memcpy_fixed<Fixed, true>(
533-
(char*)(&result[i]) + offset,
534-
nullmap[i] ? (char*)&zero : data + i * sizeof(Fixed));
535-
}
536-
} else {
537-
for (size_t i = 0; i < row_numbers; ++i) {
538-
memcpy_fixed<Fixed, true>((char*)(&result[i]) + offset,
539-
data + i * sizeof(Fixed));
540-
}
543+
// make sure null cell is filled by 0x0
544+
key_columns[j]->assume_mutable()->replace_column_null_data(nullmap);
545+
}
546+
auto* __restrict current = result_data + offset;
547+
for (size_t i = 0; i < row_numbers; ++i) {
548+
memcpy_fixed<Fixed, true>(current, data + i * sizeof(Fixed));
549+
current += sizeof(T);
541550
}
542551
};
543552

0 commit comments

Comments
 (0)