Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2005, 11:13 PM
svvc svvc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 12 svvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 58 sec
Reputation Power: 0
tune a query with left outer join

HI,

I have a query
select a.*,b.* from a left outer join b on a.col1=b.col1 and a.col2=b.col2 and a.col3=b.col3 and a.col4=b.col4

This query takes around 2 hours...

Table a has around 50 million records and table b has 200000...I have indexes on col1,col2,col3,col4 on both the tables....

Is there anyway to improve the run time?....

Thanks

Sam

Reply With Quote
  #2  
Old November 7th, 2005, 03:31 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,042 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 6 Days 14 h 44 m 37 sec
Reputation Power: 281
Run an EXPLAIN and post it's result here.
Also post the table structure.

Reply With Quote
  #3  
Old November 7th, 2005, 09:29 AM
svvc svvc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 12 svvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 58 sec
Reputation Power: 0
Thanks for your response..Here is the explain plan...I have a index on table DEPARTMENT for the columns in the join condition. I also have an index on table DEPARTMENT but it has one index on extra columns as well...Doe it make any difference?...

Please suggest...


Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop

SELECT STATEMENT Optimizer Mode=ALL_ROWS 47 M 68141
HASH JOIN OUTER 47 M 6G 68141
TABLE ACCESS FULL COMPANY 47 M 3G 16638
TABLE ACCESS FULL DEPARTMENT 183 K 13 M 66

Reply With Quote
  #4  
Old November 7th, 2005, 09:51 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,042 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 6 Days 14 h 44 m 37 sec
Reputation Power: 281
Can you post the exact query and table structure?

Reply With Quote
  #5  
Old November 7th, 2005, 10:50 AM
svvc svvc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 12 svvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 58 sec
Reputation Power: 0
Thank You

SELECT COMPANY.col1, COMPANY.col2, COMPANY.col3, COMPANY.col4, COMPANY.col5, COMPANY.col6, COMPANY.col7, COMPANY.col8, COMPANY.col9, COMPANY.col10, COMPANY.col11, COMPANY.col12, COMPANY.col13, COMPANY.col14, COMPANY.col15, COMPANY.col16, COMPANY.col17, COMPANY.col18, COMPANY.col19, COMPANY.col20, COMPANY.col21, DEPARTMENT.col1, DEPARTMENT.col2, DEPARTMENT.col3, DEPARTMENT.col4, DEPARTMENT.col5, DEPARTMENT.col6, DEPARTMENT.col7, DEPARTMENT.col8, DEPARTMENT.col9, DEPARTMENT.col10, DEPARTMENT.col11, DEPARTMENT.col12
FROM
COMPANY LEFT OUTER JOIN DEPARTMENT
ON COMPANY.col2 = DEPARTMENT.col1 AND
COMPANY.col3 = DEPARTMENT.col2 AND
COMPANY.col4 = DEPARTMENT.col3 AND
COMPANY.col14 = DEPARTMENT.col6


CREATE TABLE COMPANY
(
col1 VARCHAR2(10 BYTE),
col2 VARCHAR2(10 BYTE),
col3 VARCHAR2(6 BYTE),
col4 VARCHAR2(2 BYTE),
col5 VARCHAR2(8 BYTE),
col6 VARCHAR2(2 BYTE),
col7 VARCHAR2(2 BYTE),
col8 VARCHAR2(2 BYTE),
col9 VARCHAR2(2 BYTE),
col10 VARCHAR2(1 BYTE),
col11 VARCHAR2(1 BYTE),
col12 VARCHAR2(34 BYTE),
col13 VARCHAR2(1 BYTE),
col14 VARCHAR2(4 BYTE),
col15 VARCHAR2(10 BYTE),
col16 VARCHAR2(1 BYTE),
col17 VARCHAR2(3 BYTE),
col18 VARCHAR2(1 BYTE),
col19 VARCHAR2(3 BYTE),
col20 VARCHAR2(6 BYTE),
col21 VARCHAR2(10 BYTE)
)

CREATE UNIQUE INDEX COMPANY_KEY ON COMPANY
(col2, col3, col4, col14, col1,
col15)

CREATE TABLE DEPARTMENT
(
col1 VARCHAR2(30 BYTE),
col2 VARCHAR2(10 BYTE),
col3 VARCHAR2(6 BYTE),
col4 VARCHAR2(8 BYTE),
col5 VARCHAR2(30 BYTE),
col6 VARCHAR2(4 BYTE),
col7 VARCHAR2(3 BYTE),
col8 VARCHAR2(6 BYTE),
col9 VARCHAR2(2 BYTE),
col10 VARCHAR2(2 BYTE),
col11 VARCHAR2(8 BYTE),
col12 VARCHAR2(20 BYTE)
)

CREATE UNIQUE INDEX DEPT_KEy ON DEPARTMENT
(col1, col2, col3, col6)

Reply With Quote
  #6  
Old November 14th, 2005, 09:19 AM
tsmetz tsmetz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 44 tsmetz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 25 m 22 sec
Reputation Power: 5
don't you have any filters?
what do you to with a result set of 50 mio rows?

additionally, do you really need all columns returned?
if you return more columns, than the index has, there has to be a table access to get this data (either a fill table access or a table access by rowid).

i recommend, that you try filters (e.g if you show the data in an application, only query the first 50 data sets).

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > tune a query with left outer join


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT