Subject Re: [firebird-support] What is duplicate index?
Author Svein Erling Tysvaer
Mohammad Jeffry wrote:
> I understand that duplicate index can slow down firebird. What is duplicate
> index? How can one create duplicate index? example please

CREATE TABLE TEST(FIELDA INTEGER NOT NULL PRIMARY KEY, FIELDB INTEGER);

CREATE INDEX DuplicateIndex1 ON TEST(FIELDA);

CREATE INDEX DuplicateIndex2 ON TEST(FIELDA, FIELDB);

CREATE INDEX OKIndex ON TEST(FIELDB, FIELDA);

CREATE INDEX DuplicateIndex3 ON TEST(FIELDB);

CREATE INDEX OKIndex2 ON TEST(FIELDA DESC);

Since the primary key automatically produces an index, DuplicateIndex1
is a copy of the primary key, DuplicateIndex2 may be different (I do not
know), but since FIELDA is unique (the primary key must be unique),
there is no case where it is of any use. OKIndex creates an index first
on FIELDB and then on FIELDA, so DuplicateIndex3 doesn't add anything
not already available through OKIndex.

I added OKIndex2 since Firebird uses unidirectional indexes and there is
a difference between the default ASC index and a DESC index.


HTH,
Set