SunQuest
 
           General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 10th, 2004, 07:50 AM
mariec2 mariec2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 mariec2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
optimizing simple query

I've got this very simple query that takes alot of time to execute:

SELECT sd.shipmentnumber
FROM shipmentdetail sd, shipment s
WHERE sd.shipmentnumber = s.shipmentnumber
AND sd.idreceived != s.iddest


Is there a way to optimize something like this?

Both tables are very large and I'm using Oracle 9i.

Reply With Quote
  #2  
Old March 10th, 2004, 02:28 PM
merliin's Avatar
merliin merliin is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 30 merliin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Lightbulb

I take it you are looking for all shipments that have not reached it's destination.
There are a few things that could be done, not sure if it will speed it up much.

1. Tried archiving?
Add a trigger to move the data into another table once sd.idreceived = s.iddest
This way you lower the number of records that needs to be searched.

2. Manipulate the indexes?
Use the secondary index field to speed up index search. This results in faster searches.

3. Use numbers
If the sd.idreceived and s.iddest are text (my guess is they are not, but needs to be mentioned), then add a destination table and use the destination id as foreign key. Matching numbers are faster then varchars

4. Store the procedure.
Might not increase speed much.

5. Make it a view.
Might not increase speed much either.

6. Alter the sql.
Although this example uses a sub query it migth have less matches and thus be faster.
(I'm in doubt on this one, you'll have to try it and see.)
Code:
select shipmentnumber 
from shipmentdetail
where shipmentnumber not in
(select sd.shipmentnumber
from shipmentdetail sd, shipment s
where sd.shipmentnumber = s.shipmentnumber
and sd.idreceived = s.iddest)


I think option 1 is the best solution.
But one of the others should work. You could even combine one ore more suggestions.

Hope this helps.

Reply With Quote
  #3  
Old March 11th, 2004, 06:33 AM
mariec2 mariec2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 mariec2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
1. Tried archiving?

This would be a nice solution in a perfect world... All data is used all the time. And shipments received in wrong destinations are also used with right destinations for other reports. But I'll se if there's a way to use this idea some other way.


Quote:
2. Manipulate the indexes?
Use the secondary index field to speed up index search. This results in faster searches.

secondary index field?


Quote:
3. Use numbers
If the sd.idreceived and s.iddest are text (my guess is they are not, but needs to be mentioned), then add a destination table and use the destination id as foreign key. Matching numbers are faster then varchars

Your guess is right. Already numbers

Quote:
4. Store the procedure.
Might not increase speed much.

It does speed up, but not enough

Quote:
5. Make it a view.
Might not increase speed much either.

Doesnt speed up at all. But I heard about Materialized views which seems to speed this up alot. Any downsides to doing it this way?
Quote:
6. Alter the sql.

Doesnt speed up either...


Thanks for the help

Reply With Quote
  #4  
Old March 12th, 2004, 12:37 AM
merliin's Avatar
merliin merliin is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 30 merliin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Indexes:
I couldn't find it on oracle's page without having to look for it, so I ripped this url:
http://alpha6.its.monash.edu.au/ora...8schem.htm#3239

Hope that helps.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > optimizing simple query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway