微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql – 我应该指定INDEX和UNIQUE INDEX吗?

在我的一个Postgresql表中,我有一组两个字段将被定义为在表中是唯一的,但在选择数据时也将一起使用.鉴于此,我只需要定义一个独特的索引,还是应该指定INDEX除了UNIQUE INDEX?

这个?

CREATE UNIQUE INDEX mytable_col1_col2_idx ON mytable (col1,col2);

或这个?

CREATE UNIQUE INDEX mytable_col1_col2_uidx ON mytable (col1,col2);
CREATE INDEX mytable_col1_col2_idx ON mytable (col1,col2);
如果你有一个UNIQUE INDEX,那么你不需要INDEX – 这将是多余的.独特的索引既可以像任何其他索引一样使用唯一约束和索引.

documentation

Note: The preferred way to add a unique constraint to a table is ALTER TABLE … ADD CONSTRAINT. The use of indexes to enforce unique constraints Could be considered an implementation detail that should not be accessed directly. One should,however,be aware that there’s no need to manually create indexes on unique columns; doing so would just duplicate the automatically-created index.

强调我的

原文地址:https://www.jb51.cc/postgresql/192190.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐