Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > problem with deleting

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-04, 06:49
zaki_mtk zaki_mtk is offline
Registered User
 
Join Date: Jan 2004
Posts: 99
problem with deleting

the following delete statement bombs out the rollback tablaspeace, I understand that by using a NOT the optimizer is doing a full table scan.

How can I write this query to be in a optimized form? the table has currrently 2 million rows, and will grow to 10 million.

any suggestion/ideas welcome?

thanks.



delete tracking.AT_Search where homeid NOT IN (#idlist#);


***** Explain Plan ************

Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop

DELETE STATEMENT Hint=CHOOSE 2 M 540
DELETE AT_SEARCH
TABLE ACCESS FULL AT_SEARCHi 2 M 32 M 540
Reply With Quote
  #2 (permalink)  
Old 02-24-04, 06:53
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
Re: problem with deleting

The amount of rollback used has nothing to do with the optimizer plan (full scan v. index), it is a function of the number of rows you are deleting, which is presumably large in this case.
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #3 (permalink)  
Old 02-24-04, 06:54
zaki_mtk zaki_mtk is offline
Registered User
 
Join Date: Jan 2004
Posts: 99
Yes your correct the rollback is bombing out because of the large amount of data, how can I optimize the query to prevent this from occuring?
Reply With Quote
  #4 (permalink)  
Old 02-24-04, 06:54
dbabren dbabren is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 152
you could try a different tact - copy out the rows you want to keep to a temp table, truncate the original table, and then either rename the temp table, or copy the rows back in again.

Different way to achieve the same thing ... (and a lot less logging!)
__________________
Regards
Dbabren
Reply With Quote
  #5 (permalink)  
Old 02-24-04, 07:02
zaki_mtk zaki_mtk is offline
Registered User
 
Join Date: Jan 2004
Posts: 99
hmm not sure on creating a temp table on this particular query, is there any way to optimize this query?
Reply With Quote
  #6 (permalink)  
Old 02-24-04, 07:11
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
If you intend to delete X rows from the table, then no amount of "query optimization" will help. Dbabren's suggestion is good, but if you don't want to go with that then other alternatives you have are:

1) Increase available rollback so that the delete doesn't fail

2) Break the job into smaller pieces, for example:

PHP Code:
begin
  
for r in (select homeid from <home tablewhere homeid NOT IN (#idlist#)
  
loop
    delete from tracking
.AT_Search where homeid r.homeid;
    
commit;
  
end loop;
end
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #7 (permalink)  
Old 02-24-04, 07:12
zaki_mtk zaki_mtk is offline
Registered User
 
Join Date: Jan 2004
Posts: 99
thanks!!!! for all your help....I will play around with the suggestions and see what comes up!!
Reply With Quote
  #8 (permalink)  
Old 02-24-04, 10:00
gbrabham gbrabham is offline
Registered User
 
Join Date: Apr 2003
Location: Greenville, SC (USA)
Posts: 1,143
As stated, try to break up the job into smaller pieces or

Create a LARGE rollback segment (ie, 200m with next extent 25m)
... Ensure your rollback tablespace is set to handle this with autoextents

Use this rollback segment prior to your delete statement

sql> set transaction use rollback segment rbs_large;

HTH
Gregg
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On