Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Full outer join

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-02-21 : 15:34:46
I have query which uses full outer join and had performance issue which is taking 4 hours to process which 10 millions records..Is there a better way instead full outer join in query..


thanks for you help in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-21 : 15:39:43
Post the query and some sample data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-21 : 15:39:57
What does statistics io and time show? How about the query plan?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-02-21 : 16:10:16
Here is the extract of a query..

select stuid,stu_date,case when datediff(hh,st_date,getdate())>0 then st_date else '' end as st_date
into tableA
from studa a full outer join studb b
on a.stuid = b.stuid
and a.stustatus=b.stustatus
and a.rank = b.rank
where a.stustatus is not null


Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-21 : 16:16:47
You don't need a full outer join there because the where clause has already turned it into a left outer join.

This should be equivalent

select stuid,stu_date,case when datediff(hh,st_date,getdate())>0 then st_date else '' end as st_date
into tableA
from studa a left outer join studb b
on a.stuid = b.stuid
and a.stustatus=b.stustatus
and a.rank = b.rank
where a.stustatus is not null

How many rows in those tables? What indexes do you have on them?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-02-21 : 16:23:39
there are nearly 10 millions rows in both tables and there is no index defined on the table.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-21 : 17:14:30
Then this is going to be slow regardless of join type. There's no row-limiting predicate, so SQL has to process both tables in their entirety. That means two table scans and a hash join. With 10 million rows it's not going to be fast.

How many rows get returned? Most of the 10 million?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-02-21 : 17:39:51
It is returning the 9 million rows..
Please advise to improve performance as it is taking longer longer time to process.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-21 : 17:42:39
There's no way to speed it up.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-02-22 : 06:02:11
what are you actually trying to do?

are you trying to weed out duplicates?

There may be better ways if you describe the actual goal you want.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-22 : 06:23:06
Where is it returning those 9 million rows to? What's the client going to do with 9 million rows?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-02-22 : 07:03:05
quote:
Originally posted by GilaMonster

Where is it returning those 9 million rows to? What's the client going to do with 9 million rows?

--
Gail Shaw
SQL Server MVP


Well it's going into another table -- I think it may be a clean-up exercise...

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-02-22 : 07:30:25
You are correct it will cleanup the execerise basic the tables data will be used to generate the reports.
Go to Top of Page
   

- Advertisement -