【发布时间】:2021-05-10 19:41:50
【问题描述】:
在 postgres 中,有一个基于 hash 的分区。但是postgres 并没有清楚地解释如何计算给定列值的散列值。
我搜索了 Postgres 文档,但一无所获。除了一些邮箱帖子,还有人提到hashtext()内部功能。有没有人知道用于散列值的实际函数(以及进一步使用模运算符)的任何信息?我的意思是 postgres 如何散列一个值,将其转换为 uint64 以进行最终的模运算。
更新:
通过阅读 postgres 源代码,我发现分区函数在尝试查找给定哈希的 uint64 值时使用这样的方法:
/*
* 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
【问题讨论】:
-
这个问题完全清楚。它应该重新打开。
标签: c postgresql