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

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Mon, 6 Jan 2020 09:33:48 +0000
Message-ID: <LNXP265MB1562E9D33C6A70BEAA9F350FA53C0_at_LNXP265MB1562.GBRP265.PROD.OUTLOOK.COM>


Vishnu,

As a general guideline remember to include the following

the version of Oracle you're using
the code that generates the data
the execution plan you've pulled from memory (dbms_xplan.display_cursor) after running the query.

You also need to think about whether you're playing around with a boundary condition: a notable defect in the examples you have described is that the rows are very short - which immediately raises the question of whether the index is bigger or smaller than the table. For all we know the your complaint about sorting or not sorting may simply mean that you didn't notice that Oracle switch from an index scan to a tablescan with sort, or index full scan to index fast full scan with sort.

Regards
Jonathan Lewis



From: oracle-l-bounce_at_freelists.org <oracle-l-bounce_at_freelists.org> on behalf of Vishnu Potukanuma <vishnupotukanuma_at_gmail.com> Sent: 06 January 2020 05:46
To: Oracle-L Freelists
Subject: Descending index - Order by Clause - sorting? optimizer - Bug?

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 - 10:33:48 CET

Original text of this message