Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Delete Expand / Collapse
Author
Message
Posted Wednesday, June 11, 2008 2:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 29, 2011 7:07 AM
Points: 3, Visits: 67
I wrote query to delete some records in one of the table in my database.
I set up job to run this query.
The query is as below:

DELETE I
FROM tbItem I (nolock)
INNER JOIN tbProductionOrder PO (nolock)
ON I.POID = PO.POID
WHERE PODescription LIKE '%00000%'

This job has ran successfully in the past, but now it start hanging my system to extent that they cannot work in the factory, what are the possible causes?
Post #515014
Posted Wednesday, June 11, 2008 2:56 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:05 AM
Points: 42,829, Visits: 35,961
how many rows is that delete likely to affect?
What indexes do you have on the 2 tables?



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #515017
Posted Wednesday, June 11, 2008 3:06 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, April 25, 2013 7:39 AM
Points: 287, Visits: 208
Not sure on the validity of (nolock) on a table where you are deleting data?

That aside, you mentioned this has worked in the past, but not so well now.

What you don't state is other contributing factors like
* Volume of data involve on both the related tables
* Is there an RI link and has that any supportive indexing to help the query.
* What sort of number of deletes are you expecting, ie When originally run a few rows to be deleted would not have the same impact as say several thousand.

As with a lot of the forum items on this site (I know because I have asked questions as well), it works a lot better if you can give as much relevant details on the issue as possible.

Cheers.
Post #515018
Posted Wednesday, June 11, 2008 3:15 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 29, 2011 7:07 AM
Points: 3, Visits: 67
DELETE I
FROM tbItem I (nolock)
INNER JOIN tbProductionOrder PO (nolock)
ON I.POID = PO.POID
WHERE PODescription LIKE '%00000%'

This will delete about 11000000 records
Once again this has been successfully severally
Post #515022
Posted Wednesday, June 11, 2008 5:00 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:05 AM
Points: 42,829, Visits: 35,961
Index definitions?
Has the total number of rows in the table changed since this worked properly?
Are your indexes fragmented? Are the statistics out of date?

I'm not asking just to be a pain. I'm asking because I want as clear a picture of the problem as possible.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #515055
Posted Wednesday, June 11, 2008 5:06 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:05 AM
Points: 42,829, Visits: 35,961
UDBNT (6/11/2008)
Not sure on the validity of (nolock) on a table where you are deleting data?


The hint will be ignored. Deletes have to lock exclusivly, lock hints or no lock hints.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #515059
Posted Wednesday, June 11, 2008 5:18 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, April 25, 2013 7:39 AM
Points: 287, Visits: 208
Fair enough, it was just that I seem to remember some reference to (nolock) dealing with potentially non-commited data and the obvious impacts of that might not be that desirable.

Seems like we are both asking for more detail/history from the originator.
Delete of 11 million rows doesn't sound like a daily task to me, but I might be wrong!!
Post #515068
Posted Wednesday, June 11, 2008 7:31 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 29, 2011 7:07 AM
Points: 3, Visits: 67
The 11 Million is a standard number so it does not vary
I also run DBCC DBREINDEX on the table earlier
So question of defragmentation should not come up
Post #515162
Posted Wednesday, June 11, 2008 1:23 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, May 22, 2014 7:04 AM
Points: 1,688, Visits: 8,766
It would be helpful if you mention the index structure on both the tables involved in delete operation.

Manu
Post #515459
Posted Wednesday, June 11, 2008 1:42 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 6:15 PM
Points: 23,300, Visits: 32,053
I'd write it more like this:

DELETE FROM
dbo.tbItem
FROM
dbo.tbItem I
INNER JOIN dbo.tbProductionOrder PO
ON (I.POID = PO.POID)
WHERE
PO.PODescription LIKE '%00000%'

You could also encolse this is a while loop and delete records in smaller batches.

declare @recordstodelete int,
@recordsdeleted int;
set @recordstodelete = 5000;

while (@recordsdeleted is null)
or (@recordsdeleted <> 0)
begin -- while

DELETE TOP (@recordstodelete) FROM
dbo.tbItem
FROM
dbo.tbItem I
INNER JOIN dbo.tbProductionOrder PO
ON (I.POID = PO.POID)
WHERE
PO.PODescription LIKE '%00000%'

set @recordsdeleted = @@rowcount

-- BACKUP LOG ... -- a transaction log backup could be coded here to manage t-log size

end -- while





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #515472
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse