Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Major perfomance difference when batch inside Transaction

Status
Not open for further replies.

whool

Programmer
Jan 31, 2002
31
AU
The following batch aggregates records in one (INVSwitchTransValidTbl)and inserts the aggregates in table INVJobsTbl. It then gets the GUID created for the Jobs records and updates the records in INVSwitchTransValidTbl which formed the aggregates.

The script takes about 30 seconds to process 200,000 records in the INVSwitchTransValidTbl table. However when I put both statement in a single transaction it takes 11 minutes! Why does this cause such a significant difference?


Code:
	--insert Aggregates for each Brd into Jobs table
	INSERT INTO INVJobsTbl(JobID,nodeAccountcode, JobTypeID, PeriodID, Jobref, JobTime, JobCharge, Qty)
	SELECT  newid()JobID ,NodeAccountCode, 2, 1 , mid, RecvTime, sum(retailCharge), count(*) FROM INVSwitchTransValidTbl
		WHERE TypeInd_Brd = 2 AND  Aggregated = 0
		Group by NodeAccountCode, mid, RecvTime 

		--Update BRD trans recs with the new JobID
	UPDATE t SET JobID = j.jobID 
		FROM INVJobsTbl j JOIN INVSwitchTransValidTbl t 
		ON j.jobRef = t.MID AND j.jobtime = t.RecvTime
		WHERE TypeInd_Brd = 2 AND Aggregated = 0




Any help appreciated.

Yael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top