Subject | RE: Order of key elements |
---|---|
Author | Svein Erling Tysvær |
Post date | 2012-10-16T08:00:13Z |
>What is the effective difference between these two key elements orderings?If PK is the primary key of T, then I'd say that a UNIQUE constraint is basically a 'relaxed version' of the primary key and that neither of these constraints make any sense (the PK itself assures uniqueness). As for having an index on these fields, the first doesn't make any sense since you already have the primary key, whereas the second would be useful only if the distribution of (the almost Boolean field) HIGH_MAX_DUP was extremely skewed (e.g. having a index on the field GENDER can be useful if you search for men with breast cancer since over 99% of breast cancers appear amongst women, the same index will be slowing down things if searching for women). The second index was also the typical way to write an index on relatively low-selective fields in Firebird in its infancy (around 10 years ago), UPDATEs used to be slow for non-selective indexes (I don't know when this changed, but have heard less about it the last few years, so I think it is less of an issue with recent Firebird versions).
>
>ALTER TABLE T ADD CONSTRAINT U UNIQUE (PK, HIGH_MAX_DUP)
>
>ALTER TABLE T ADD CONSTRAINT U UNIQUE (HIGH_MAX_DUP, PK)
HTH,
Set