On one of my PostgreSQL tables, I have a set of two fields that will be defined as being unique in the table, but will also both be used together when selecting data. Given this, do I only need to define a UNIQUE INDEX, or should I specify an INDEX in addition to the UNIQUE INDEX?
This?
CREATE UNIQUE INDEX mytable_col1_col2_idx ON mytable (col1, col2);
Or this?
CREATE UNIQUE INDEX mytable_col1_col2_uidx ON mytable (col1, col2);
CREATE INDEX mytable_col1_col2_idx ON mytable (col1, col2);
If you have a UNIQUE INDEX then you don’t also need the INDEX – it would be redundant. A UNIQUE INDEX is both a unique constraint and an index that can be used like any other index.
From the documentation:
Emphasis mine.