Subject | Re: Creating index |
---|---|
Author | Adam |
Post date | 2006-02-12T02:23:30Z |
> Hi, Adamif 99% of the values are 'Y', and only 1% are 'N', then the index would
>
> <Quaoted>
> Generally no.
>
> There are exceptions if the field values are skewed. For example,
> be very useful to perform where field = 'N'.index be used?
> <Quaoted>
>
> what if using where field <> 'N' or where field = 'Y', will the
If it is available and there is no better candidate index then yes
Firebird will attempt to use the index. This is not a question about
whether the index will be used or not. In one sense, the optimiser is
quite simple. It looks at the possible methods of returning the
records and identifies the plan it thinks is the cheapest.
It is always going to cost more time and effort to read both the
index. So therefore to make it worthwhile to read the index, you need
to make savings on the data page reads. In the above example you quoted,
where field <> 'N' represents 99% of the values. Therefore it is
unlikely that the cost of reading the index and generating the bitmap
is going to be made up for in a reduced amount of data read in.
where field = 'Y' (in this case) is the same thing. We know that the
index is not going to help us a whole lot in eliminating records to
read in when compared to the cost of reading the index.
Therefore the following queries would be the most useful.
where field = 'N'
where field <> 'Y'
where field || '' <> 'N'
where field || '' = 'Y'
Ann suggested in her other post that you could OR the last two with
1=0 (where field <> 'N' or 1=0) which would do the same thing.
Adam