Subject | Re: query optimization- MAX() from .. WHERE |
---|---|
Author | tomjanczkadao |
Post date | 2010-08-18T13:00:33Z |
> >It doubles reads amount.Sorry, i meant there is one read, but it's very slow.
> That seems to tell us that FOREIGN_KEY and NUMER both increase systematically as the database grows...is that the case?Yes.
> If so, test the benefit of placing a descending index on both (but not a compound descending index involving both).Actually it does not matter whether foreign_key has ascending or descending index. There's one read, but very slow, about 25ms (this query is executed many times in loop).
>
> ./heLen
>
But I've temporary solution for this case:
select first 1 numer
from test_tab t
where t.foreign_key = :some_value
order by t.foreign_key desc, t.numer desc
It REALLY use compound index (foreign_key, numer). Query is about 1000x (!) faster. tested in loop.
Regards, Tomek