Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Speed up a Query

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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, 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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

636 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