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.

强调我的

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...