> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 哈希函数文档

# 哈希函数

哈希函数可用于以确定性的伪随机方式打乱元素顺序。

simhash 是一种哈希函数，对于接近 (相似) 的参数会返回接近的哈希值。

大多数哈希函数都接受任意数量、任意类型的参数。

<Note>
  NULL 的哈希值为 NULL。要获取 Nullable 列的非 NULL 哈希值，请将其包装在 tuple 中：

  ```sql theme={null}
  SELECT cityHash64(tuple(NULL))
  ```
</Note>

<Note>
  要计算整个表内容的哈希值，请使用 `sum(cityHash64(tuple(*)))` (或其他哈希函数) 。`tuple` 可确保包含 NULL 值的行不会被跳过。`sum` 可确保行的顺序不会影响结果。
</Note>

{/*AUTOGENERATED_START*/}

<div id="BLAKE3">
  ## BLAKE3
</div>

在 v22.10.0 中引入

计算 BLAKE3 哈希字符串，并以 FixedString 返回结果字节集。
该加密哈希函数通过 BLAKE3 Rust 库集成到 ClickHouse 中。
该函数速度很快，与 SHA-2 相比，性能大约快两倍，同时生成的哈希长度与 SHA-256 相同。
它将 BLAKE3 哈希作为类型为 FixedString(32) 的字节数组返回。

**语法**

```sql theme={null}
BLAKE3(message)
```

**参数**

* `message` — 要进行哈希运算的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回输入字符串的 32 字节 BLAKE3 哈希值，类型为定长字符串。[`FixedString(32)`](/zh/reference/data-types/fixedstring)

**示例**

**hash**

```sql title=Query theme={null}
SELECT hex(BLAKE3('ABC'))
```

```response title=Response theme={null}
┌─hex(BLAKE3('ABC'))───────────────────────────────────────────────┐
│ D1717274597CF0289694F75D96D444B992A096F1AFD8E7BBFA6EBB1D360FEDFC │
└──────────────────────────────────────────────────────────────────┘
```

<div id="MD4">
  ## MD4
</div>

引入版本：v21.11.0

计算给定字符串的 MD4 哈希。

**语法**

```sql theme={null}
MD4(s)
```

**参数**

* `s` — 要计算哈希的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 MD4 哈希值，格式为定长字符串。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(MD4('abc'));
```

```response title=Response theme={null}
┌─hex(MD4('abc'))──────────────────┐
│ A448017AAF21D8525FC10AE87AA6729D │
└──────────────────────────────────┘
```

<div id="MD5">
  ## MD5
</div>

引入于：v1.1.0

计算给定字符串的 MD5 哈希值。

**语法**

```sql theme={null}
MD5(s)
```

**参数**

* `s` — 待计算哈希的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

以定长字符串形式返回给定输入字符串的 MD5 哈希值。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(MD5('abc'));
```

```response title=Response theme={null}
┌─hex(MD5('abc'))──────────────────┐
│ 900150983CD24FB0D6963F7D28E17F72 │
└──────────────────────────────────┘
```

<div id="RIPEMD160">
  ## RIPEMD160
</div>

引入版本：v24.10.0

计算给定字符串的 RIPEMD-160 哈希。

**语法**

```sql theme={null}
RIPEMD160(s)
```

**参数**

* `s` — 要计算哈希的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 RIPEMD160 哈希值，类型为定长字符串。[`FixedString(20)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'));
```

```response title=Response theme={null}
┌─HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'))─┐
│ 37F332F68DB77BD9D7EDD4969571AD671CF9DD3B                      │
└───────────────────────────────────────────────────────────────┘
```

<div id="SHA1">
  ## SHA1
</div>

引入版本：v1.1.0

计算给定字符串的 SHA1 哈希值。

**语法**

```sql theme={null}
SHA1(s)
```

**参数**

* `s` — 要进行哈希计算的输入字符串 [`String`](/zh/reference/data-types/string)

**返回值**

以定长字符串形式返回给定输入字符串的 SHA1 哈希值。[`FixedString(20)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(SHA1('abc'));
```

```response title=Response theme={null}
┌─hex(SHA1('abc'))─────────────────────────┐
│ A9993E364706816ABA3E25717850C26C9CD0D89D │
└──────────────────────────────────────────┘
```

<div id="SHA224">
  ## SHA224
</div>

引入版本：v1.1.0

计算给定字符串的 SHA224 哈希值。

**语法**

```sql theme={null}
SHA224(s)
```

**参数**

* `s` — 要哈希的输入值。[`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 SHA224 哈希值，类型为定长字符串。[`FixedString(28)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(SHA224('abc'));
```

```response title=Response theme={null}
┌─hex(SHA224('abc'))───────────────────────────────────────┐
│ 23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7 │
└──────────────────────────────────────────────────────────┘
```

<div id="SHA256">
  ## SHA256
</div>

Introduced in: v1.1.0

计算给定字符串的 SHA256 哈希值。

**语法**

```sql theme={null}
SHA256(s)
```

**参数**

* `s` — 要计算哈希的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 SHA256 哈希，类型为定长字符串。[`FixedString(32)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(SHA256('abc'));
```

```response title=Response theme={null}
┌─hex(SHA256('abc'))───────────────────────────────────────────────┐
│ BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD │
└──────────────────────────────────────────────────────────────────┘
```

<div id="SHA384">
  ## SHA384
</div>

引入版本：v1.1.0

计算给定字符串的 SHA384 哈希值。

**语法**

```sql theme={null}
SHA384(s)
```

**参数**

* `s` — 要进行哈希计算的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 SHA384 哈希值，类型为定长字符串。[`FixedString(48)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(SHA384('abc'));
```

```response title=Response theme={null}
┌─hex(SHA384('abc'))───────────────────────────────────────────────────────────────────────────────┐
│ CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7 │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<div id="SHA512">
  ## SHA512
</div>

引入于：v1.1.0

计算给定字符串的 SHA512 哈希值。

**语法**

```sql theme={null}
SHA512(s)
```

**参数**

* `s` — 要哈希的输入字符串 [`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 SHA512 哈希值，类型为定长字符串。[`FixedString(64)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(SHA512('abc'));
```

```response title=Response theme={null}
┌─hex(SHA512('abc'))───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<div id="SHA512_256">
  ## SHA512\_256
</div>

引入版本：v1.1.0

计算给定字符串的 SHA512\_256 哈希值。

**语法**

```sql theme={null}
SHA512_256(s)
```

**参数**

* `s` — 要计算哈希的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回给定输入字符串的 SHA512\_256 哈希值，类型为定长字符串。[`FixedString(32)`](/zh/reference/data-types/fixedstring)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT HEX(SHA512_256('abc'));
```

```response title=Response theme={null}
┌─hex(SHA512_256('abc'))───────────────────────────────────────────┐
│ 53048E2681941EF99B2E29B76B4C7DABE4C2D0C634FC6D46E0E2F13107E7AF23 │
└──────────────────────────────────────────────────────────────────┘
```

<div id="URLHash">
  ## URLHash
</div>

引入版本：v1.1.0

一种快速、质量较好的非加密哈希函数，用于对经过某种规范化处理后从 URL 得到的字符串计算哈希值。

该哈希函数有两种模式：

| Mode              | Description                                                                       |
| ----------------- | --------------------------------------------------------------------------------- |
| `URLHash(url)`    | 基于字符串计算哈希值；如果末尾存在 `/`、`?` 或 `#`，则会先去掉其中之一。                                        |
| `URLHash(url, N)` | 基于 URL 层级中直到第 N 级的字符串计算哈希值；如果末尾存在 `/`、`?` 或 `#`，则会先去掉其中之一。级别与 `URLHierarchy` 中相同。 |

**语法**

```sql theme={null}
URLHash(url[, N])
```

**参数**

* `url` — 要计算哈希的 URL 字符串。[`String`](/zh/reference/data-types/string)
* `N` — 可选。URL 层级中的层级。[`(U)Int*`](/zh/reference/data-types/int-uint)

**返回值**

返回 `url` 的哈希计算结果。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT URLHash('https://www.clickhouse.com')
```

```response title=Response theme={null}
┌─URLHash('htt⋯house.com')─┐
│     13614512636072854701 │
└──────────────────────────┘
```

**指定层级的 url 哈希值**

```sql title=Query theme={null}
SELECT URLHash('https://www.clickhouse.com/docs', 0);
SELECT URLHash('https://www.clickhouse.com/docs', 1);
```

```response title=Response theme={null}
-- https://www.clickhouse.com 的哈希值
┌─URLHash('htt⋯m/docs', 0)─┐
│     13614512636072854701 │
└──────────────────────────┘
-- https://www.clickhouse.com/docs 的哈希值
┌─URLHash('htt⋯m/docs', 1)─┐
│     13167253331440520598 │
└──────────────────────────┘
```

<div id="cityHash64">
  ## cityHash64
</div>

引入版本：v1.1.0

生成一个 64 位 [CityHash](https://github.com/google/cityhash) 哈希值。

这是一种快速的非加密哈希函数。
对于字符串参数，它使用 CityHash 算法；对于其他数据类型的参数，则使用特定于实现的快速非加密哈希函数。
该函数使用 CityHash 组合器来生成最终结果。

<Info>
  Google 在将 CityHash 引入 ClickHouse 后修改了该算法。
  换句话说，ClickHouse 的 cityHash64 与 Google 上游的 CityHash 现在会产生不同的结果。
  ClickHouse 的 cityHash64 对应于 CityHash v1.0.2。
</Info>

<Note>
  对于参数类型不同但输入值相同的情况，计算得到的哈希值可能相同。
  例如，这会影响不同位宽的整数类型、数据相同的具名和非具名 `Tuple`，以及数据相同的 `Map` 和对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
cityHash64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的可变数量输入参数。([`Any`](/zh/reference/data-types))

**返回值**

返回根据输入参数计算出的哈希值。([`UInt64`](/zh/reference/data-types/int-uint))

**示例**

**调用示例**

```sql title=Query theme={null}
SELECT cityHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS CityHash, toTypeName(CityHash) AS type;
```

```response title=Response theme={null}
┌─────────────CityHash─┬─type───┐
│ 12072650598913549138 │ UInt64 │
└──────────────────────┴────────┘
```

**计算整个表的校验和，精确到行的顺序**

```sql title=Query theme={null}
CREATE TABLE users (
    id UInt32,
    name String,
    age UInt8,
    city String
)
ENGINE = MergeTree
ORDER BY tuple();

INSERT INTO users VALUES
(1, 'Alice', 25, 'New York'),
(2, 'Bob', 30, 'London'),
(3, 'Charlie', 35, 'Tokyo');

SELECT groupBitXor(cityHash64(*)) FROM users;
```

```response title=Response theme={null}
┌─groupBitXor(⋯age, city))─┐
│     11639977218258521182 │
└──────────────────────────┘
```

<div id="farmFingerprint64">
  ## farmFingerprint64
</div>

引入版本：v20.12.0

使用 `Fingerprint64` 方法生成 64 位的 [FarmHash](https://github.com/google/farmhash) 值。

<Tip>
  相比 [`farmHash64`](#farmHash64)，为了获得稳定且可移植的值，优先使用 `farmFingerprint64`。
</Tip>

<Note>
  对于参数类型不同但输入值相同的情况，计算出的哈希值可能相同。
  例如，这会影响不同大小的整数类型、具有相同数据的具名和非具名 `Tuple`，以及具有相同数据的 `Map` 和对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
farmFingerprint64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希值的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算得出的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT farmFingerprint64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmFingerprint, toTypeName(FarmFingerprint) AS type;
```

```response title=Response theme={null}
┌─────FarmFingerprint─┬─type───┐
│ 5752020380710916328 │ UInt64 │
└─────────────────────┴────────┘
```

<div id="farmHash64">
  ## farmHash64
</div>

引入版本：v1.1.0

使用 `Hash64` 方法生成 64 位 [FarmHash](https://github.com/google/farmhash) 值。

<Tip>
  如需稳定且可移植的值，建议优先使用 [`farmFingerprint64`](#farmFingerprint64)。
</Tip>

<Note>
  对于参数类型不同但输入值相同的情况，计算得到的哈希值可能相同。
  例如，不同位宽的整数类型、数据相同的具名与非具名 `Tuple`，以及数据相同的 `Map` 与对应的 `Array(Tuple(key, value))` 类型都会受到影响。
</Note>

**语法**

```sql theme={null}
farmHash64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 要计算哈希的输入参数，数量可变。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT farmHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmHash, toTypeName(FarmHash) AS type;
```

```response title=Response theme={null}
┌─────────────FarmHash─┬─type───┐
│ 18125596431186471178 │ UInt64 │
└──────────────────────┴────────┘
```

<div id="gccMurmurHash">
  ## gccMurmurHash
</div>

引入版本：v20.1.0

使用与 [GCC](https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/libstdc%2B%2B-v3/include/bits/functional_hash.h#L191) 相同的 seed，计算输入值的 64 位 [MurmurHash2](https://github.com/aappleby/smhasher) 哈希值。

它在 Clang 和 GCC 的构建之间具有可移植性。

**语法**

```sql theme={null}
gccMurmurHash(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 要计算哈希的可变数量参数。[`Any`](/zh/reference/data-types)

**返回值**

返回输入参数计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT
    gccMurmurHash(1, 2, 3) AS res1,
    gccMurmurHash(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2)))) AS res2
```

```response title=Response theme={null}
┌─────────────────res1─┬────────────────res2─┐
│ 12384823029245979431 │ 1188926775431157506 │
└──────────────────────┴─────────────────────┘
```

<div id="halfMD5">
  ## halfMD5
</div>

引入于：v1.1.0

将所有输入参数都[解释为](/zh/reference/functions/regular-functions/type-conversion-functions#reinterpretAsString)字符串，并分别计算其 MD5 哈希值。然后将这些哈希组合起来，取结果字符串哈希值的前 8 个字节，并按大端字节序将其解释为 [UInt64](/zh/reference/data-types/int-uint)。该函数相对较慢 (每个处理器核心每秒可处理 500 万个短字符串) 。

建议改用 [`sipHash64`](#sipHash64) 函数。

该函数接受数量可变的输入参数。
参数可以是任意受支持的数据类型。
对于某些数据类型，即使参数类型不同，相同的值计算出的哈希值也可能相同 (例如不同大小的整数、包含相同数据的命名和未命名 Tuple，以及包含相同数据的 Map 和对应的 Array(Tuple(key, value)) 类型) 。

**语法**

```sql theme={null}
halfMD5(arg1[, arg2, ..., argN])
```

**参数**

* `arg1[, arg2, ..., argN]` — 用于计算哈希的数量可变的参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据给定输入参数计算得出的一半 MD5 哈希值，结果以大端字节序的 `UInt64` 形式表示。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT HEX(halfMD5('abc', 'cde', 'fgh'));
```

```response title=Response theme={null}
┌─hex(halfMD5('abc', 'cde', 'fgh'))─┐
│ 2C9506B7374CFAF4                  │
└───────────────────────────────────┘
```

<div id="hiveHash">
  ## hiveHash
</div>

引入版本：v20.1.0

根据字符串计算 “HiveHash”。
它实际上就是将符号位清零后的 [`JavaHash`](#javaHash)。
在 3.0 之前的版本中，[Apache Hive](https://en.wikipedia.org/wiki/Apache_Hive) 使用此函数。

<Warning>
  此哈希函数性能较差。
  仅当其他系统已使用此算法，且你需要计算相同结果时，才应使用它。
</Warning>

**语法**

```sql theme={null}
hiveHash(arg)
```

**参数**

* `arg` — 要计算哈希的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回输入字符串的“hive 哈希”计算结果。[`Int32`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hiveHash('Hello, world!');
```

```response title=Response theme={null}
┌─hiveHash('Hello, world!')─┐
│                 267439093 │
└───────────────────────────┘
```

<div id="icebergHash">
  ## icebergHash
</div>

首次引入于：v25.5.0

实现了 Iceberg [哈希转换](https://iceberg.apache.org/spec/#appendix-b-32-bit-hash-requirements) 的逻辑

**语法**

```sql theme={null}
icebergHash(value)
```

**参数**

* `value` — 要计算哈希的源值，类型可以是 [`Integer`](/zh/reference/data-types/int-uint)、[`Bool`](/zh/reference/data-types/boolean)、[`Decimal`](/zh/reference/data-types/decimal)、[`Float*`](/zh/reference/data-types/float)、[`String`](/zh/reference/data-types/string)、[`FixedString`](/zh/reference/data-types/fixedstring)、[`UUID`](/zh/reference/data-types/uuid)、[`Date`](/zh/reference/data-types/date)、[`Time`](/zh/reference/data-types/time) 或 [`DateTime`](/zh/reference/data-types/datetime)

**返回值**

返回一个 32 位的 Murmur3 哈希值 (x86 变体) ，种子为 0，类型为 [`Int32`](/zh/reference/data-types/int-uint)

**示例**

**示例**

```sql title=Query theme={null}
SELECT icebergHash(1.0 :: Float32)
```

```response title=Response theme={null}
-142385009
```

<div id="intHash32">
  ## intHash32
</div>

引入版本：v1.1.0

计算整数的 32 位哈希值。

该哈希函数速度较快，但不是加密哈希函数。

**语法**

```sql theme={null}
intHash32(arg)
```

**参数**

* `arg` — 要计算哈希值的整数。[`(U)Int*`](/zh/reference/data-types/int-uint)

**返回值**

返回输入整数计算得到的 32 位哈希值 [`UInt32`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT intHash32(42);
```

```response title=Response theme={null}
┌─intHash32(42)─┐
│    1228623923 │
└───────────────┘
```

<div id="intHash64">
  ## intHash64
</div>

引入版本：v1.1.0

计算整数的 64 位哈希值。

该哈希函数速度较快 (甚至比 [`intHash32`](#intHash32) 还快) ，但不是加密哈希函数。

**语法**

```sql theme={null}
intHash64(int)
```

**参数**

* `int` — 要计算哈希的整数。[`(U)Int*`](/zh/reference/data-types/int-uint)

**返回值**

64 位哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT intHash64(42);
```

```response title=Response theme={null}
┌────────intHash64(42)─┐
│ 11490350930367293593 │
└──────────────────────┘
```

<div id="javaHash">
  ## javaHash
</div>

引入版本：v20.1.0

根据以下类型的值计算 JavaHash：

* [String](http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/String.java#l1452),
* [Byte](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Byte.java#l405),
* [Short](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Short.java#l410),
* [Integer](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Integer.java#l959),
* [Long](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Long.java#l1060).

<Warning>
  此哈希函数性能较差。
  仅当其他系统已在使用该算法，且你需要计算相同结果时，才应使用它。
</Warning>

<Note>
  Java 仅支持计算有符号整数的哈希，
  因此，如果你想计算无符号整数的哈希，必须先将它们转换为相应的有符号 ClickHouse 类型。
</Note>

**语法**

```sql theme={null}
javaHash(arg)
```

**参数**

* `arg` — 要进行哈希计算的输入值。[`Any`](/zh/reference/data-types)

**返回值**

返回 `arg` 的计算哈希值 [`Int32`](/zh/reference/data-types/int-uint)

**示例**

**使用示例 1**

```sql title=Query theme={null}
SELECT javaHash(toInt32(123));
```

```response title=Response theme={null}
┌─javaHash(toInt32(123))─┐
│               123      │
└────────────────────────┘
```

**使用示例 2**

```sql title=Query theme={null}
SELECT javaHash('Hello, world!');
```

```response title=Response theme={null}
┌─javaHash('Hello, world!')─┐
│               -1880044555 │
└───────────────────────────┘
```

<div id="javaHashUTF16LE">
  ## javaHashUTF16LE
</div>

引入版本：v20.1.0

根据一个字符串计算 [JavaHash](http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/String.java#l1452)，假定其中包含的是表示 UTF-16LE 编码字符串的字节。

**语法**

```sql theme={null}
javaHashUTF16LE(arg)
```

**参数**

* `arg` — 采用 UTF-16LE 编码的字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回该 UTF-16LE 编码字符串的哈希值。[`Int32`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'));
```

```response title=Response theme={null}
┌─javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'))─┐
│                                                      3556498 │
└──────────────────────────────────────────────────────────────┘
```

<div id="jumpConsistentHash">
  ## jumpConsistentHash
</div>

版本引入：v1.1.0

计算一个整数的 [跳跃一致性哈希](https://arxiv.org/pdf/1406.2294.pdf)。

**语法**

```sql theme={null}
jumpConsistentHash(key, buckets)
```

**参数**

* `key` — 输入键。[`UInt64`](/zh/reference/data-types/int-uint)
* `buckets` — 桶的数量。[`Int32`](/zh/reference/data-types/int-uint)

**返回值**

返回计算出的哈希值。[`Int32`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT jumpConsistentHash(256, 4)
```

```response title=Response theme={null}
┌─jumpConsistentHash(256, 4)─┐
│                          3 │
└────────────────────────────┘
```

<div id="kafkaMurmurHash">
  ## kafkaMurmurHash
</div>

引入版本：v23.4.0

使用与 [Kafka](https://github.com/apache/kafka/blob/461c5cfe056db0951d9b74f5adc45973670404d7/clients/src/main/java/org/apache/kafka/common/utils/Utils.java#L482) 相同的种子值，计算输入值的 32 位 [MurmurHash2](https://github.com/aappleby/smhasher) 哈希，并去除最高位，以兼容 [Default Partitioner](https://github.com/apache/kafka/blob/139f7709bd3f5926901a21e55043388728ccca78/clients/src/main/java/org/apache/kafka/clients/producer/internals/BuiltInPartitioner.java#L328)。

**语法**

```sql theme={null}
kafkaMurmurHash(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的可变数量的参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算得到的哈希值。[`UInt32`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT
    kafkaMurmurHash('foobar') AS res1,
    kafkaMurmurHash(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS res2
```

```response title=Response theme={null}
┌───────res1─┬─────res2─┐
│ 1357151166 │ 85479775 │
└────────────┴──────────┘
```

<div id="keccak256">
  ## keccak256
</div>

引入版本：v25.4.0

计算给定字符串的 Keccak-256 加密哈希值。
这种哈希函数广泛用于区块链应用，尤其是以太坊。

**语法**

```sql theme={null}
keccak256(message)
```

**参数**

* `message` — 要进行哈希计算的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回输入字符串的 32 字节 Keccak-256 哈希，类型为定长字符串。[`FixedString(32)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(keccak256('hello'))
```

```response title=Response theme={null}
┌─hex(keccak256('hello'))──────────────────────────────────────────┐
│ 1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8 │
└──────────────────────────────────────────────────────────────────┘
```

<div id="kostikConsistentHash">
  ## kostikConsistentHash
</div>

Introduced in：v22.6.0

这是 Konstantin 'Kostik' Oblakov 提出的一种时间和空间复杂度均为 O(1) 的一致性哈希算法。
仅在 `n <= 32768` 时才高效。

**Syntax**

```sql theme={null}
kostikConsistentHash(input, n)
```

**别名**: `yandexConsistentHash`

**参数**

* `input` — 一个整型键。[`UInt64`](/zh/reference/data-types/int-uint)
* `n` — 桶的数量。[`UInt16`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。[`UInt16`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT kostikConsistentHash(16045690984833335023, 2);
```

```response title=Response theme={null}
┌─kostikConsistentHash(16045690984833335023, 2)─┐
│                                             1 │
└───────────────────────────────────────────────┘
```

<div id="metroHash64">
  ## metroHash64
</div>

引入版本：v1.1.0

生成一个 64 位的 [MetroHash](http://www.jandrewrogers.com/2015/05/27/metrohash/) 哈希值。

<Note>
  对于不同参数类型中相同的输入值，计算出的哈希值可能相同。
  例如，这会影响不同位宽的整数类型、数据相同的具名和非具名 `Tuple`，以及数据相同的 `Map` 和对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
metroHash64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算出的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT metroHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MetroHash, toTypeName(MetroHash) AS type;
```

```response title=Response theme={null}
┌────────────MetroHash─┬─type───┐
│ 14235658766382344533 │ UInt64 │
└──────────────────────┴────────┘
```

<div id="murmurHash2_32">
  ## murmurHash2\_32
</div>

Introduced in：v18.5.0

计算输入值的 [MurmurHash2](https://github.com/aappleby/smhasher) 哈希值。

<Note>
  对于数值相同但参数类型不同的输入，计算得到的哈希值可能相同。
  例如，这会影响不同位宽的整数类型、数据相同的具名和非具名 `Tuple`，以及数据相同的 `Map` 和对应的 `Array(Tuple(key, value))` 类型。
</Note>

**Syntax**

```sql theme={null}
murmurHash2_32(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的可变数量的输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算出的哈希值。[`UInt32`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT murmurHash2_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type;
```

```response title=Response theme={null}
┌─MurmurHash2─┬─type───┐
│  3681770635 │ UInt32 │
└─────────────┴────────┘
```

<div id="murmurHash2_64">
  ## murmurHash2\_64
</div>

引入版本：v18.10.0

计算输入值的 [MurmurHash2](https://github.com/aappleby/smhasher) 哈希值。

<Note>
  对于参数类型不同但输入值相同的情况，计算出的哈希值可能相同。
  例如，这会影响不同位宽的整数类型、数据相同的具名和非具名 `Tuple`，以及数据相同的 `Map` 与对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
murmurHash2_64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的输入参数，数量可变。[`Any`](/zh/reference/data-types)

**返回值**

返回输入参数计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT murmurHash2_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type;
```

```response title=Response theme={null}
┌──────────MurmurHash2─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘
```

<div id="murmurHash3_128">
  ## murmurHash3\_128
</div>

引入版本：v18.10.0

计算输入值的 128 位 [MurmurHash3](https://github.com/aappleby/smhasher) 哈希值。

**语法**

```sql theme={null}
murmurHash3_128(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回输入参数计算得出的 128 位 `MurmurHash3` 哈希值。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(murmurHash3_128('foo', 'foo', 'foo'));
```

```response title=Response theme={null}
┌─hex(murmurHash3_128('foo', 'foo', 'foo'))─┐
│ F8F7AD9B6CD4CF117A71E277E2EC2931          │
└───────────────────────────────────────────┘
```

<div id="murmurHash3_32">
  ## murmurHash3\_32
</div>

引入版本：v18.10.0

生成 [MurmurHash3](https://github.com/aappleby/smhasher) 哈希值。

<Note>
  对于 argument 类型不同但输入值相同的情况，计算出的哈希值可能会相同。
  例如，这会影响不同大小的整数类型、数据相同的具名和非具名 `Tuple`，以及数据相同的 `Map` 与对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
murmurHash3_32(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的数量可变的输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算得到的哈希值。[`UInt32`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT murmurHash3_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
```

```response title=Response theme={null}
┌─MurmurHash3─┬─type───┐
│     2152717 │ UInt32 │
└─────────────┴────────┘
```

<div id="murmurHash3_64">
  ## murmurHash3\_64
</div>

引入版本：v18.10.0

计算输入值的 [MurmurHash3](https://github.com/aappleby/smhasher) 哈希。

<Note>
  对于参数类型不同但输入值相同的情况，计算得到的哈希值可能相同。
  例如，这会影响不同位宽的整数类型、数据相同的具名和非具名 `Tuple`，以及数据相同的 `Map` 与对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
murmurHash3_64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回输入参数计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT murmurHash3_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
```

```response title=Response theme={null}
┌──────────MurmurHash3─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘
```

<div id="ngramMinHash">
  ## ngramMinHash
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，计算每个 n-gram 的哈希值，并返回包含这些哈希值的 Tuple。
使用 `hashnum` 个最小哈希值计算最小哈希，使用 `hashnum` 个最大哈希值计算最大哈希。
该函数区分大小写。

可结合 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 用于检测半重复字符串。
对于两个字符串，如果返回的哈希值对两者都相同，则这两个字符串相同。

**语法**

```sql theme={null}
ngramMinHash(string[, ngramsize, hashnum])
```

**参数**

* `string` — 要计算哈希的字符串。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希值 (最小值和最大值) 的 Tuple。[`Tuple`](/zh/reference/data-types/tuple)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT ngramMinHash('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,9054248444481805918) │
└────────────────────────────────────────────┘
```

<div id="ngramMinHashArg">
  ## ngramMinHashArg
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，并返回基于相同输入由 [`ngramMinHash`](#ngramMinHash) 函数计算出的哈希值最小和最大的 n-gram。
该函数区分大小写。

**语法**

```sql theme={null}
ngramMinHashArg(string[, ngramsize, hashnum])
```

**参数**

* `string` — 要计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的长度，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个 Tuple，其中包含两个 Tuple，每个 Tuple 各含 `hashnum` 个 n-gram。[`Tuple(String)`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramMinHashArg('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('Hou','lic','ick','ous','ckH','Cli')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

<div id="ngramMinHashArgCaseInsensitive">
  ## ngramMinHashArgCaseInsensitive
</div>

引入于：v21.1.0

将 ASCII 字符串拆分为由 `ngramsize` 个符号组成的 n-grams，并返回在相同输入下由 [`ngramMinHashCaseInsensitive`](#ngramMinHashCaseInsensitive) 函数计算得到的哈希值最小和最大的 n-grams。
该函数不区分大小写。

**语法**

```sql theme={null}
ngramMinHashArgCaseInsensitive(string[, ngramsize, hashnum])
```

**参数**

* `string` — 要计算哈希的字符串。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个由两个 Tuple 组成的 Tuple，每个 Tuple 包含 `hashnum` 个 n-gram。[`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramMinHashArgCaseInsensitive('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','kHo','use','Cli'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

<div id="ngramMinHashArgCaseInsensitiveUTF8">
  ## ngramMinHashArgCaseInsensitiveUTF8
</div>

引入于：v21.1.0

将 UTF-8 字符串按 `ngramsize` 个符号拆分为 n-grams，并返回使用相同输入由 ngramMinHashCaseInsensitiveUTF8 函数计算出的哈希值最小和最大的 n-grams。
该函数不区分大小写。

**语法**

```sql theme={null}
ngramMinHashArgCaseInsensitiveUTF8(string[, ngramsize, hashnum])
```

**参数**

* `string` — 要计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的长度，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个 Tuple，其中包含两个 Tuple，每个 Tuple 各含有 `hashnum` 个 n-gram。[`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT ngramMinHashArgCaseInsensitiveUTF8('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ckH','ous','ick','lic','kHo','use'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

<div id="ngramMinHashArgUTF8">
  ## ngramMinHashArgUTF8
</div>

引入版本：v21.1.0

将一个 UTF-8 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，并返回在相同输入下由 `ngramMinHashUTF8` 函数计算得到的哈希值最小和最大的 n-gram。
该函数区分大小写。

**语法**

```sql theme={null}
ngramMinHashArgUTF8(string[, ngramsize, hashnum])
```

**参数**

* `string` — 要计算哈希的字符串。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为从 `1` 到 `25` 的任意值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为从 `1` 到 `25` 的任意值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个元组，其中包含两个元组，每个元组各有 `hashnum` 个 n-gram。[`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramMinHashArgUTF8('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('kHo','Hou','lic','ick','ous','ckH')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

<div id="ngramMinHashCaseInsensitive">
  ## ngramMinHashCaseInsensitive
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，计算每个 n-gram 的哈希值，并返回包含这些哈希值的 Tuple。
使用 `hashnum` 个最小哈希值计算最小哈希，使用 `hashnum` 个最大哈希值计算最大哈希。
该函数不区分大小写。

可与 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 配合使用，以检测近似重复字符串。
对于两个字符串，如果两者返回的哈希值相同，则这两个字符串相同。

**语法**

```sql theme={null}
ngramMinHashCaseInsensitive(string[, ngramsize, hashnum])
```

**参数**

* `string` — String。[String](/zh/reference/data-types/string)。- `ngramsize` — n-gram 的大小。可选。可能的值：`1` 到 `25` 之间的任意数值。默认值：`3`。[UInt8](/zh/reference/data-types/int-uint)。- `hashnum` — 用于计算结果的最小哈希值和最大哈希值的数量。可选。可能的值：`1` 到 `25` 之间的任意数值。默认值：`6`。[UInt8](/zh/reference/data-types/int-uint)。

**返回值**

包含两个哈希值 (最小值和最大值) 的 Tuple。[Tuple](/zh/reference/data-types/tuple)([UInt64](/zh/reference/data-types/int-uint), [UInt64](/zh/reference/data-types/int-uint))。[`Tuple`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramMinHashCaseInsensitive('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────┐
│ (2106263556442004574,13203602793651726206) │
└────────────────────────────────────────────┘
```

<div id="ngramMinHashCaseInsensitiveUTF8">
  ## ngramMinHashCaseInsensitiveUTF8
</div>

引入版本：v21.1.0

将 UTF-8 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，计算每个 n-gram 的哈希值，并返回一个包含这些哈希值的 Tuple。
使用 `hashnum` 个最小哈希值来计算最小哈希，使用 `hashnum` 个最大哈希值来计算最大哈希。
此函数不区分大小写。

可结合 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 用于检测半重复字符串。
对于两个字符串，如果两者返回的哈希值相同，则这两个字符串相同。

**语法**

```sql theme={null}
ngramMinHashCaseInsensitiveUTF8(string [, ngramsize, hashnum])
```

**参数**

* `string` — 用于计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小和最大哈希值的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希值 (最小值和最大值) 的 Tuple。[`Tuple`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramMinHashCaseInsensitiveUTF8('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple───────────────────────────────────────┐
│ (12493625717655877135,13203602793651726206) │
└─────────────────────────────────────────────┘
```

<div id="ngramMinHashUTF8">
  ## ngramMinHashUTF8
</div>

引入版本：v21.1.0

将 UTF-8 字符串按 `ngramsize` 个符号切分为 n-gram，计算每个 n-gram 的哈希值，并返回包含这些哈希值的 Tuple。
使用 `hashnum` 个最小哈希值计算最小哈希，使用 `hashnum` 个最大哈希值计算最大哈希。
该函数区分大小写。

可与 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 配合使用，以检测半重复字符串。
对于两个字符串，如果两者返回的哈希值相同，则这两个字符串相同。

**语法**

```sql theme={null}
ngramMinHashUTF8(string[, ngramsize, hashnum])
```

**参数**

* `string` — 要计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为 `1` 到 `25` 的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希值 (最小值和最大值) 的 Tuple。[`Tuple`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramMinHashUTF8('ClickHouse') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,6742163577938632877) │
└────────────────────────────────────────────┘
```

<div id="ngramSimHash">
  ## ngramSimHash
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，并返回这些 n-gram 的 `simhash`。

可结合 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 用于检测近似重复字符串。
两个字符串计算得到的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这两个字符串越可能相同。

**语法**

```sql theme={null}
ngramSimHash(string[, ngramsize])
```

**参数**

* `string` — 用于计算区分大小写 `simhash` 的字符串。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回输入字符串计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramSimHash('ClickHouse') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 1627567969 │
└────────────┘
```

<div id="ngramSimHashCaseInsensitive">
  ## ngramSimHashCaseInsensitive
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分为由 `ngramsize` 个符号组成的 n-gram，并返回该 n-gram 的 `simhash`。
它不区分大小写。

可结合 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 用于检测半重复字符串。
两个字符串计算得到的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这些字符串就越可能相同。

**语法**

```sql theme={null}
ngramSimHashCaseInsensitive(string[, ngramsize])
```

**参数**

* `string` — 用于计算不区分大小写的 `simhash` 的字符串。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

哈希值。[UInt64](/zh/reference/data-types/int-uint)。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramSimHashCaseInsensitive('ClickHouse') AS Hash;
```

```response title=Response theme={null}
┌──────Hash─┐
│ 562180645 │
└───────────┘
```

<div id="ngramSimHashCaseInsensitiveUTF8">
  ## ngramSimHashCaseInsensitiveUTF8
</div>

引入版本：v21.1.0

将 UTF-8 字符串按 `ngramsize` 个符号切分为 n-gram，并返回这些 n-gram 的 `simhash`。
该函数不区分大小写。

可结合 [bitHammingDistance](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 用于检测半重复字符串。两个字符串计算出的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这些字符串就越可能相同。

**语法**

```sql theme={null}
ngramSimHashCaseInsensitiveUTF8(string[, ngramsize])
```

**参数**

* `string` — 用于计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可以是从 `1` 到 `25` 的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramSimHashCaseInsensitiveUTF8('ClickHouse') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 1636742693 │
└────────────┘
```

<div id="ngramSimHashUTF8">
  ## ngramSimHashUTF8
</div>

引入版本：v21.1.0

将一个 UTF-8 编码的字符串按 `ngramsize` 个符号切分为 n-grams，并返回这些 n-gram 的 `simhash`。
该函数区分大小写。

可结合 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 用于检测近似重复字符串。
两个字符串计算得到的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这些字符串就越有可能相同。

**语法**

```sql theme={null}
ngramSimHashUTF8(string[, ngramsize])
```

**参数**

* `string` — 要计算其哈希值的字符串。[`String`](/zh/reference/data-types/string)
* `ngramsize` — 可选。n-gram 的大小，可以是从 `1` 到 `25` 的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT ngramSimHashUTF8('ClickHouse') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 1628157797 │
└────────────┘
```

<div id="sipHash128">
  ## sipHash128
</div>

引入版本：v1.1.0

与 [`sipHash64`](#sipHash64) 类似，但会生成 128 位哈希值，即最终的异或折叠状态会一直处理到 128 位。

<Tip>
  **新项目请使用 sipHash128Reference**

  这个 128 位变体与参考实现不同，且强度更弱。
  之所以保留这个版本，是因为编写它时，SipHash 还没有官方的 128 位扩展。
  建议新项目使用 [`sipHash128Reference`](#sipHash128Reference)。
</Tip>

**语法**

```sql theme={null}
sipHash128(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希值的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回一个 128 位的 `SipHash` 哈希值。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(sipHash128('foo', '\x01', 3));
```

```response title=Response theme={null}
┌─hex(sipHash128('foo', '', 3))────┐
│ 9DE516A64A414D4B1B609415E4523F24 │
└──────────────────────────────────┘
```

<div id="sipHash128Keyed">
  ## sipHash128Keyed
</div>

引入版本：v23.2.0

与 [`sipHash128`](#sipHash128) 相同，但会额外接受一个显式指定的密钥参数，而不是使用固定密钥。

<Tip>
  **新项目请使用 sipHash128ReferenceKeyed**

  这个 128 位变体与参考实现不同，而且安全性更弱。
  之所以保留这个版本，是因为在编写它时，SipHash 还没有官方的 128 位扩展。
  新项目应优先使用 [`sipHash128ReferenceKeyed`](#sipHash128ReferenceKeyed)。
</Tip>

**语法**

```sql theme={null}
sipHash128Keyed((k0, k1), [arg1, arg2, ...])
```

**参数**

* `(k0, k1)` — 由两个 UInt64 值组成、表示键的元组。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)
* `arg1[, arg2, ...]` — 用于计算哈希的数量可变的输入参数。[`Any`](/zh/reference/data-types)

**返回值**

类型为 [FixedString(16)](/zh/reference/data-types/fixedstring) 的 128 位 `SipHash` 哈希值。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(sipHash128Keyed((506097522914230528, 1084818905618843912),'foo', '\x01', 3));
```

```response title=Response theme={null}
┌─hex(sipHash128Keyed((506097522914230528, 1084818905618843912), 'foo', '', 3))─┐
│ B8467F65C8B4CFD9A5F8BD733917D9BF                                              │
└───────────────────────────────────────────────────────────────────────────────┘
```

<div id="sipHash128Reference">
  ## sipHash128Reference
</div>

引入版本：v23.2.0

与 [`sipHash128`](/zh/reference/functions/regular-functions/hash-functions#sipHash128) 类似，但实现了由 SipHash 原作者提出的 128 位算法。

**语法**

```sql theme={null}
sipHash128Reference(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 用于计算哈希值的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算出的 128 位 `SipHash` 哈希值。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(sipHash128Reference('foo', '', 3));
```

```response title=Response theme={null}
┌─hex(sipHash128Reference('foo', '', 3))─┐
│ 4D1BE1A22D7F5933C0873E1698426260       │
└────────────────────────────────────────┘
```

<div id="sipHash128ReferenceKeyed">
  ## sipHash128ReferenceKeyed
</div>

引入版本：v23.2.0

与 [`sipHash128Reference`](#sipHash128Reference) 相同，但会额外接受一个显式指定的密钥参数，而不是使用固定密钥。

**语法**

```sql theme={null}
sipHash128ReferenceKeyed((k0, k1), arg1[, arg2, ...])
```

**参数**

* `(k0, k1)` — 由两个值组成、表示键的 Tuple。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)
* `arg1[, arg2, ...]` — 用于计算哈希的可变数量输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算得出的 128 位 `SipHash` 哈希值。[`FixedString(16)`](/zh/reference/data-types/fixedstring)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(sipHash128Reference('foo', '', 3));
```

```response title=Response theme={null}
┌─hex(sipHash128Reference('foo', '', 3))─┐
│ 4D1BE1A22D7F5933C0873E1698426260       │
└────────────────────────────────────────┘
```

<div id="sipHash64">
  ## sipHash64
</div>

引入版本：v1.1.0

生成 64 位的 [SipHash](https://en.wikipedia.org/wiki/SipHash) 哈希值。

这是一种加密哈希函数。它的运行速度至少比 [`MD5`](#MD5) 哈希函数快 3 倍。

该函数会将所有输入参数都[解释](/zh/reference/functions/regular-functions/type-conversion-functions#reinterpretAsString)为字符串，并分别计算每个参数的哈希值。
然后，它会使用以下算法组合这些哈希值：

1. 将第一个和第二个哈希值拼接为一个数组，并对其进行哈希计算。
2. 将前一步计算出的哈希值与第三个输入参数的哈希值，按类似方式再次进行哈希计算。
3. 对原始输入中其余所有哈希值重复这一计算过程。

<Note>
  对于参数类型不同但输入值相同的情况，计算出的哈希值可能相同。
  例如，这会影响不同大小的整数类型、具有相同数据的具名和匿名 `Tuple`，以及具有相同数据的 `Map` 和对应的 `Array(Tuple(key, value))` 类型。
</Note>

**语法**

```sql theme={null}
sipHash64(arg1[, arg2, ...])
```

**参数**

* `arg1[, arg2, ...]` — 可变数量的输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入参数计算出的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT sipHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type;
```

```response title=Response theme={null}
┌──────────────SipHash─┬─type───┐
│ 11400366955626497465 │ UInt64 │
└──────────────────────┴────────┘
```

<div id="sipHash64Keyed">
  ## sipHash64Keyed
</div>

引入版本：v23.2.0

与 [`sipHash64`](#sipHash64) 类似，但它额外接受一个显式指定的 `key` 参数，而不是使用固定键。

**语法**

```sql theme={null}
sipHash64Keyed((k0, k1), arg1[,arg2, ...])
```

**参数**

* `(k0, k1)` — 由两个值组成、用于表示键的 Tuple。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)
* `arg1[,arg2, ...]` — 数量可变的输入参数。[`Any`](/zh/reference/data-types)

**返回值**

返回根据输入值计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT sipHash64Keyed((506097522914230528, 1084818905618843912), array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type;
```

```response title=Response theme={null}
┌─────────────SipHash─┬─type───┐
│ 8017656310194184311 │ UInt64 │
└─────────────────────┴────────┘
```

<div id="wordShingleMinHash">
  ## wordShingleMinHash
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分成由 `shinglesize` 个单词组成的多个部分 (分区片段) ，计算每个单词分区片段的哈希值，并返回包含这些哈希值的元组。
使用 `hashnum` 个最小哈希值来计算最小哈希，使用 `hashnum` 个最大哈希值来计算最大哈希。
该函数区分大小写。

可借助 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 检测近似重复字符串。
对于两个字符串，如果两者返回的哈希值相同，则这两个字符串相同。

**语法**

```sql theme={null}
wordShingleMinHash(string[, shinglesize, hashnum])
```

**参数**

* `string` — 要计算其哈希值的字符串。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小和最大哈希值数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希值 (最小值和最大值) 的 Tuple。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHash('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────┐
│ (16452112859864147620,5844417301642981317) │
└────────────────────────────────────────────┘
```

<div id="wordShingleMinHashArg">
  ## wordShingleMinHashArg
</div>

引入版本：v1.1.0

将一个 ASCII 字符串拆分为若干部分 (shingles) ，每个部分包含 `shinglesize` 个单词，并返回在相同输入下由 wordShingleMinHash 函数计算得到的单词哈希值最小和最大的 shingles。
它区分大小写。

**语法**

```sql theme={null}
wordShingleMinHashArg(string[, shinglesize, hashnum])
```

**参数**

* `string` — 要计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，取值范围为 `1` 到 `25`。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，取值范围为 `1` 到 `25`。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个元组的元组，每个元组包含 `hashnum` 个分区片段。[`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashArg('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────────────────────────────────┐
│ (('OLAP','database','analytical'),('online','oriented','processing')) │
└───────────────────────────────────────────────────────────────────────┘
```

<div id="wordShingleMinHashArgCaseInsensitive">
  ## wordShingleMinHashArgCaseInsensitive
</div>

引入版本：v21.1.0

将 ASCII 字符串按每 `shinglesize` 个单词切分为若干部分 (shingles) ，并返回在相同输入下由 [`wordShingleMinHashCaseInsensitive`](#wordShingleMinHashCaseInsensitive) 函数计算出的单词哈希值最小和最大的 shingles。
该函数不区分大小写。

**语法**

```sql theme={null}
wordShingleMinHashArgCaseInsensitive(string[, shinglesize, hashnum])
```

**参数**

* `string` — 要计算哈希的字符串。 [`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，取值范围为 `1` 到 `25`。默认值为 `3`。 [`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小和最大哈希的数量，取值范围为 `1` 到 `25`。默认值为 `6`。 [`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个 Tuple，其中包含两个 Tuple，每个 Tuple 包含 `hashnum` 个分区片段。 [`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashArgCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────────────────────────────────┐
│ (('queries','database','analytical'),('oriented','processing','DBMS')) │
└────────────────────────────────────────────────────────────────────────┘
```

<div id="wordShingleMinHashArgCaseInsensitiveUTF8">
  ## wordShingleMinHashArgCaseInsensitiveUTF8
</div>

引入于：v21.1.0

将 UTF-8 字符串按每 `shinglesize` 个单词切分为若干部分 (shingles) ，并返回在相同输入下由 [`wordShingleMinHashCaseInsensitiveUTF8`](#wordShingleMinHashCaseInsensitiveUTF8) 函数计算出的单词哈希值最小和最大的 shingles。
它不区分大小写。

**语法**

```sql theme={null}
wordShingleMinHashArgCaseInsensitiveUTF8(string[, shinglesize, hashnum])
```

**参数**

* `string` — 要计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。单个分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希值和最大哈希值的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个 Tuple 的 Tuple，每个 Tuple 都包含 `hashnum` 个分区片段。[`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashArgCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────────────────────────────────┐
│ (('queries','database','analytical'),('oriented','processing','DBMS')) │
└────────────────────────────────────────────────────────────────────────┘
```

<div id="wordShingleMinHashArgUTF8">
  ## wordShingleMinHashArgUTF8
</div>

引入版本：v21.1.0

将一个 UTF-8 字符串按每 `shinglesize` 个单词切分为若干部分 (shingles) ，并返回在相同输入下由 [`wordShingleMinHashUTF8`](#wordShingleMinHashUTF8) 函数计算出的单词哈希值最小和最大的 shingles。
它区分大小写。

**语法**

```sql theme={null}
wordShingleMinHashArgUTF8(string[, shinglesize, hashnum])
```

**参数**

* `string` — 要计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个 Tuple，其中包含两个 Tuple，每个 Tuple 包含 `hashnum` 个分区片段。[`Tuple(Tuple(String))`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashArgUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────────────────────────────────┐
│ (('OLAP','database','analytical'),('online','oriented','processing')) │
└───────────────────────────────────────────────────────────────────────┘
```

<div id="wordShingleMinHashCaseInsensitive">
  ## wordShingleMinHashCaseInsensitive
</div>

引入版本：v21.1.0

将 ASCII 字符串按每 `shinglesize` 个单词一组拆分为多个分区片段，计算每个分区片段的哈希值，并返回一个包含这些哈希值的元组。
使用 `hashnum` 个最小哈希值计算最小哈希，使用 `hashnum` 个最大哈希值计算最大哈希。
它不区分大小写。

可用于通过 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 检测近似重复字符串。
对于两个字符串，如果两者返回的哈希值相同，则这两个字符串相同。

**语法**

```sql theme={null}
wordShingleMinHashCaseInsensitive(string[, shinglesize, hashnum])
```

**参数**

* `string` — 用于计算哈希的字符串。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，取值范围为 `1` 到 `25`。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小和最大哈希数量，取值范围为 `1` 到 `25`。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希值的 Tuple，即最小哈希和最大哈希。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────┐
│ (3065874883688416519,1634050779997673240) │
└───────────────────────────────────────────┘
```

<div id="wordShingleMinHashCaseInsensitiveUTF8">
  ## wordShingleMinHashCaseInsensitiveUTF8
</div>

引入版本：v21.1.0

将一个 UTF-8 字符串拆分为由 `shinglesize` 个单词组成的分区片段 (shingles) ，计算每个分区片段的哈希值，并返回一个包含这些哈希的 Tuple。
使用 `hashnum` 个最小哈希值计算最小哈希，使用 `hashnum` 个最大哈希值计算最大哈希。
该函数不区分大小写。

可结合 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 用于检测半重复字符串。
对于两个字符串，如果两者返回的哈希相同，则这两个字符串相同。

**语法**

```sql theme={null}
wordShingleMinHashCaseInsensitiveUTF8(string[, shinglesize, hashnum])
```

**参数**

* `string` — 用于计算哈希的字符串。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，取值范围为 `1` 到 `25`。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小和最大哈希值个数，取值范围为 `1` 到 `25`。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希的 Tuple——最小哈希和最大哈希。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple─────────────────────────────────────┐
│ (3065874883688416519,1634050779997673240) │
└───────────────────────────────────────────┘
```

<div id="wordShingleMinHashUTF8">
  ## wordShingleMinHashUTF8
</div>

引入版本：v21.1.0

将 UTF-8 字符串拆分为由 `shinglesize` 个单词组成的片段 (分区片段) ，计算每个分区片段的哈希值，并返回包含这些哈希值的元组。
使用 `hashnum` 个最小哈希值来计算最小哈希，使用 `hashnum` 个最大哈希值来计算最大哈希。
该函数区分大小写。

可结合 [`tupleHammingDistance`](/zh/reference/functions/regular-functions/tuple-functions#tupleHammingDistance) 使用，以检测近似重复字符串。
对于两个字符串，如果返回的哈希值在两者中都相同，则这两个字符串相同。

**语法**

```sql theme={null}
wordShingleMinHashUTF8(string[, shinglesize, hashnum])
```

**参数**

* `string` — 要计算其哈希值的字符串。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。词分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)
* `hashnum` — 可选。用于计算结果的最小哈希和最大哈希的数量，可为 `1` 到 `25` 之间的任意数值。默认值为 `6`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个哈希值的元组——最小哈希和最大哈希。[`Tuple(UInt64, UInt64)`](/zh/reference/data-types/tuple)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleMinHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```response title=Response theme={null}
┌─Tuple──────────────────────────────────────┐
│ (16452112859864147620,5844417301642981317) │
└────────────────────────────────────────────┘
```

<div id="wordShingleSimHash">
  ## wordShingleSimHash
</div>

引入版本：v21.1.0

将 ASCII 字符串拆分为由 `shinglesize` 个单词组成的分区片段 (shingles) ，并返回这些分区片段的 `simhash`。
该函数区分大小写。

可结合 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 用于检测近似重复字符串。
两个字符串计算得到的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这些字符串就越可能相同。

**语法**

```sql theme={null}
wordShingleSimHash(string[, shinglesize])
```

**参数**

* `string` — 用于计算哈希的 String。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。词分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT wordShingleSimHash('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 2328277067 │
└────────────┘
```

<div id="wordShingleSimHashCaseInsensitive">
  ## wordShingleSimHashCaseInsensitive
</div>

引入版本：v21.1.0

将 ASCII 字符串按 `shinglesize` 个单词拆分为若干部分 (shingles) ，并返回这些词分区片段的 `simhash`。
它不区分大小写。

可与 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 结合使用，以检测近似重复字符串。
两个字符串计算得到的 `simhash` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这些字符串相同的可能性就越大。

**语法**

```sql theme={null}
wordShingleSimHashCaseInsensitive(string[, shinglesize])
```

**参数**

* `string` — 用于计算哈希的 String。 [`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。词分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。 [`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。 [`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleSimHashCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 2194812424 │
└────────────┘
```

<div id="wordShingleSimHashCaseInsensitiveUTF8">
  ## wordShingleSimHashCaseInsensitiveUTF8
</div>

引入版本：v1.1.0

将 UTF-8 编码的字符串拆分为由 `shinglesize` 个单词组成的多个片段 (shingles) ，并返回这些词分区片段的 `simhash`。
此函数不区分大小写。

可与 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 配合使用，以检测近似重复字符串。
两个字符串计算得到的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，它们越有可能相同。

**语法**

```sql theme={null}
wordShingleSimHashCaseInsensitiveUTF8(string[, shinglesize])
```

**参数**

* `string` — 要计算其哈希值的 String。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的长度，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wordShingleSimHashCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 2194812424 │
└────────────┘
```

<div id="wordShingleSimHashUTF8">
  ## wordShingleSimHashUTF8
</div>

引入版本：v21.1.0

将 UTF-8 字符串按每 `shinglesize` 个单词拆分为若干部分 (shingles) ，并返回单词分区片段的 `simhash`。
它区分大小写。

可与 [`bitHammingDistance`](/zh/reference/functions/regular-functions/bit-functions#bitHammingDistance) 结合使用，以检测近似重复字符串。
两个字符串计算得到的 `simhashes` 的 [Hamming 距离](https://en.wikipedia.org/wiki/Hamming_distance) 越小，这两个字符串越可能相同。

**语法**

```sql theme={null}
wordShingleSimHashUTF8(string[, shinglesize])
```

**参数**

* `string` — 要计算哈希值的字符串。[`String`](/zh/reference/data-types/string)
* `shinglesize` — 可选。分区片段的大小，可为 `1` 到 `25` 之间的任意数值。默认值为 `3`。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回计算得到的哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT wordShingleSimHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```response title=Response theme={null}
┌───────Hash─┐
│ 2328277067 │
└────────────┘
```

<div id="wyHash64">
  ## wyHash64
</div>

引入版本：v22.7.0

计算 [wyHash64](https://github.com/wangyi-fudan/wyhash) 的 64 位哈希值。

**语法**

```sql theme={null}
wyHash64(arg)
```

**参数**

* `arg` — 要计算哈希的 String 参数。[`String`](/zh/reference/data-types/string)

**返回值**

返回计算得到的 64 位哈希值 [`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT wyHash64('ClickHouse') AS Hash;
```

```response title=Response theme={null}
12336419557878201794
```

<div id="xxHash32">
  ## xxHash32
</div>

引入版本：v20.1.0

计算字符串的 [xxHash](http://cyan4973.github.io/xxHash/) 哈希值。

64 位版本参见 [`xxHash64`](#xxHash64)

**语法**

```sql theme={null}
xxHash32(arg)
```

**参数**

* `arg` — 要计算哈希值的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回输入字符串的 32 位哈希值。[`UInt32`](/zh/reference/data-types/int-uint)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT xxHash32('Hello, world!');
```

```response title=Response theme={null}
┌─xxHash32('Hello, world!')─┐
│                 834093149 │
└───────────────────────────┘
```

<div id="xxHash64">
  ## xxHash64
</div>

引入版本：v20.1.0

计算字符串的 [xxHash](http://cyan4973.github.io/xxHash/) 哈希值。

32 位版本请参见 [`xxHash32`](#xxHash32)

**语法**

```sql theme={null}
xxHash64(arg)
```

**参数**

* `arg` — 要计算哈希值的输入字符串。[`String`](/zh/reference/data-types/string)

**返回值**

返回输入字符串的 64 位哈希值。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT xxHash64('Hello, world!');
```

```response title=Response theme={null}
┌─xxHash64('Hello, world!')─┐
│      17691043854468224118 │
└───────────────────────────┘
```

<div id="xxh3">
  ## xxh3
</div>

引入版本：v22.12.0

计算 [XXH3](https://github.com/Cyan4973/xxHash) 的 64 位哈希值。

**语法**

```sql theme={null}
xxh3(expr)
```

**参数**

* `expr` — 任意数据类型的表达式列表。[`Any`](/zh/reference/data-types)

**返回值**

返回计算出的 64 位 `xxh3` 哈希值 [`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT xxh3('ClickHouse')
```

```response title=Response theme={null}
18009318874338624809
```

<div id="xxh3_128">
  ## xxh3\_128
</div>

引入版本：v26.2.0

计算 [XXH3](https://github.com/Cyan4973/xxHash) 的 128 位哈希值。

**语法**

```sql theme={null}
xxh3_128(expr)
```

**参数**

* `expr` — 任意数据类型的表达式列表。[`Any`](/zh/reference/data-types)

**返回值**

返回计算出的 128 位 `xxh3` 哈希值 [`UInt128`](/zh/reference/data-types/int-uint)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT hex(xxh3_128('ClickHouse'))
```

```response title=Response theme={null}
3A038784C52804B4DBA43A038784C528
```
