Solved

Speed up a Query

Posted on 2008-10-09
4
442 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:
Kdo 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:Kdo
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 (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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now