Updated on 2023-10-23 GMT+08:00

Hash Function

  • hash_array(anyarray)

    Description: Hashes an array, obtains the result of an array element using the hash function, and returns the combination result.

    Parameter: data of the anyarray type

    Return type: integer

    Example:

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

    Description: Calculates the hash value of each column in the Group Clause in the streaming engine. (Due to specification changes, the current version no longer supports the current feature. Do not use this feature.)

    Parameter: key indicates the value of each column in the Group Clause.

    Return type: 32-bit hash value

    Example:

     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
    Perform the following steps in sequence.
    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)

    Description: Calculates the hash value of numeric data.

    Parameter: data of the numeric type.

    Return type: integer

    Example:

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

    Description: Calculates the hash value of a range.

    Parameter: data of the anyrange type

    Return type: integer

    Example:

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

    Description: Calculates the hash value of bpchar.

    Parameter: data of the character type

    Return type: integer

    Example:

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

    Description: Converts char and Boolean data into hash values.

    Parameter: data of the char or bool type

    Return type: integer

    Example:

     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)

    Description: Converts enumerated values to hash values.

    Parameter: data of the anyenum type

    Return type: integer

    Example:

    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)

    Description: Converts float4 values to hash values.

    Parameter: data of the real type

    Return type: integer

    Example:

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

    Description: Converts float8 values to hash values.

    Parameter: data of the double precision type

    Return type: integer

    Example:

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

    Description: Supports hashing indexes on inet or cidr. Returns the hash value of inet.

    Parameter: data of the inet type

    Return type: integer

    Example:

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

    Description: Converts INT1 values to hash values.

    Parameter: data of the tinyint type

    Return type: uint32

    Example:

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

    Description: Converts INT2 values to hash values.

    Parameter: data of the smallint type

    Return type: uint32

    Example:

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