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)
 Multi threading

Author  Topic 

AAAV
Posting Yak Master

152 Posts

Posted - 2011-12-14 : 10:41:32
A) I need to process 3 million rows. will i be able to run 3 threads of 1 million each in sql server 2008 at the same time?
B) I need to run two cross apply queries which cacluates different values. will i be able to run them simultaniously?

I am trying to reduce the execution time. Let me know what you all use to acheive that.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 11:16:32
A, for increasing parallelism in execution, you can specify the level of parallelism by means of MAXDOP hint
B, its possible to run a query with multiple cross applys together simultaneously


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

AAAV
Posting Yak Master

152 Posts

Posted - 2011-12-14 : 11:31:54
B... interested in knowing this

suppose i have 2 queries
Select * from tableA cross apply fnA
select * from tableA cross apply fnB

Let me know how??
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 11:34:43
depending in your requirement it can be either of two

1.select
from (Select * from tableA cross apply fnA)a
inner join(
select * from tableA cross apply fnB)b
on b.relatedcol = a.relatedcol

2.Select * from tableA a
cross apply fnA fa
cross apply fnB fb


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

AAAV
Posting Yak Master

152 Posts

Posted - 2011-12-14 : 12:43:17
but will it run each of the cross apply in its own thread...
i am trying to cut down the execution time
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 12:47:22
quote:
Originally posted by AAAV

but will it run each of the cross apply in its own thread...
i am trying to cut down the execution time



you cant guarantee that
didnt understand need of such a requirement though
currently how long query is executing?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

AAAV
Posting Yak Master

152 Posts

Posted - 2011-12-14 : 12:57:51
I have 3 million rows


This is not the actual case but for example
i have 3 million products
for each i run 7 cross apply functions (calculating different cost- each of which is in a function).

I am thinkign if possible i can run costA and CostB together.
Each cross apply outputs the result to a temp table.

that way i can run CostA and CostB together CostC and CostD together and CostE and CostF together . CostG takes all the costA thro CostF into account hence it has to be done alone.

My objective is...
1) if i am able to run 2 costs at the same time fine... it might reduce the time
2) if i am able to split the input rows in to 3 batches and 2 batches run at the same time then also the time must be reduced

correct me if iam wrong...
now it runs for roughly 5 hours.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 13:04:01
why do you need 7 cross applys? why cant you merge the cost calculations together?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

AAAV
Posting Yak Master

152 Posts

Posted - 2011-12-14 : 13:24:09
That is a good idea... but merging them will not reduce the time right?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 13:25:29
it will as all logic will now be inside single cross apply

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

AAAV
Posting Yak Master

152 Posts

Posted - 2011-12-14 : 13:38:53
will try now....
Go to Top of Page
   

- Advertisement -