If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Create index for ORDER BY

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-02-10, 17:30
brucejin brucejin is offline
Registered User
 
Join Date: Feb 2010
Posts: 24
Create index for ORDER BY

My query (SELECT cola, colb from tableA ORDER BY cola) is slow so I created an index

CREATE indexa on schema.tableA (cola)

The index was created and my query is as slow as before. Do I miss something?

This plan works on DB2, MS SQL, MySQL. Why not on Oracle?

Thanks
Reply With Quote
  #2 (permalink)  
Old 08-02-10, 17:41
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
>This plan works on DB2, MS SQL, MySQL. Why not on Oracle?
post EXPLAIN PLAN from all 4 DBs.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 08-02-10, 17:49
brucejin brucejin is offline
Registered User
 
Join Date: Feb 2010
Posts: 24
On MS SQL Server for example, my query takes 27 seconds

SELECT cola, colb from dbo.tableA ORDER BY cola

After creating index:

CREATE indexa on dba.tableA (cola)

The same query only takes 0.1 seconds.
Reply With Quote
  #4 (permalink)  
Old 08-02-10, 17:53
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
Proves NOTHING!

>This plan works on DB2, MS SQL, MySQL. Why not on Oracle?
post EXPLAIN PLAN from all 4 DBs.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 08-02-10, 19:07
artacus72 artacus72 is offline
Registered User
 
Join Date: Aug 2009
Location: Olympia, WA
Posts: 337
Most likely this is because you created a clustered index in MS SQL. Otherwise indexes don't generally help w/ order by speed unless its a covering index.
Reply With Quote
  #6 (permalink)  
Old 08-03-10, 12:44
brucejin brucejin is offline
Registered User
 
Join Date: Feb 2010
Posts: 24
These 2 queries take 23 seconds on Oracle:

(1) select invline from mrcmpower.bisales order by invline desc
(2) select invline from mrcmpower.bisales where invline >0 order by invline desc

They should be the same because all 2 million rows in the table have invline > 0.

Then I added index
create index mrcmpower.index2 on mrcmpower.bisales (invline desc)

Now query (1) still takes 23 seconds and (2) only takes 0.01 second.

Why query (1) does not use the index?

Thanks
Reply With Quote
  #7 (permalink)  
Old 08-03-10, 12:49
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #8 (permalink)  
Old 08-03-10, 13:07
MCrowley MCrowley is online now
Wage drone 24601
 
Join Date: Jan 2003
Location: Massachusetts
Posts: 4,900
More likely in the MS SQL Server case, the data is being read from cache on the first run, and the second query reads the same data (does a table scan) but reads from memory.
Reply With Quote
  #9 (permalink)  
Old 08-03-10, 14:17
NaveenK NaveenK is offline
Registered User
 
Join Date: Aug 2010
Location: Bangalore
Posts: 7
What is load on those table?

Try gathering the stats on the index that you have created. That might help you.
Reply With Quote
  #10 (permalink)  
Old 09-04-10, 08:43
magicwand magicwand is offline
Registered User
 
Join Date: Mar 2010
Location: Vienna, Austria
Posts: 130
Create a concatenated index:

Code:
create index indexA on tableA(colA, colB)
In this case, Oracle will not access the data segments and get all the info out of the index (you save 50% of I/O this way)
__________________
If A is a success in life, then A = x + y + z.
Work is x; y is play; and z is keeping your mouth shut. After all the years, I'm still working on the correct value for z.
(Albert Einstein)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On