Solved

Speed up a Query

Posted on 2008-10-09
4
445 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

861 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