optimize fixed size column

This commit is contained in:
liuneng 2023-06-28 15:04:43 +08:00 committed by LiuNeng
parent 035dbdaf22
commit f96b9b7512
2 changed files with 23 additions and 4 deletions

View File

@ -140,9 +140,9 @@ StringRef ColumnNullable::serializeValueIntoArena(size_t n, Arena & arena, char
const bool is_null = arr[n];
static constexpr auto s = sizeof(arr[0]);
char * pos;
if (const ColumnString * string_col = checkAndGetColumn<ColumnString>(getNestedColumn()))
if (isString(nested_column->getDataType()))
{
auto data = string_col->getDataAt(n);
auto data = nested_column->getDataAt(n);
size_t string_size = data.size + 1;
auto memory_size = is_null ? s : s + sizeof(string_size) + string_size;
pos = arena.allocContinue(memory_size, begin);
@ -154,6 +154,19 @@ StringRef ColumnNullable::serializeValueIntoArena(size_t n, Arena & arena, char
}
return StringRef(pos, memory_size);
}
else if (isNumber(nested_column->getDataType()) || isFixedString(nested_column->getDataType()))
{
auto data = nested_column->getDataAt(n);
auto size = data.size;
auto memory_size = is_null ? s : s + size;
pos = arena.allocContinue(memory_size, begin);
memcpy(pos, &arr[n], s);
if (!is_null)
{
memcpy(pos + s, data.data, size);
}
return StringRef(pos, memory_size);
}
else
{
pos = arena.allocContinue(s, begin);

View File

@ -11,13 +11,19 @@
key_string1 Nullable(String),
key_string2 Nullable(String),
key_string3 Nullable(String),
key_int64_1 Nullable(Int64),
key_int64_2 Nullable(Int64),
key_int64_3 Nullable(Int64),
key_int64_4 Nullable(Int64),
key_int64_5 Nullable(Int64),
m1 Int64,
m2 Int64,
m2 Int64
)
ENGINE = Memory
</create_query>
<fill_query>insert into t_nullable select ['aaaaaa','bbaaaa','ccaaaa','ddaaaa'][number % 101 + 1], ['aa','bb','cc','dd'][number % 100 + 1], ['aa','bb','cc','dd'][number % 102 + 1], number%6000+1, number%5000+2 from numbers_mt(20000000)</fill_query>
<fill_query>insert into t_nullable select ['aaaaaa','bbaaaa','ccaaaa','ddaaaa'][number % 101 + 1], ['aa','bb','cc','dd'][number % 100 + 1], ['aa','bb','cc','dd'][number % 102 + 1], number%1000+1, number%1000+2, number%1000+3, number%1000+4,number%1000+5, number%6000+1, number%5000+2 from numbers_mt(20000000)</fill_query>
<query>select key_string1,key_string2,key_string3, min(m1) from t_nullable group by key_string1,key_string2,key_string3</query>
<query>select key_string3,key_int64_1,key_int64_2, min(m1) from t_nullable group by key_string3,key_int64_1,key_int64_2</query>
<drop_query>drop table if exists t_nullable</drop_query>
</test>