SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Delete


Delete

Author
Message
John Rowan
John Rowan
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12880 Visits: 4588
Also, your WHERE clause of PO.PODescription LIKE '%00000%' will normally produce a table scan. It's a bit hard to say for sure though as you have not posted an execution plan or your index structure as requested by the other posters.

John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Matt Miller (4)
Matt Miller (4)
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27814 Visits: 18995
John Rowan (6/11/2008)
Also, your WHERE clause of PO.PODescription LIKE '%00000%' will normally produce a table scan. It's a bit hard to say for sure though as you have not posted an execution plan or your index structure as requested by the other posters.


Agreed, although I can't think of how that wouldn't cause a table scan, thanks to the leading %. That kind of forces a table scan (or a clustered index scan), since there's no decent way to use an index to seek those out.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89792 Visits: 38937
Matt Miller (6/11/2008)
John Rowan (6/11/2008)
Also, your WHERE clause of PO.PODescription LIKE '%00000%' will normally produce a table scan. It's a bit hard to say for sure though as you have not posted an execution plan or your index structure as requested by the other posters.


Agreed, although I can't think of how that wouldn't cause a table scan, thanks to the leading %. That kind of forces a table scan (or a clustered index scan), since there's no decent way to use an index to seek those out.


I also agree, but we have to go with what the OP provided. There is one thing, and unfortunately I don't have time to try and find it, I thought I had read in "Inside Microsoft SQL Server 2005 T-SQL Querying" that SQL Server 2005 had some improvements in its statitistics that improved query performance with leading wildcard characters in the LIKE clause. When I have some free time (what ever that is) I will see if I can find it again.

Cool

Cool
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)
John Rowan
John Rowan
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12880 Visits: 4588
Yes, please do. I'd be interested in reading that if you find it.

Thanks Lynn!

John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Sangeeta Satish Jadhav-362431
Sangeeta Satish Jadhav-362431
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 18
Try this...
DELETE FROM tbItem l (nolock)
Where exists(Select p.POID From tbProductionOrder p (nolock) where l.POID = p.POID AND PODescription LIKE '%00000%')
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)

Group: General Forum Members
Points: 203200 Visits: 41947
Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here... Maybe...

The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem? Parallelism?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89792 Visits: 38937
Jeff Moden (6/12/2008)
Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here... Maybe...

The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem? Parallelism?


True enough Jeff. Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work. The issue could be blocking. Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.

If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation. The OP should check these out.

Cool

Cool
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)
steveb.
steveb.
SSCrazy Eights
SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)SSCrazy Eights (10K reputation)

Group: General Forum Members
Points: 9954 Visits: 7195
Could it be a case of your disks filling up with the transaction log?

have you checked for free space?
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)SSC Guru (203K reputation)

Group: General Forum Members
Points: 203200 Visits: 41947
Lynn Pettis (6/12/2008)
Jeff Moden (6/12/2008)
Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here... Maybe...

The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem? Parallelism?


True enough Jeff. Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work. The issue could be blocking. Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.

If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation. The OP should check these out.

Cool


Correct, WITH (NOLOCK) only affects SELECTs.

I just can believe the delete of 11 million rows didn't get caught blocking before. Somethings not quite right here. I think Lynn is on the right track... I've seen it where the undocumented ability to DELETE alias has bitten folks before. Gotta follow the rules and delete from a table name, instead.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
noeld
noeld
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21538 Visits: 2048
Jeff Moden (6/12/2008)
Lynn Pettis (6/12/2008)
Jeff Moden (6/12/2008)
Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here... Maybe...

The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem? Parallelism?


True enough Jeff. Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work. The issue could be blocking. Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.

If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation. The OP should check these out.

Cool


Correct, WITH (NOLOCK) only affects SELECTs.

I just can believe the delete of 11 million rows didn't get caught blocking before. Somethings not quite right here. I think Lynn is on the right track... I've seen it where the undocumented ability to DELETE alias has bitten folks before. Gotta follow the rules and delete from a table name, instead.


Sometimes there is no tracking in the amount of rows on tables and a sudden increase can be a "surprise" Wink


* Noel
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search