For the complete documentation index, see llms.txt. This page is also available as Markdown.

XXH32

Compute a fast 32-bit xxHash. XXH32 returns the XXH32 hash of a text value as a 32-bit unsigned integer.

XXH32 was added in MariaDB 13.1.

Syntax

XXH32(expr)

Description

XXH32 returns a fast, non-cryptographic xxHash of a text value as a 32-bit number (INT UNSIGNED). It's useful for checksums, change detection, and grouping or bucketing rows. For a 64-bit result, use XXH3().

The argument must be a text value: a string, BLOB/TEXT, JSON, ENUM, or SET. Numbers, dates, and other non-text values are rejected with an error; CAST() them to a string first.

Hashing NULL returns NULL. Hashing an empty string returns 0.

The result depends on the collation, not on the raw bytes. Values that count as equal under the collation hash to the same number (for example, 'abc' and 'ABC' under a case-insensitive collation). The same text in a different character set or collation gives a different number.

Predicting the partition for KEY partitioning

The same XXH32 algorithm is available as a KEY partitioning algorithm (PARTITION BY KEY ALGORITHM=XXH32). For a table partitioned on a single column, the partition a value lands in is MOD(XXH32(value), number_of_partitions) — handy for knowing where a row will go, or for partition pruning. The collation rule above still applies: the value must use the column's collation to predict correctly.

This shortcut holds only for a plain, single-column KEY. It doesn't apply to LINEAR KEY (unless the number of partitions is a power of two), to multi-column keys, or to NULL values (the server places those itself).

XXH3 is the 64-bit variant. The XXH64() and XXH128() functions are not part of this release.

Examples

The result depends on the session collation, so a bare literal reproduces only under the same collation (the result above is for the default utf8mb4_uca1400_ai_ci). For a byte-exact hash that doesn't depend on collation, hash the binary form:

NULL and the empty string:

Equal values under a case-insensitive collation hash to the same number:

A non-text argument is rejected:

See Also

This page is licensed: CC BY-SA / Gnu FDL

spinner

Last updated

Was this helpful?