Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2668
  • Last Modified:

Examining and optomizing a query

I have some simple quesitons about my DB2 query.  Like "is it using an index when it joins table a to table b?"  I've been looking all day for references that tell how to do this.  I've found didly.

Here are some of the google searches I've done:
db2 query optimization
db2 query plan
db2 explain
db2 explain query
db2 explain results

Nearly every hit is either a page trying to sell a training class or a third party software tool.  Neither are options I can use.

I did find references to the EXPLAIN statement and how to run it.  Seemed promising.  There was nothing about what to do once the statement is executed.  Lots of stuff gets put into the "explain tables" but I've found precious little information about how to interpret the results.

Please do not post examples of how to do what I need.  I'm looking for references.  Please post links to GOOD sites that explian SQL profiling/explaining/optimizing for DB2 databases.

Thank you.

0
GnarOlak
Asked:
GnarOlak
  • 6
  • 5
  • 3
  • +2
3 Solutions
 
nguyenvinhtuCommented:
Try this in Google friend: DB2 join table
0
 
nguyenvinhtuCommented:
Try this one friend to save your time:
http://sqlzoo.net/howto/source/z.dir/tip360466/i01select.xml
0
 
GnarOlakAuthor Commented:
I know how to write SQL queries.  I've been doing it for years.  What I need is a way to determine how db2, a database I have little experience with, will execute the query.

Oracle had an explain plan capability that listed, in order of execution, the tables being joined, wether or not an index was being used, what the index was, etc.  This is what I am looking for in DB2.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
GnarOlakAuthor Commented:
I'm going to accept the last answer (not the one about moving the question!).  There was a reference in the How To list that refered me to the db2expln tool.  The reference I found only showed how to run the tool but nothing about interpreting the output.  As such, if I were to accept the answer now I'd grade it C.  If you, nguyenvinhtu, can provide a link or two about interpreting the output of the command I would be grateful and raise that grade to A.

Thanks
0
 
GnarOlakAuthor Commented:
Annie,

The answer given does provide the basis of the information I was looking for.  The link refered me to a tool that produces a report of how DB2 will execute a query.  As such I am willing to accept that as the answer to my question.

I feel that the answer is a bit weak because it only answers the specific "What tool do I use..."  but not the more general "and how do I use it?"  Perhaps I should have been more thourough when stating my question?

I need to know how DB2 is executing my queries so that I can improve them through restructuring the query, adding indexes, etc.  That being the case I really need to know not just what tool produces the query plan but also how to interpret it.

I was offering a better grade for better information.  It seemed reasonable to me.  If anyone else can provide that additonal information I will split the points.
0
 
AnnieModCommented:
As I said - give the experts a few days so they can continue helping :)
You just need to explain to them what you just explained to me :) ( they will read it)

This is how the site works - the experts work with you and with the rest of the experts :)
0
 
srielauCommented:
There are essentially thre ways to get explains:
1. db2expln which you have found.
  db2expln is best to "reverse engineer" plans form compiled packages such as procedures.
2. Visual explain
   This is part of the command center GUI.
   When you type a query there is an explain button on the top and it will pop up the explain graph
3. db2exfmt
   This is the preffered tool by DB2 Optimizer developers (when you open a PMR they love to see the result in this format.
   To get it first you need to ensure you have the supporting "explain tables" defiened:
    cd <...>/sqllib/misc
   db2 connect to <db>
   db2 -fvf EXPLAIN.DDL
   You do this once. Visual explain does it for you implicitly.
   now:
   db2 "explain plan for select * from sysibm.sysdummy1"
  Should return something like: "The query was not executed but only compiled...."  
   What has happened is that the optimizer has collected a lot of information and stored it in the tables defined
   in EXPLAIN.DDL.
   Now it's time to fromat the output.
   Typically you just type:
   db2exfmt -d <db> -o <filename>.exfmt -1
   (The -1 (number one) says: Don't ask me any more questions, just pick up the last plan stored)
   You can now look at the plan in your favorite editor.
   It will show some basic information first (system config).
   Then it shows the SQL you typed and the SQL DB2 tuned your query into after rewriting it.
   The main attraction is the pretty-printed graph followed by details on teh so called LOLEPOP (low level plan operator).
 
Here is a link into the docs:
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/c0005135.htm

Cheers
Serge
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi GnarOlak,

IBM continues to build Cadillacs that you work on with with wooden hammers from "My First Toolbox".  sigh.....

AQT (Advanced Query Tool) is a low-cost database client with a built in Explain Plan "handler".  It will give you a graphical representation of the plan that's easy to understand.  I don't know if AQT comes with a trial period.

This is a pretty good site for the basics:

http://www.devx.com/getHelpOn/10MinuteSolution/16567/1954?pf=true

Also, Aqua Data Studio has a pretty good (free) database client with a built-in Explain Plan package.  It will convert the explain plan to an easy-to-read diagram that is very clear about the steps and processes.  Here's a link to its description:

http://docs.aquafold.com/docs-ep-plan.html

The download is at the same site.



Good Luck!
Kent
0
 
nguyenvinhtuCommented:
Ok, GnarOlak
You seems very interested in DB2,
This is a gift from me, an ebook of DB2, to GnarOlak and to any one who work with DB2 ^_^
http://www.fixdown.com/soft/22868.asp?fixdown=gdteldowns

I am not focus on DB2 but still spend free time to help you more GnarOlak.
0
 
nguyenvinhtuCommented:
This site is to help you understand more on DB2, DB2 administration
http://webdocs.caspur.it/ibm/db2/8.1/doc/htmlcd/en_US/index.htm?openup=admin/cfptun04.htm
0
 
GnarOlakAuthor Commented:
Serge,

I tried your suggestion but when I ran the db2exfmt command I got a fairly lengthy error message that included this:

Error Message =
SQL0035N  The file "db2exfmt.msg" cannot be opened.

I looked in the ...sqllib/misc directory and the file is not there.  I also searched the entire db2 installation and that file is not there either.  Is the installation incomplete?
0
 
srielauCommented:
Hmm, since db2exfmt is a tool perhaps you don't have the right client installed (?).
Can you try this from a shell running on the server?

Cheers
Serge
0
 
GnarOlakAuthor Commented:
Serge,

I did run that command on the server where db2 is running.
0
 
srielauCommented:
That is.. bizarre
0
 
GnarOlakAuthor Commented:
Thank you all very much.  I will continue to explore the information you have given me.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now