加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在postgresql gist索引类型中使用uuid?

发布时间:2020-12-13 16:18:25 所属栏目:百科 来源:网络整理
导读:我不能直接使用uist和gist索引 CREATE INDEX idx_leaderboads_values_gist ON leaderboard_entry USING gist (id_leaderboard,value); 我收到了这个错误: ERROR: data type uuid has no default operator class for access method “gist” HINT: You must
我不能直接使用uist和gist索引
CREATE INDEX idx_leaderboads_values_gist
  ON leaderboard_entry
  USING gist
  (id_leaderboard,value);

我收到了这个错误:

ERROR: data type uuid has no default operator class for access method
“gist”

HINT: You must specify an operator class for the index or define a
default operator class for the data type.

Postgres 10或更新

btree_gist现在也涵盖了数据类型uuid,如Paul commented.(以及其他一些数据类型,非常类似于枚举类型.)

现在您需要做的是:每个数据库安装一次扩展:

CREATE EXTENSION btree_gist;

然后你的索引应该工作.

有关:

> Exclusion constraint on a bitstring column with bitwise AND operator
> Creating multicolumn index in PostgreSQL,containing both scalar and array columns

Postgres 9.6或更高版本

(原始答案.)
通常我建议使用附加模块btree_gist,但uuid型不在其中.

理论上,由于UUID是128位数量(per documentation),因此最有效的方法是将其转换为两个bigint或float8以用于索引.但是这些演员阵容都没有在标准的Postgres中定义.

我找到了stab in that direction in the pqsql-hackers list,但似乎没有成功.

剩下的选项是文本表示的函数GiST索引:

CREATE INDEX idx_leaderboads_values_gist
ON leaderboard_entry USING gist (id_leaderboard,cast("value" AS text));

要使用此功能索引,查询必须与该表达式匹配.您可以在查询中使用简写“value”:: text(但不能在索引定义中使用,而不添加更多括号).

旁白:不要使用值作为列名,它是reserved word in standard SQL.

问题是:为什么需要GiST索引.最好的解决方案取决于目标.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读