更新时间:2024-01-22 GMT+08:00
分享

HashFunc函数

  • hash_array(anyarray)

    描述:数组哈希,将数组的元素通过哈希函数得到结果,并返回合并结果。

    参数:数据类型为anyarray。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hash_array(ARRAY[[1,2,3],[1,2,3]]);
     hash_array 
    ------------
     -382888479
    (1 row)
    
  • hash_group(key)

    描述:流引擎(由于规格变更,当前版本已经不再支持本特性,请不要使用)中,该函数可将Group Clause中的各列计算为一个hash值。

    参数:key为Group Clause中各列的值。

    返回值类型:32位hash值

    示例:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    按照步骤依次执行。
    openGauss=# CREATE TABLE tt(a int, b int,c int,d int);
    NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using 'a' as the distribution column by default.
    HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
    CREATE TABLE
    openGauss=# select * from tt;
     a | b | c | d 
    ---+---+---+---
    (0 rows)
    
    openGauss=# insert into tt values(1,2,3,4);
    INSERT 0 1
    openGauss=# select * from tt;
     a | b | c | d 
    ---+---+---+---
     1 | 2 | 3 | 4
    (1 row)
    
    openGauss=# insert into tt values(5,6,7,8);
    INSERT 0 1
    openGauss=# select * from tt;
     a | b | c | d 
    ---+---+---+---
     1 | 2 | 3 | 4
     5 | 6 | 7 | 8
    (2 rows)
    
    openGauss=# select hash_group(a,b) from tt where a=1 and b=2;
     hash_group 
    ------------
      990882385
    (1 row)
    
  • hash_numeric(numeric)

    描述:计算Numeric类型的数据的hash值。

    参数:Numeric类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hash_numeric(30);
     hash_numeric 
    --------------
       -282860963
    (1 row)
    
  • hash_range(anyrange)

    描述:计算range的哈希值。

    参数:anyrange类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hash_range(numrange(1.1,2.2));
     hash_range 
    ------------
      683508754
    (1 row)
    
  • hashbpchar(character)

    描述:计算bpchar的哈希值。

    参数:character类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hashbpchar('hello');
     hashbpchar  
    -------------
     -1870292951
    (1 row)
    
  • hashchar(char)

    描述:char和布尔数据转换为哈希值。

    参数:char类型的数据或者bool类型的数据。

    返回值类型:integer

    示例:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    openGauss=# select hashbpchar('hello');
     hashbpchar  
    -------------
     -1870292951
    (1 row)
    
    openGauss=# select hashchar('true');
      hashchar  
    ------------
     1686226652
    (1 row)
    
  • hashenum(anyenum)

    描述:枚举类型转哈希值。

    参数:anyenum类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    6
    7
    openGauss=# CREATE TYPE b1 AS ENUM('good', 'bad', 'ugly');
    CREATE TYPE
    openGauss=# call hashenum('good'::b1);
      hashenum  
    ------------
     1821213359
    (1 row)
    
  • hashfloat4(real)

    描述:float4转哈希值。

    参数:real类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hashfloat4(12.1234);
     hashfloat4 
    ------------
     1398514061
    (1 row)
    
  • hashfloat8(double precision)

    描述:float8转哈希值。

    参数:double precision类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hashfloat8(123456.1234);
     hashfloat8 
    ------------
     1673665593
    (1 row)
    
  • hashinet(inet)

    描述:支持inet / cidr上的哈希索引的功能。返回传入inet的hash值。

    参数:inet类型的数据。

    返回值类型:integer

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hashinet('127.0.0.1'::inet);
      hashinet   
    -------------
     -1435793109
    (1 row)
    
  • hashint1(tinyint)

    描述:INT1转哈希值。

    参数:tinyint类型的数据。

    返回值类型:uint32

    示例:

    1
    2
    3
    4
    5
    openGauss=# select hashint1(20);
      hashint1   
    -------------
     -2014641093
    (1 row)
    
  • hashint2(smallint)

    描述:INT2转哈希值。

    参数:smallint类型的数据。

    返回值类型:uint32

    示例:

    openGauss=# select hashint2(20000);
      hashint2  
    ------------
     -863179081
    (1 row)
分享:

    相关文档

    相关产品