* Support bitmap_intersect
Support aggregate function Bitmap Intersect, it is mainly used to take intersection of grouped data.
The function 'bitmap_intersect(expr)' calculates the intersection of bitmap columns and returns a bitmap object.
The defination is following:
FunctionName: bitmap_intersect,
InputType: bitmap,
OutputType: bitmap
The scenario is as follows:
Query which users satisfy the three tags a, b, and c at the same time.
```
select bitmap_to_string(bitmap_intersect(user_id)) from
(
select bitmap_union(user_id) user_id from bitmap_intersect_test
where tag in ('a', 'b', 'c')
group by tag
) a
```
Closed #3552.
* Add docs of bitmap_union and bitmap_intersect
* Support null of bitmap_intersect
1.5 KiB
1.5 KiB
title, language
| title | language |
|---|---|
| bitmap_union | zh-CN |
bitmap_union
description
聚合函数,用于计算分组后的 bitmap 并集。常见使用场景如:计算PV,UV。
Syntax
BITMAP BITMAP_UNION(BITMAP value)
输入一组 bitmap 值,求这一组 bitmap 值的并集,并返回。
example
mysql> select page_id, bitmap_union(user_id) from table group by page_id;
和 bitmap_count 函数组合使用可以求得网页的 PV 数据
mysql> select page_id, bitmap_count(bitmap_union(user_id)) from table group by page_id;
当 user_id 字段为 int 时,上面查询语义等同于
mysql> select page_id, count(distinct user_id) from table group by page_id;
keyword
BITMAP_UNION, BITMAP