在我的一个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 – 这将是多余的.独特的索引既可以像任何其他索引一样使用唯一约束和索引.
原文链接:https://www.f2er.com/postgresql/192190.htmlNote: 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.
强调我的