具有唯一约束的 Postgres 哈希索引 [英] Postgres hash index with unique constraint

查看:44
本文介绍了具有唯一约束的 Postgres 哈希索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 Postgres 10 正确支持哈希索引,我想使用哈希索引进行 id 查找(与 btree 相比,哈希索引的大小更小,理论上更快).

With Postgres 10 properly supporting hash index, I would like to use hash index for id lookup (hash index is smaller in size compared to btree and theoretically faster).

我有一张桌子

create table t (id int);
create unique index on t using hash (id);

但我得到了以下信息:

错误:访问方法hash"不支持唯一索引

为什么哈希索引不允许唯一约束?有没有办法绕过这个?

Why does hash index not allow unique constraint? Are there ways to circumvent this?

推荐答案

文档不容置疑:

目前,只有 B-tree 索引可以声明为唯一.

Currently, only B-tree indexes can be declared unique.

有一个关于黑客名单的讨论 最近关于这个,并得出结论,添加允许 UNIQUE 哈希索引的功能并不简单.

There was a discussion on the hackers list about this recently, and it was concluded that it wouldn't be simple to add the capability to allow UNIQUE hash indexes.

这篇关于具有唯一约束的 Postgres 哈希索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆