Subject | RE: [firebird-support] Indices and Firebird |
---|---|
Author | Svein Erling Tysvær |
Post date | 2010-04-07T10:36:43Z |
>3, Let's say I create an index on multiple columns:I suppose so too. However, you may find
>CREATE INDEX IDX_MYTABLE ON MYTABLE(COL1,COL2);
>
>Now if I call
>SELECT somestuff FROM MyTable WHERE Col1 >= 0 AND Col2 = 1 ORDER BY Col1;
>I suppose FB will use the index.
CREATE INDEX IDX_MYTABLE ON MYTABLE(COL2, COL1);
to have better performance. The order of columns within an index matters and if your table contained
Row# Col1 Col2
1 -3 1
2 0 1
3 0 2
4 1 1
Then an index on (Col1, Col2) could easily get to row#2, but would then have to eliminate row#3. An index on (Col2, Col1) would equally easy get to row#2, but would finish before ever getting to row#3.
This is not how things are done internally within Firebird, just the way I perceive things. I rarely use combined indexes, but if you do consider the order of the fields within the index. Often, you will want fields with an equality comparison before those with a range comparison.
HTH,
Set