diff --git a/dbms/include/DB/Interpreters/AggregationCommon.h b/dbms/include/DB/Interpreters/AggregationCommon.h index ffb8dc219e6..7247d89e107 100644 --- a/dbms/include/DB/Interpreters/AggregationCommon.h +++ b/dbms/include/DB/Interpreters/AggregationCommon.h @@ -131,7 +131,17 @@ static inline T ALWAYS_INLINE packFixed( for (size_t j = 0; j < keys_size; ++j) { - bool is_null = has_bitmap && (bitmap[j / 8] & (UINT8_C(1) << (j % 8))); + bool is_null; + + if (!has_bitmap) + is_null = false; + else + { + size_t bucket = j / 8; + size_t off = j % 8; + is_null = ((bitmap[bucket] >> off) & 1) == 1; + } + if (is_null) continue; diff --git a/dbms/include/DB/Interpreters/Aggregator.h b/dbms/include/DB/Interpreters/Aggregator.h index 66af3f46273..44833944bc6 100644 --- a/dbms/include/DB/Interpreters/Aggregator.h +++ b/dbms/include/DB/Interpreters/Aggregator.h @@ -289,7 +289,6 @@ protected: const auto & nullable_col = static_cast(*col); actual_columns.push_back(nullable_col.getNestedColumn().get()); null_maps.push_back(nullable_col.getNullValuesByteMap().get()); - has_nullable_columns = true; } else { @@ -333,7 +332,6 @@ protected: private: ConstColumnPlainPtrs actual_columns; ConstColumnPlainPtrs null_maps; - bool has_nullable_columns = false; }; /// Case where nullable keys are not supported. @@ -422,7 +420,7 @@ struct AggregationMethodKeysFixed { static constexpr auto bitmap_size = has_nullable_keys ? std::tuple_size>::value : 0; /// In any hash key value, column values to be read start just after the bitmap, if it exists. - size_t offset = bitmap_size; + size_t pos = bitmap_size; for (size_t i = 0; i < keys_size; ++i) { @@ -449,7 +447,7 @@ struct AggregationMethodKeysFixed /// corresponding key is nullable. Update the null map accordingly. size_t bucket = i / 8; size_t offset = i % 8; - bool val = (reinterpret_cast(&value.first)[bucket] >> offset) & 1; + UInt8 val = (reinterpret_cast(&value.first)[bucket] >> offset) & 1; null_map->insert(val); is_null = val == 1; } @@ -461,8 +459,8 @@ struct AggregationMethodKeysFixed else { size_t size = key_sizes[i]; - observed_column->insertData(reinterpret_cast(&value.first) + offset, size); - offset += size; + observed_column->insertData(reinterpret_cast(&value.first) + pos, size); + pos += size; } } } diff --git a/dbms/src/Functions/FunctionsArray.cpp b/dbms/src/Functions/FunctionsArray.cpp index 33fe70bb1f3..76fb61a9eec 100644 --- a/dbms/src/Functions/FunctionsArray.cpp +++ b/dbms/src/Functions/FunctionsArray.cpp @@ -1599,7 +1599,11 @@ bool FunctionArrayUniq::execute128bit( { const auto & null_map = static_cast(*null_maps[i]).getData(); if (null_map[j] == 1) - bitmap[i / 8] |= UINT8_C(1) << (i % 8); + { + size_t bucket = i / 8; + size_t offset = i % 8; + bitmap[bucket] |= UInt8(1) << offset; + } } } set.insert(packFixed(j, count, columns, key_sizes, bitmap)); @@ -1909,7 +1913,11 @@ bool FunctionArrayEnumerateUniq::execute128bit( { const auto & null_map = static_cast(*null_maps[i]).getData(); if (null_map[j] == 1) - bitmap[i / 8] |= UINT8_C(1) << (i % 8); + { + size_t bucket = i / 8; + size_t offset = i % 8; + bitmap[bucket] |= UInt8(1) << offset; + } } } res_values[j] = ++indices[packFixed(j, count, columns, key_sizes, bitmap)];