| |
|
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.
|
 |

08-02-10, 17:30
|
|
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
|
|

08-02-10, 17:41
|
|
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.
|
|

08-02-10, 17:49
|
|
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.
|
|

08-02-10, 17:53
|
|
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.
|
|

08-02-10, 19:07
|
|
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.
|
|

08-03-10, 12:44
|
|
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
|
|

08-03-10, 12:49
|
|
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.
|
|

08-03-10, 13:07
|
|
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.
|
|

08-03-10, 14:17
|
|
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.
|
|

09-04-10, 08:43
|
|
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)
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|