If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > optimizing the Delete SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-20-08, 02:59
azs0309 azs0309 is offline
Registered User
 
Join Date: Jan 2008
Posts: 88
optimizing the Delete SQL

delete from tab1 a where cast(a.col as BIGINT) not in (select cast(s.col as bigint) from tab2 s).

Does anyone has any idea to optimize this delete. I want to delete the data from tab1 on the basis of column which doesnt have any equivalent row in tab2.

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-20-08, 04:23
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You do have indexes on TAB2.COL and TAB1.COL? Other than that, there is not much to optimize.

The main issue here will be logging anyway, i.e. if there are many rows to be deleted, the before image of each row must be written to the log. So you may want to consider turning logging off with ALTER TABLE ... NOT LOGGED INITIALLY.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 02-20-08, 06:19
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Using the CAST function on a predicate may reduce (or eliminate) the chances of DB2 using an index on that column.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 02-20-08, 08:10
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
Quote:
Originally Posted by azs0309
delete from tab1 a where cast(a.col as BIGINT) not in (select cast(s.col as bigint) from tab2 s).
Thanks

make sure, that s.col is NOT NULL in tab2. If a NULL-value occures, the DELETE fails.

For performance reasons, omit the CAST() funcion ( at least in the WHERE-clause of the outer statement )
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

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