Need to put @Index even when I marked with @Column(unique=true) ?
I have a property that will be used frequently to retrieve the entity and wanted to make it an index column on the database. So this property is already marked with @Column(unique=true), do I need to put @Index?
thanks
Most databases do implement
UNIQUEconstraints using aUNIQUE INDEX, but they aren’t required to and aUNIQUEconstraint does not necessarily give you the benefits of an index. In theory, a constraint would not be considered by the query planner whereas an index would be.That said, in the particular case of MySQL, it seems that a
UNIQUEconstraint and aUNIQUE INDEXare “synonymous”.But you should confirm that by checking the query plan.