In postgres, there is a partitioning based on hash
. But postgres
does not clearly explains how hashing of the given column's value is calculated.
I have searched through Postgres doc and have found nothing. Except in some mailbox posts, some people mentioned hashtext()
internal function. Does anyone have any info about the actual function used for hashing of value (and further using modulus operator)? I mean how postgres hashes a value, converts it to uint64
to the final modulus operation.
Update:
Reading through postgres source code, I have found partitioning functions use a method like this when they try to find an uint64
value of a given hash:
/*
* DatumGetUInt64
* Returns 64-bit unsigned integer value of a datum.
*
* Note: this macro hides whether int64 is pass by value or by reference.
*/
#ifdef USE_FLOAT8_BYVAL
#define DatumGetUInt64(X) ((uint64) (X))
#else
#define DatumGetUInt64(X) (* ((uint64 *) DatumGetPointer(X)))
#endif