postgresql - postgres 10 对 varchars 使用什么哈希算法?

标签 postgresql

如果我在 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.chash_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/

相关文章:

sql - 由于命名冲突无法创建表

PostgreSQL: 导入一些数据后,如果插入有错误 - IntegrityError duplicate key value violates unique constraint "place_country_pkey"

arrays - Ruby PG Gem 使用 TextEncoder::Array 进行 SELECT WHERE fieldname IN exec_params

node.js - 如何在 Node.js 中创建 "private beta"用户队列系统?

php - 如何独立于时区获取所有相同的日期和时间

database - 如何在 PostgreSQL 中将数据库从一台服务器移动到另一台服务器?

postgresql - 如何判断我的 PGSQL 数据库的 autovacuum 是否正在 Windows Server 2003 上运行?

sql-server - 使用 dtsx 包运行功能导入 .mdb 文件 从 SQL Server 转换为 PostgreSQL

ruby-on-rails - PG_SEARCH gem 仅搜索 JSON 的特定列

postgresql - 如何从 Dapper(使用 Npgsql)调用具有混合大小写名称的存储过程?