1/In a table, how would index I1 on T(col1, col2)
be different from index I2 on T(col2, col1)
? Can we create both ? Take for example Unique Index
.
Index Skip Scanning seems to dictate that the column order is important, meaning perhaps I1 would be different from I2.
In another text, I have seen
CREATE TABLE INVOICES
(ID NUMBER(11),
INVOICE_DATE DATE,
CONSTRAINT UN_ID UNIQUE(ID, DATE) USING INDEX(CREATE INDEX I_INVOICES ON INVOICES(ID, INVOICE_DATE)),
CONSTRAINT UN_DATE UNIQUE(DATE, ID) USING INDEX I_INVOICES);
meaning both Unique constraints (col1, col2)
and (col2, col1)
are using the same index (col1, col2)
.
Some insights from everyone ? My question is not about When we choose one over another ?
but about when they co-exist Are they two different indice/objects ? Does order matter ? Why would the example use the same index then for both ? Would it be better to create another index (col2, col1) besides (col1, col2) because orders matter?
2/ On the same question: Why are we using just CREATE INDEX
and not CREATE UNIQUE INDEX
? In which case we use CREATE UNIQUE INDEX
?