Merge pull request #31806 from Algunenano/speedup_count

This commit is contained in:
Vladimir C 2021-11-29 10:48:40 +03:00 committed by GitHub
commit 7a356bee44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -203,6 +203,21 @@ public:
data(place).count += !assert_cast<const ColumnNullable &>(*columns[0]).isNullAt(row_num);
}
void addBatchSinglePlace(
size_t batch_size, AggregateDataPtr place, const IColumn ** columns, Arena *, ssize_t if_argument_pos) const override
{
auto & nc = assert_cast<const ColumnNullable &>(*columns[0]);
if (if_argument_pos >= 0)
{
const auto & flags = assert_cast<const ColumnUInt8 &>(*columns[if_argument_pos]).getData();
data(place).count += countBytesInFilterWithNull(flags, nc.getNullMapData().data());
}
else
{
data(place).count += batch_size - countBytesInFilter(nc.getNullMapData().data(), batch_size);
}
}
void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena *) const override
{
data(place).count += data(rhs).count;

View File

@ -4,6 +4,8 @@
<fill_query>INSERT INTO data SELECT number, 1 from numbers(10000000)</fill_query>
<query tag='count_10M' short='1'>SELECT count() FROM data</query>
<query>SELECT count(k) FROM (SELECT k FROM data, numbers(20) _a)</query>
<query>SELECT count(k) FROM (SELECT toNullable(k) as k FROM data, numbers(20) _a)</query>
<drop_query>DROP TABLE IF EXISTS data</drop_query>
</test>

View File

@ -1,3 +1,21 @@
<test>
<query>SELECT countIf(number % 2) FROM numbers(100000000)</query>
<query>
SELECT countIf(key IS NOT NULL)
FROM
(
SELECT materialize(toNullable(1)) AS key
FROM numbers(100000000)
)
</query>
<query>
SELECT countIf(key IS NOT NULL)
FROM
(
SELECT materialize(CAST(NULL, 'Nullable(Int8)')) AS key
FROM numbers(100000000)
)
</query>
</test>