?
Solved

Speed up a Query

Posted on 2008-10-09
4
Medium Priority
?
448 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 46

Accepted Solution

by:
Kent Olsen earned 2000 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 46

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 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