Descending index - Order by Clause - sorting? optimizer - Bug?

From: Vishnu Potukanuma <vishnupotukanuma_at_gmail.com>
Date: Mon, 6 Jan 2020 11:16:47 +0530
Message-ID: <CAP-RywwBFYv8j49a5zDMq1qXQ7Ry7uy0Lk+vBEe6z6itRNXRCw_at_mail.gmail.com>



Came across an interesting issue today.
the situation is as follows:
create table randomload(roll number, name varchar2(20), mark1 number); roll is the primary key.
create index mark1_desc_roll_idx on randomload(mark1 desc, roll); populate data uniformly for mark1, gather statistics

the following statement regardless of what it uses sorting. (sort order by) select roll from randomload where mark1=11999 order by roll ;

even if we create the index specifically which will not make any sense, but just in case.
create index mark1_desc_roll_asc_idx on randomload(mark1 desc, roll asc); select roll from randomload where mark1=11999 order by roll;

we know that the roll column in the index is already sorted in the ascending order, but still why does oracle perform sorting?

I was wondering whether function based index had to do with any of it. created the index as follows:
create index mark1_roll_idx on randomload(mark1-1, roll); gathered statistics, then running the query. select roll from randomload where mark1=11200 -1 order by roll; here in this case, sorting is not performed, clearly nothing wrong with the function based index and how the data is organized in the indexes, but looks like an issue with the optimizer generating the plan?

all works perfectly fine when the trailing column of the index uses desc instead of leading column...

Thanks,
Vishnu

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Jan 06 2020 - 06:46:47 CET

Original text of this message