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 2005 Forums
 Transact-SQL (2005)
 cross join slow performance

Author  Topic 

DharmeshParekh
Starting Member

1 Post

Posted - 2009-06-19 : 09:21:51
insert into tran_table(location,cartype,specificdate,capacity,Nocollection,minLor,NoDropoff,Nobooking)
select lc.location,'ecm',tmpDt.value,0,1,sippcode.lorvalue,0,0
from @Locations lc
inner join @tmpSippCode SippCode on SippCode.SippCodeId = lc.sippcodeID
cross join @tmpDateRange tmpDt
where not exists (select 1 from tran_table where location =lc.location and specificdate = tmpDt.value)

can you tell me what is wrong with above query. sometimes it takes too much time to complete the execution. so i got timeout error in front-end application. is it the cross-join culprit?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-06-19 : 09:41:20
Very likely. Whenever select 1 from tran_table where location =lc.location and specificdate = tmpDt.value doesn't exist, you're going to get every row out of it for each row in
@Locations lc
inner join @tmpSippCode SippCode on SippCode.SippCodeId = lc.sippcodeID

that's called a Cartesian product. Are you sure that's what you want?
Explain what you are trying to accomplish with the query and maybe we can re-write it.

Jim

Jim
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-20 : 02:19:57
whats the purpose of last cross join? i dont think you need that. can you explain your requirements with some sample data in following format

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
   

- Advertisement -