Merge pull request #15034 from amosbird/fff

Improve performance of grouping by single LowCardinality(FixedString)
This commit is contained in:
alexey-milovidov 2020-09-20 19:42:38 +03:00 committed by GitHub
commit 55eb533fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 12 deletions

View File

@ -367,6 +367,14 @@ AggregatedDataVariants::Type Aggregator::chooseAggregationMethod()
throw Exception("Logical error: numeric column has sizeOfField not in 1, 2, 4, 8, 16, 32.", ErrorCodes::LOGICAL_ERROR);
}
if (params.keys_size == 1 && isFixedString(types_removed_nullable[0]))
{
if (has_low_cardinality)
return AggregatedDataVariants::Type::low_cardinality_key_fixed_string;
else
return AggregatedDataVariants::Type::key_fixed_string;
}
/// If all keys fits in N bits, will use hash table with all keys packed (placed contiguously) to single N-bit key.
if (params.keys_size == num_fixed_contiguous_keys)
{
@ -399,14 +407,6 @@ AggregatedDataVariants::Type Aggregator::chooseAggregationMethod()
return AggregatedDataVariants::Type::key_string;
}
if (params.keys_size == 1 && isFixedString(types_removed_nullable[0]))
{
if (has_low_cardinality)
return AggregatedDataVariants::Type::low_cardinality_key_fixed_string;
else
return AggregatedDataVariants::Type::key_fixed_string;
}
return AggregatedDataVariants::Type::serialized;
}

View File

@ -228,7 +228,7 @@ struct AggregationMethodString
static void insertKeyIntoColumns(const StringRef & key, MutableColumns & key_columns, const Sizes &)
{
key_columns[0]->insertData(key.data, key.size);
static_cast<ColumnString *>(key_columns[0].get())->insertData(key.data, key.size);
}
};
@ -254,7 +254,7 @@ struct AggregationMethodStringNoCache
static void insertKeyIntoColumns(const StringRef & key, MutableColumns & key_columns, const Sizes &)
{
key_columns[0]->insertData(key.data, key.size);
static_cast<ColumnString *>(key_columns[0].get())->insertData(key.data, key.size);
}
};
@ -280,7 +280,7 @@ struct AggregationMethodFixedString
static void insertKeyIntoColumns(const StringRef & key, MutableColumns & key_columns, const Sizes &)
{
key_columns[0]->insertData(key.data, key.size);
static_cast<ColumnFixedString *>(key_columns[0].get())->insertData(key.data, key.size);
}
};
@ -305,7 +305,7 @@ struct AggregationMethodFixedStringNoCache
static void insertKeyIntoColumns(const StringRef & key, MutableColumns & key_columns, const Sizes &)
{
key_columns[0]->insertData(key.data, key.size);
static_cast<ColumnFixedString *>(key_columns[0].get())->insertData(key.data, key.size);
}
};

View File

@ -0,0 +1,17 @@
<test max_ignored_relative_change="0.2">
<create_query>DROP TABLE IF EXISTS perf_lc_fixed_str_groupby</create_query>
<create_query>CREATE TABLE perf_lc_fixed_str_groupby(
a LowCardinality(FixedString(14)),
b LowCardinality(FixedString(14))
) ENGINE MergeTree ORDER BY tuple()
</create_query>
<fill_query>
INSERT INTO perf_lc_fixed_str_groupby SELECT ('number key ' || toString(number % 400)) AS a, ('number key ' || toString(number % 20)) AS b FROM numbers(30000000)
</fill_query>
<query short="1">SELECT count() FROM perf_lc_fixed_str_groupby GROUP BY a</query>
<query short="1">SELECT count() FROM perf_lc_fixed_str_groupby GROUP BY b</query>
<drop_query>DROP TABLE IF EXISTS perf_lc_fixed_str_groupby</drop_query>
</test>