Solved

Speed up a Query

Posted on 2008-10-09
4
447 Views
Last Modified: 2011-10-19
I am fairly new to writing sql statements and I was hoping someone could look at the query and make some suggestions on how to speed it up because I know it is not the most efficient it could be.
Copy-of-Job-History-20080929.txt
0
Comment
Question by:montrof
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 22678398
Hi Montrof,

Are you familiar with explain plans?  If so, I suggest that you run this through the EXPLAIN processor to see where improvements are warranted.

The query certainly performs a lot of joins.  Something to keep in mind is that when you join a derived table, the number of rows returned in the derived table needs to be as small as possible.  Derived tables can not be indexed so if it contains a lot of rows, you're forcing several full table scans into the process, and possibly a sort or two.  Sometimes joining a derived table is the best choice, but sometimes joining the table and filtering the join is more efficient.  (Only your explain plan will know for sure!)

The only thing that really jumps out as a no-no is the join at the bottom of the script where the join keys are generated by recasting other data.  If a large number of rows are involved, you've injected at least one more full table scan.

Check out the explain plan.  And if you have the Toad/DB2 tools, they have a pretty good SQL rewriter that is pretty darned good at producing more efficient SQL.


Good Luck,
Kent


0
 
LVL 1

Author Comment

by:montrof
ID: 22678655
Kent,

I have Toad for Data Analysis and when I click on the Explain Plan it does nothing.  

Thanks,
Montrof
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 22678847
Hmmm....

I've got Toad and it works fine.  

Executing an Explain Plan will result in tabled being created (if necessary) and updated in your default schema, NOT the schema where you're necessarily working.  I've seen events with some clients where this happened and it looks for all the world like nothing happened.


Kent
0
 
LVL 1

Author Comment

by:montrof
ID: 22678990
I could not find anything it just seems to be doing nothing. I look for the table and no luck there.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question