更新时间:2024-04-18 GMT+08:00
分享

精度函数

HLL(HyperLogLog)主要存在三种模式Explicit,Sparse,Full。当数据规模比较小的时候会使用Explicit模式和Sparse模式, 这两种模式在计算结果上基本上没有误差。 随着distinct值越来越多,就会转换成Full模式,但结果也会存在一定误差。下列函数用于查看HLL中精度参数。

hll_schema_version(hll)

描述:查看当前hll中的schema version。

返回值类型:integer

示例:

1
2
3
4
5
SELECT hll_schema_version(hll_empty());
 hll_schema_version 
--------------------
           1
(1 row)

hll_type(hll)

描述:查看当前hll的类型。

返回值类型:integer

示例:

1
2
3
4
5
SELECT hll_type(hll_empty());
 hll_type 
----------
        1
(1 row)

hll_log2m(hll)

描述:查看当前hll的log2m数值,此值会影响最后hll计算distinct误差率,误差率计算公式为:

返回值类型:integer

示例:

1
2
3
4
5
SELECT hll_log2m(hll_empty());
 hll_log2m 
-----------
        11
(1 row)

hll_regwidth(hll)

描述:查看hll数据结构中桶的位数大小。

返回值类型:integer

示例:

1
2
3
4
5
SELECT hll_regwidth(hll_empty());
 hll_regwidth
--------------
            5
(1 row)

hll_expthresh(hll)

描述:得到当前hll中expthresh大小,hll通常会由Explicit模式到Sparse模式再到Full模式,这个过程称为promotion hierarchy策略。可以通过调整expthresh值的大小改变策略,比如expthresh为0的时候就会跳过Explicit模式而直接进入Sparse模式。当显式指定expthresh的取值为1-7之间时,该函数得到的是 2expthresh

返回值类型:record

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT hll_expthresh(hll_empty());
 hll_expthresh 
---------------
 (-1,160)
(1 row)

SELECT hll_expthresh(hll_empty(11,5,3));
 hll_expthresh 
---------------
 (8,8)
(1 row)

hll_sparseon(hll)

描述:是否启用sparse模式,0是关闭,1是开启。

返回值类型:integer

示例:

1
2
3
4
5
SELECT hll_sparseon(hll_empty());
 hll_sparseon
--------------
            1
(1 row)
分享:

    相关文档

    相关产品