The index are on tuples, ordered sets, of columns, but the UNIQUE constraint or qualifiant for an index is on (unordered) sets of columns.
I have MySQL/MariaDB in mind but my questions certainly applies to other DBMS.
If I have a table T with two columns id1, id2 and two index on this two columns:
INDEX idx_id1_id2 (id1, id2)
INDEX idx_id2_id1 (id2, id1)
and I want to declare to the DBMS that the multi-set on all records of the table T of all couples (value(id1), value(id2)), or equivalently all couples (value(id2), value(id1)), is "UNIQUE" (this multi-set is a set),
I can change
INDEX idx_id1_id2 (id1, id2)
INDEX idx_id2_id1 (id2, id1)
for
UNIQUE INDEX idx_id1_id2 (id1, id2)
INDEX idx_id2_id1 (id2, id1)
But I can also declare :
UNIQUE INDEX idx_id1_id2 (id1, id2)
UNIQUE INDEX idx_id2_id1 (id2, id1)
Is there some DBMS that deduce from
UNIQUE INDEX idx_id1_id2 (id1, id2)
INDEX idx_id2_id1 (id2, id1)
that the second index is also unique?
Is there some DBMS that deduce from
UNIQUE INDEX idx_id1_id2 (id1, id2)
UNIQUE INDEX idx_id2_id1 (id2, id1)
that they don't have to do twice the unicity check on inserting/updating value in the table ?
From a declarative point of view, I prefer
UNIQUE INDEX idx_id1_id2 (id1, id2)
UNIQUE INDEX idx_id2_id1 (id2, id1)
but however there may be a performance penalty on insert/update.
If there is a performance penalty for declaring UNIQUE on many indexes, will it be significant ?
Is there any (significant) performance boost for some queries with the second UNIQUE qualifiant added ?