Skip to main content

CityHash

ClickHouse uses one of previous versions of CityHash from Google.

info

CityHash has changed the algorithm after we have added it into ClickHouse.

CityHash documentation specifically notes that the user should not rely to specific hash values and should not save it anywhere or use it as sharding key.

But as we exposed this function to the user, we had to fix the version of CityHash (to 1.0.2). And now we guarantee that the behaviour of CityHash functions available in SQL will not change.

— Alexey Milovidov

Note

Current version of Google's CityHash differs from ClickHouse cityHash64 variant.

Don't use farmHash64 to get Google's CityHash value! FarmHash is a successor to CityHash, but they are not fully compatible.

StringClickHouse64CityHash64FarmHash64
Moscow1250790149629287863859927100784533574095992710078453357409
How can you write a big system without C++? -Paul Glick623794531165004562574929116295744250411716470977470720228

Also see Introducing CityHash for description and reasoning behind creation. TL;DR non-cryptographic hash that is faster than MurmurHash, but more complex.

Implementations

Go

You can use go-faster/city Go package that implements both variants.