- When a database index is created for a unique constraint on a field or multiple indexes are created for a multiple field unique constraint, are those same indexes able to be used for efficiency gains when querying for objects, much in the same way any other database index is used? My guess is that the indexes created for unique constraints are the same as ones created for efficiency gains, and the unique constraint itself is something additional, but I’m not well versed in databases.
- Is it ever possible to break a unique constraint, including a multiple field constraint (e.g. field_a and field_b are unique together) in any way through long transactions and high concurrency, etc? Or, does a unique constraint offer 100% protection.
When a database index is created for a unique constraint on a field or
Share
As to question 1:
YES – these are indexes as any other indexes you define and are used in query plans for example for performance gains… you can define unique indexes without defining a “unique contraint” btw.
As to question 2:
YES – it is a 100% protection as long as the DB engine is is ACID compliant and reliable (i.e. no bugs in this regard) and as long as you don’t temporarily disable the constraint.