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


Simple Delete Query is Taking Huge Time


Simple Delete Query is Taking Huge Time

Author
Message
debanjan.ray
debanjan.ray
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 189
Hi All,

One of simple delete query is taking more than 10hrs to execute. There are more than 12 foreign keys dependent on that table. Query is like this,

Delete from Some_Table where table_sr_key !=-99 and sector_id=@some_code

But if we execute the same query after updating the statistics of the table then the query get executed in few minutes.

Please help me how me handle this issue so that those query will execute without any manual intervention.

Thanks in advance,

Debanjan
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5294 Visits: 4076
debanjan.ray (1/24/2013)
One of simple delete query is taking more than 10hrs to execute. There are more than 12 foreign keys dependent on that table. Query is like this,
Delete from Some_Table where table_sr_key !=-99 and sector_id=@some_code


Two questions :
How much data it contains ?
and do FK are with "on cascade delete" option ?

Also post table defintion along with index definition

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Koen Verbeeck
Koen Verbeeck
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: 27563 Visits: 13268
Maybe you should create a job to automatically update your statistics, since they're clearly out of date.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
debanjan.ray
debanjan.ray
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 189
That table contains only 1lac rows.

Table PK:

Table_sr_key, table_eff_strt_dt

Table FK(10 Fks like same structure):

PRD_SR_KEY, EFF_STRT_DT
REFERENCES Product (PRD_SR_KEY, EFF_STRT_DT)

Table is refernced by more than 20 table.
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5294 Visits: 4076
still you havent posted what all i asked

anyways
i will suggest you to take batch approach for "Deletion" . and i dont think "periodic statistics updation will help you much HERE "

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5294 Visits: 4076
do FK are with "on cascade delete" option ?

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
debanjan.ray
debanjan.ray
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 189
No.. On delete cascade option is not there with FK....
Koen Verbeeck
Koen Verbeeck
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: 27563 Visits: 13268
debanjan.ray (1/24/2013)
That table contains only 1lac rows.

Table PK:

Table_sr_key, table_eff_strt_dt

Table FK(10 Fks like same structure):

PRD_SR_KEY, EFF_STRT_DT
REFERENCES Product (PRD_SR_KEY, EFF_STRT_DT)

Table is refernced by more than 20 table.


This is primarily a English-speaking site, so 95% of the people here don't know what you mean with lac (or lakh). Also read the following article about keeping the integrity of your database when deleting rows in a table referenced by FKs:

Do not disable foreign keys


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5294 Visits: 4076
Koen Verbeeck (1/24/2013)
Do not disable foreign keys
Any other reference ?

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Koen Verbeeck
Koen Verbeeck
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: 27563 Visits: 13268
Bhuvnesh (1/24/2013)
Koen Verbeeck (1/24/2013)
Do not disable foreign keys
Any other reference ?


Maybe. I'm sure Google can help you out ;-)


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
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