Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Index hints and sorting

User_N25PCFeb 2 2019 — edited Feb 3 2019

Hi,

lets say that I have a huge table T1.

Inside I have ID column ( int type  )  and LASTDATE ( DATE type ) column and composite index INDEX1 on both of them. There are also other columns in this table....

Also, for some particular ID, I have lot of rows.......could be also a huge set.

Now I want to get the last active date for particular ID.

Out of the readings from the net, seems to be that the following:

select /*+ index_desc( t1 index1) */ * from T1 where ID = 10  and rownum=1;

does not guaranties that I am going to get really, and for sure, the last date......because, I omitted ORDER BY, and maybe it will not really go to the end of the index, pick up there ROWID and then give that particular row. One that I want...on the very quick and optimal way.

Because the table is huge, I dont see that I can use anyhow ORDER BY to get what I really want here....just the last row from the particular ID on the best way.

So, please tell me, can I use  /*+ index_desc( t1 index1) */ for this , how I planned, and if not, what would be the best way to do this ?

( just to mention that in this particular case, getting the last active date has sense for me just if this is very fast and cheap ......without consuming too much memories or exploring too many rows or waiting for the result )

thx

This post has been answered by Jonathan Lewis on Feb 3 2019
Jump to Answer
Comments
Post Details
Added on Feb 2 2019
6 comments
2,066 views