Optimize large SQL query with multiple joins [message #287485] |
Wed, 12 December 2007 06:28 |
ramya.pathak
Messages: 15 Registered: August 2007
|
Junior Member |
|
|
Hi all,
Am using a big SQL query in order to retrieve my data in a procedure.
The query is like:
SELECT A.COL1,.....,K.COL100
FROM A,B,C,D,E,F,G,H,I,J,K
WHERE A.KEY = B.KEY (+)
AND A.KEY = C.KEY (+)
AND A.KEY = D.KEY (+)
AND A.KEY = E.KEY (+)
AND A.KEY = F.KEY (+)
AND A.KEY = G.KEY (+)
AND A.KEY = H.KEY (+)
AND A.KEY = I.KEY (+)
AND A.KEY = J.KEY (+)
AND A.KEY = K.KEY (+)
'A' is the main table. Parent table of all.
Table 'A' contains around 150,000 records.
The query is taking too long to run.
Any way I can optimize the query..??
|
|
|
|
|
|
|
Re: Optimize large SQL query with multiple joins [message #287567 is a reply to message #287485] |
Wed, 12 December 2007 12:54 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
I cannot see your query plan, the file must be missing.
However, if your query is truly like this, you are looking at all rows in all tables subject to the correct joins, then using indexes (and presumably nested loops) would likely be a real bad thing.
I suggest you enable hash joins (may require the setting of multiple parameters so do some research), compute statistics on all the tables involved (dbms_stats... cascade=>true), and then see if the query plan shows full table scans and hash joins. This would be much faster than nested loop via index lookups, especially if there is more than just a few rows in these tables. You should look for improvement somewhere between 2 and 10 times faster depending upon the number of rows being joined.
As always, your mileage may vary.
Good luck, Kevin
|
|
|
|
Re: Optimize large SQL query with multiple joins [message #287597 is a reply to message #287584] |
Wed, 12 December 2007 20:27 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
The plan contains a COUNT STOPKEY line, which means that query contains a ROWNUM clause somewhere. Your original query does not contain a ROWNUM clause, so this tells me the Explain Plan is for a different query.
Post the REAL explain plan.
Ross Leishman
|
|
|
|