使用场景:通常为计算 uv

一、准备测试数据表

create table test_distinct (

    id UInt32

) ENGINE = Memory;

insert into test_distinct values

(1),(1),(1),(2)(2),(2),(2),(2),(3),(4),(4),(4),(5),(6),(7),(8),(7),(6),(8),(8);

二、根据ID进行去重

在Mysql 的常规写法为

select countdistinct id ) from test_distinct;

CK提供的去重函数

1、精确

  • uniqExact(expr) 支持各种数据类型
  • groupBitmap(expr) 仅支持整数去重复,效率非常高

2、非精确

  • uniq(expr) 精度在 99% 以上
  • uniqHLL12(expr) 效率更高,但是精度不如 uniq

支持亿级数据去重

ck写法:

select uniq(id) from test_distinct; ---非精确

select uniqExact(id) from test_distinct;  ----精确

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐