如果我在 varchar 上应用散列索引,postgres 10 将使用什么算法来散列该值?会是MD5吗?杂音3? FNV-1?我无法在任何地方找到这个记录。
最佳答案
您可以使用此查询找到正确的函数:
SELECT DISTINCT p.amproc
FROM pg_amproc p
JOIN pg_opfamily f ON p.amprocfamily = f.oid
JOIN pg_am a ON f.opfmethod = a.oid
WHERE a.amname = 'hash'
AND p.amproclefttype = 'text'::regtype;
函数是hashtext
,它在内部调用backend/access/hash/hashfunc.c
的hash_any
。
这个函数的注释告诉你更多:
/*
* This hash function was written by Bob Jenkins
* (bob_jenkins@burtleburtle.net), and superficially adapted
* for PostgreSQL by Neil Conway. For more information on this
* hash function, see http://burtleburtle.net/bob/hash/doobs.html,
* or Bob's article in Dr. Dobb's Journal, Sept. 1997.
*
* In the current code, we have adopted Bob's 2006 update of his hash
* function to fetch the data a word at a time when it is suitably aligned.
* This makes for a useful speedup, at the cost of having to maintain
* four code paths (aligned vs unaligned, and little-endian vs big-endian).
* It also uses two separate mixing functions mix() and final(), instead
* of a slower multi-purpose function.
*/
关于postgresql - postgres 10 对 varchars 使用什么哈希算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48553037/