|
22 | 22 | #include <utility> |
23 | 23 |
|
24 | 24 | #include "common/compiler_util.h" |
| 25 | +#include "util/simd/bits.h" |
25 | 26 | #include "vec/columns/column_array.h" |
26 | 27 | #include "vec/columns/column_nullable.h" |
27 | 28 | #include "vec/common/arena.h" |
@@ -502,42 +503,50 @@ struct MethodKeysFixed : public MethodBase<TData> { |
502 | 503 | result.clear(); |
503 | 504 | result.resize(row_numbers); |
504 | 505 |
|
| 506 | + auto* __restrict result_data = reinterpret_cast<char*>(result.data()); |
| 507 | + |
505 | 508 | size_t offset = 0; |
506 | 509 | if (bitmap_size > 0) { |
507 | 510 | for (size_t j = 0; j < nullmap_columns.size(); j++) { |
508 | 511 | if (!nullmap_columns[j]) { |
509 | 512 | continue; |
510 | 513 | } |
511 | | - size_t bucket = j / BITSIZE; |
512 | | - size_t local_offset = j % BITSIZE; |
513 | | - const auto& data = |
| 514 | + const auto* __restrict data = |
514 | 515 | 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; |
515 | 527 | 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); |
517 | 530 | } |
518 | 531 | } |
519 | 532 | offset += bitmap_size; |
520 | 533 | } |
521 | 534 |
|
522 | 535 | 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; |
524 | 537 |
|
525 | 538 | auto foo = [&]<typename Fixed>(Fixed zero) { |
526 | 539 | CHECK_EQ(sizeof(Fixed), key_sizes[j]); |
527 | 540 | if (!nullmap_columns.empty() && nullmap_columns[j]) { |
528 | | - const auto& nullmap = |
| 541 | + const auto* nullmap = |
529 | 542 | 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); |
541 | 550 | } |
542 | 551 | }; |
543 | 552 |
|
|
0 commit comments