Suppose a SQL database of "values of series". Each Value
belongs to a Series
, and has a date:
@Entity
class Series { … }
Value {
Series series;
Date date;
…
}
Each value is unique for each combination of series and date, which is guaranteed by this index:
UkSeries UNIQUE INDEX value (series ASC, data ASC)
In Hibernate, the above index is created by this annotation:
@Table (
uniqueConstraints = @UniqueConstraint (columnNames = {"series", "data"}))
Now, please compare it to this possible alternative index definition:
UkSeries UNIQUE INDEX value (series ASC, data ASC)
IdxSeries INDEX value (series ASC, data ASC)
@Table (
uniqueConstraints = @UniqueConstraint (columnNames = {"series", "data"}),
indexes = { @Index (name = "IdxSeries", columnList = "series, data") })
Considering I also want to speed up the search for values in the database, my question is:
Will the "UNIQUE INDEX" alone, apart from guaranteeing uniqueness, also be used to speed the searches? Or do I really need both indexes, as presented in my alternative index definition above?
Note: I am using MySQL, but I believe this question is simple enough so that my specific database doesn't matter.