Subject | Re: [firebird-support] Re: need help on optimization |
---|---|
Author | Helen Borrie |
Post date | 2005-04-25T09:11:28Z |
At 08:28 AM 25/04/2005 +0000, Michael Vilhelmsen wrote:
Yes, it will use an index and, if you have only an ascending index on
MyDate, it will be worse than walking the set. Define a DESC index on any
column that you are likely to want to do a MAX() on, across a large
set. Then the result will be instantaneous. Apply a similar index
strategy to any columns on which you are going to do a GROUP BY DESC or an
ORDER BY DESC) on a large set.
One saw mud and the other saw stars."
:-))
./hb
> >Now, does one answer Yes or No to that question? :-))
> > In the first two cases, it does have to read every row. How would you
> > suppose an index could be used ?
> >
>
>Does this also include the usage of MAX ?
>
>I.e. If I want to have
>
>Select
> Max(MyDate)
>from MyTable
>
>And there is an index defined using date.
>
>Will it still not use the index ?
Yes, it will use an index and, if you have only an ascending index on
MyDate, it will be worse than walking the set. Define a DESC index on any
column that you are likely to want to do a MAX() on, across a large
set. Then the result will be instantaneous. Apply a similar index
strategy to any columns on which you are going to do a GROUP BY DESC or an
ORDER BY DESC) on a large set.
> And why not ?"Two men looked out through prison bars:
One saw mud and the other saw stars."
:-))
./hb