Hash functions

```
┌──────────MurmurHash2─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘
```

## murmurHash3\_128[​](#murmurHash3_128 "Direct link to murmurHash3_128")

Introduced in: v18.10.0

Computes the 128-bit [MurmurHash3](https://github.com/aappleby/smhasher) hash of the input value.

**Syntax**

```
murmurHash3_128(arg1[, arg2, ...])
```

**Arguments**

- `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed 128-bit `MurmurHash3` hash value of the input arguments. [`FixedString(16)`](/docs/sql-reference/data-types/fixedstring)

**Examples**

**Usage example**

```
SELECT hex(murmurHash3_128('foo', 'foo', 'foo'));
```

```
┌─hex(murmurHash3_128('foo', 'foo', 'foo'))─┐
│ F8F7AD9B6CD4CF117A71E277E2EC2931          │
└───────────────────────────────────────────┘
```

## murmurHash3\_32[​](#murmurHash3_32 "Direct link to murmurHash3_32")

Introduced in: v18.10.0

Produces a [MurmurHash3](https://github.com/aappleby/smhasher) hash value.

Note

The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.

**Syntax**

```
murmurHash3_32(arg1[, arg2, ...])
```

**Arguments**

- `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT murmurHash3_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
```

```
┌─MurmurHash3─┬─type───┐
│     2152717 │ UInt32 │
└─────────────┴────────┘
```

## murmurHash3\_64[​](#murmurHash3_64 "Direct link to murmurHash3_64")

Introduced in: v18.10.0

Computes the [MurmurHash3](https://github.com/aappleby/smhasher) hash of the input value.

Note

The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.

**Syntax**

```
murmurHash3_64(arg1[, arg2, ...])
```

**Arguments**

- `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT murmurHash3_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
```

```
┌──────────MurmurHash3─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘
```

## ngramMinHash[​](#ngramMinHash "Direct link to ngramMinHash")

Introduced in: v21.1.0

Splits a ASCII string into n-grams of `ngramsize` symbols and calculates hash values for each n-gram and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case sensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/docs/sql-reference/functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```
ngramMinHash(string[, ngramsize, hashnum])
```

**Arguments**

- `string` — String for which to compute the hash. [`String`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHash('ClickHouse') AS Tuple;
```

```
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,9054248444481805918) │
└────────────────────────────────────────────┘
```

## ngramMinHashArg[​](#ngramMinHashArg "Direct link to ngramMinHashArg")

Introduced in: v21.1.0

Splits a ASCII string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the [`ngramMinHash`](#ngramMinHash) function with the same input.
It is case sensitive.

**Syntax**

```
ngramMinHashArg(string[, ngramsize, hashnum])
```

**Arguments**

- `string` — String for which to compute the hash. [`String`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(String)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashArg('ClickHouse') AS Tuple;
```

```
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('Hou','lic','ick','ous','ckH','Cli')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

## ngramMinHashArgCaseInsensitive[​](#ngramMinHashArgCaseInsensitive "Direct link to ngramMinHashArgCaseInsensitive")

Introduced in: v21.1.0

Splits a ASCII string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the [`ngramMinHashCaseInsensitive`](#ngramMinHashCaseInsensitive) function with the same input.
It is case insensitive.

**Syntax**

```
ngramMinHashArgCaseInsensitive(string[, ngramsize, hashnum])
```

**Arguments**

- `string` — String for which to compute the hash. [`String`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(Tuple(String))`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashArgCaseInsensitive('ClickHouse') AS Tuple;
```

```
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','kHo','use','Cli'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

## ngramMinHashArgCaseInsensitiveUTF8[​](#ngramMinHashArgCaseInsensitiveUTF8 "Direct link to ngramMinHashArgCaseInsensitiveUTF8")

Introduced in: v21.1.0

Splits a UTF-8 string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashCaseInsensitiveUTF8 function with the same input.
It is case insensitive.

**Syntax**

```
ngramMinHashArgCaseInsensitiveUTF8(string[, ngramsize, hashnum])
```

**Arguments**