如果我在varchar上应用哈希索引,postgres 10将使用什么算法来散列值?它会是MD5吗? Murmur3? FNV-1?我无法在任何地方找到此文件。
答案 0 :(得分:3)
您可以使用此查询找到正确的函数:
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
,并在内部从hash_any
调用backend/access/hash/hashfunc.c
。
此功能的评论告诉您更多:
/*
* 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.
*/