SQL Server Performance Forum – Threads Archive
Query is taking ages to execute….
Hi,<br /><br />I am trying to update TBL1 (approx. 22 million records) by getting information from another table TBL2 (6 million records).<br /><br />Here is my query<br /><br /><font color="blue">UPDATE<br />DB1.DBO.TBL1<br />SET<br />DB1.DBO.TBL1.FLD1=DB2.DBO.TBL2.FLD1,DB1.DBO.TBL1.FLD2=DB2.DBO.TBL2.FLD2<br />FROM<br />DB1.DBO.TBL1<br />LEFT JOIN <br />DB2.DBO.TBL2<br />ON<br />DB1.DBO.TBL1.FLD3=DB2.DBO.TBL2.FLD3<br /></font id="blue"><br />(DB2.DBO.TBL1.FLD3 and DB2.DBO.TBL2.FLD3 both are indexed).<br /><br />DB1 size mdf = 43.2 GB, ldf = 7.11 GB.<br />DB2 size mdf = 12.2 GB, ldf = 8.60 GB.<br /><br />This query is running from last 1:47 hours:minutes and still executing.<br />Do it suppose to execute for this long or is there any thing i can do?<br />I can see Harddisk is spinning like hell (i am using 300GB Ultra scsi 10K), but CPU is quite.<br /><br />FYI,<br />tempdb mdf = 3.23 GB, ldf = 14.6 MB.<br /><br />Any suggestion [<img src=’/community/emoticons/emotion-6.gif’ alt=’
You can try to do it in batches of 1000 rows or so. It wouldn’t make it faster but could save log space if simple recovery model is used or frequent enough transaction log backups are performed.
Composite index on tbl2.fld3, fld2, fld1 could speed up the query.
Yesterday night, i left my machine on to execute this query overnight. <br />But this morning when i came back office, this query was still executing [B)] from last 18 hours.<br /><br />I was not able to do any thing, so i decided to cancel the query. I stop query and restart server, and now i cannot work. After start it hangs, i stop SQL server and start in Single user mode and check logs and got the error below<br /><br /><font color="red">2006-03-16 09:58:28.57 spid10 Recovery of database ‘DB2′ (6) is 4% complete (approximately 36044 more seconds) (Phase 3 of 3).</font id="red"> [<img src=’/community/emoticons/emotion-6.gif’ alt=’

I think as your query was doing updates so when you killed the process it started to rollback.But as you restarted the server the rollback was in process.So when the server came back up again it started to finish the rollback.In the worst case the rollback might take as long as the job had been running.
This is just a guess and the reason could be something else too. cheers
Pali
Everything happens for your own good.
Hi Pali, Thanks for your reply.
I am running database at my machine with Single 300GB drive. My IO start sucking when i was trying to update table with join of 22 million and 6 million record.
Now i am waiting for another server with at least 4-5 drives to perform any such opertaion.
http://www.sqljunkies.com/Article/7F8518F9-FDAA-4FF3-8FC5-25E8946C8D0C.scuk
http://support.microsoft.com/?id=224587
http://support.microsoft.com/kb/835864 HTH Satya SKJ
Contributing Editor & Forums Moderator
http://www.SQL-Server-Performance.Com
This posting is provided “AS IS†with no rights for the sake of knowledge sharing.
]]>