阿里云深度优化云数据库 HybridDB for PostgreSQL,除原生 Greenplum Database 功能外,还支持 HyperLogLog,为互联网广告分析及有类似预估分析计算需求的行业提供解决方案,以便于快速预估 PV、UV 等业务指标。
创建 HyperLogLog 插件
执行如下命令,创建 HyperLogLog 插件:
CREATE EXTENSION hll;
基本类型
select hll_add_agg(1::hll_hashval) = hll_add_agg(2::hll_hashval);
select hll_add_agg(1::hll_hashval) || hll_add_agg(2::hll_hashval);
select #hll_add_agg(1::hll_hashval);
select 1::hll_hashval = 2::hll_hashval;
select 1::hll_hashval <> 2::hll_hashval;
select hll_hash_boolean(true);
select hll_hash_integer(1);
select hll_add_agg(1::hll_hashval);
select hll_union(hll_add_agg(1::hll_hashval),hll_add_agg(2::hll_hashval));
select hll_set_defaults(15,5,-1,1);
select hll_print(hll_add_agg(1::hll_hashval));
create table access_date (acc_date date unique, userids hll);
insert into access_date select current_date, hll_add_agg(hll_hash_integer(user_id)) from generate_series(1,10000) t(user_id);
insert into access_date select current_date-1, hll_add_agg(hll_hash_integer(user_id)) from generate_series(5000,20000) t(user_id);
insert into access_date select current_date-2, hll_add_agg(hll_hash_integer(user_id)) from generate_series(9000,40000) t(user_id);
postgres=# select #userids from access_date where acc_date=current_date;
?column?
------------------
9725.85273370708
(1 row)
postgres=# select #userids from access_date where acc_date=current_date-1;
?column?
------------------
14968.6596883279
(1 row)
postgres=# select #userids from access_date where acc_date=current_date-2;
?column?
------------------
29361.5209149911
(1 row)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。