Does a unique constraint automatically acts like a composite index making the CompositeIndex redundant in MySql? And if so is this the case for all db’s supported by Ormlite?
and [CompositeIndex(nameof(CustomerId), nameof(Day), nameof(Server), Unique = true)]
Are equivalent in terms of functionality and are fully interchangeable?
Or it’s better to use the CompositeIndex because the UniqueConstraint just check uniqueness and there’s no related index or it doesn’t act like an index at all?
From what I can find online it seems that there’s an index on a unique constraint (in MySql at least) but I got this on stackoverflow and the multiples answers felt more like opinions (even the accepted answer) than a definitive answer.
No, have a look at the RDBMS Create Table SQL they generate by enabling SQL logging:
OrmLiteUtils.PrintSql();
[UniqueConstraint] creates a unique RDBMS constraint, whilst [CompositeIndex] creates a composite RDBMS index, adding Unique=true generates a UNIQUE composite index. You’d decide which to use based on whether or not your System would benefit from the existence of this specific composite index, if you’re unsure don’t create it.
These attributes do not have any affect of OrmLite’s behavior at runtime, i.e. they’re only used when OrmLite creates the table.