I am using postgresql.
In each table, uuid is set as the primary key in the "id" column.
At this time, in some conditional clause When using "id" and "name" as conditions,
Is a composite index of "id" and "name" ["unique"] meaningful?
Since the "id" is already used as a unique key, I think the "name" behind it is meaningless.
If this is the case, is there no need for a composite index for all unique columns?
Thank you!
[Edit]
Postgresql version : v9.1
[I did]
I created two indexes "id" with "name" composite unique index and only "id" unique index.
And if I look at the query with "id" and "name" as conditions and the query with "id" as the condition as execution plans,
I noticed that the two execution plans use different indexes.
Yes, that additional constraint is meaningless: if id
is unique by virtue of being the primary key, the combination of id
and name
is unique as well.
The need for this conceptually unnecessary unique constraint arises because a foreign key has to reference a primary key or unique constraints that contains exactly the targeted rows. Otherwise it might not be clear which of several constraints is referenced by a certain foreign key.