How to optimize DELETE for large number of data?

Hi Guys,
I am creating a DELETE sql for deleting large amount of data, approximately a million records. When I tested it, it got a lot amount of execution time. Is there a way how can I optimize this query?
I highly appreciate any idea from you guys!
Thanks,
Jay

JayPavia wrote:
I am creating a DELETE sql for deleting large amount of data, approximately a million records. When I tested it, it got a lot amount of execution time. Is there a way how can I optimize this query?
I highly appreciate any idea from you guys!Jay,
one quite nice approach is described in the AskTom thread: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2345591157689#2356959585102
In a nutshell: You can create a partitioned table with the same layout (using e.g. a RANGE partitioning with a single default partition), insert the remaining data into that table and swap the two segments using ALTER TABLE EXCHANGE PARTITION.
This allows you to load the data into the partitioned table using all means available to you, e.g. direct-path parallel insert with nologging attribute of the table to make it as fast as possible, rebuilding/creating any indexes in bulk after the load completed.
Furthermore, at least seamless read-access to the table is possible while you're performing this operation, and you don't have to deal with renaming/granting etc. which you would need to do with a traditional CTAS approach.
Of course, if the table needs to be online for DML while performing the DELETE you can't use these options.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/

Similar Messages

  • Fastest Way to Delete a large number of data

    I m trying to delete a large number of Data
    this Proc will be running every day without disturbing the other Process
    SET sql = 'DELETE TOP (100) FROM ' + @TableName + ' WHERE Id IN (Select Distinct Id FROM [state] WHERE ToDel = 1)'SET @Deleted_Rows = 1;SET @Rows = 0; WHILE (@Deleted_Rows > 0)BEGIN BEGIN TRANEXEC sp_executesql @sql SET @Deleted_Rows = (SELECT @@ROWCOUNT);SET @Rows = (@Rows + @Deleted_Rows);COMMIT TRANWaitFor DELAY '00:00:00:01' END
    Have you any Idea how can I optimize my Query ?
    Thank you very much

    Hi, following are few thoughts.
    1. If you can manage without dynamic sql then it may yield better performance as except table name there is no need for it as per your query.
    2. Ensure indexes are in place.
    3. If the table in question is not participant in replication then you may slightly go for higher batch size and again it depends on volume.
    Please take a look at the tweaked code.
    declare @Deleted_Rows int, @Rows int;
    SET @Deleted_Rows = 1;
    SET @Rows = 0;
    WHILE (@Deleted_Rows > 0)
    BEGIN
    BEGIN TRAN;
    DELETE TOP (100) t1
    FROM
    tabName as t1
    WHERE exists (Select * FROM [state] as t2 WHERE t2.ToDel = 1 and t2.Id = t1.id);
    SET @Deleted_Rows = @@ROWCOUNT ;
    SET @Rows = @Rows + @Deleted_Rows;
    COMMIT TRAN;
    WaitFor DELAY '00:00:00:01';
    END
    Print 'Total rows deleted : '+convert(varchar(50), @Rows);

  • How can I delete a large number of messages from my iCloud mailbox in bulk mode?

    I decided that I have a large number of e-mail messages in my iCloud mailbox that I do not need anymore and I would like to delete these messages in a single - simple move. How can I do it (Gmail offers a nice way to do this but I cannot find anything similar in iCloud...)?

    Archive the contacts you have in Address book, then delete them, they will be removed from iCloud as well. Restore the archive

  • How do I delete a large number of songs off my iPad

    I have a large music collection and have downloaded a large number of songs onto my iPad (10GB).  I don't need that much music on my iPad and would like to put the songs back in the cloud.  I don't want to have to delete thousands of songs one at a time by swiping.  What is the best way to do this?
    I have a 4th gen iPad and I have iTunes Match.

    Then I suspect you do not have iTunes Match enabled. Using that "delete all" command in the Settings does not remove the music from the cloud, nor does it disable iTunes Match. With iTunes Match enabled you will still see all the music.
    So go to Settings > iTunes and App Store and make sure iTunes Match is set to ON (green).

  • XML file for large number of data records

    I have to create an xml file using the data from multiple table. The problem That i am facing is the data is huge it is in millions so I was wondering that is there any efective way of creating such an xml file.
    It would be great if you can suggest some approach to achieve my requirement.
    Thanks,
    -Vinod

    You'd probably be better asking over in the XML DB forum as that forum is dedicated to dealing with the XML side of things.
    The FAQ in that forum is here: {thread:id=410714}

  • I am trying to delete a large number of songs from my Itunes library without having to delete them one at a time.  How do I do that?

    I am trying to delete a large number of songs from my itunes library without having to do it one at a time.  How can I do this.  All of my songs have check marks by them.  Help!

    Then I suspect you do not have iTunes Match enabled. Using that "delete all" command in the Settings does not remove the music from the cloud, nor does it disable iTunes Match. With iTunes Match enabled you will still see all the music.
    So go to Settings > iTunes and App Store and make sure iTunes Match is set to ON (green).

  • I want to remove my credit card from my account and only use gift cards for purchases. How can I delete my card number?

    I want to delete my credit card from my account and only use gift cards.  How can I delete my card number?

    You'll want to get in touch with ITunes support for this. Normally when you start an account with the CC you can't remove it yourself. But by contacting iTunes they can get that taken off for you.
    Use this link to get in touch with the iTunes advisors
    http://www.apple.com/lae/support/itunes/contact.html

  • How do i go about deleting a large number of files at the same time?  where's the easiest place to do it?

    how do i go about deleting a large number of files at the same time?  where's the easiest place to do it?

    A bit vague as to what you intend, but the simple answer is to select all the files you want to delete then either drag to the Trash or CTRL- or RIGHT-click on the selection and choose Move to Trash from the contextual menu.

  • How can I most quickly delete a large number of outlook messages from my iphone?

    How can I most quickly delete a large number of outlook messages from my iphone?

    Who is the email account provider?
    If the email account is an exchange or IMAP account that you access with Outlook on your computer, delete the email with Outlook which will remove the email from your iPhone.

  • How to change Org Unit for larg number of emplyees

    Dear Guru's,
    My client has uploaded wrong Org Units while hiring, now that has to be changed for larg number of employees.
    Can any one suggest me how can we do this for larg number of employees?
    Thanks in advance for your kind suggestions.
    Regards,
    Srinivas

    Hello Srinivas;
    By saying uploaded wrong organizational units, do you mean that organizational structure in PPOME is wrong or employee - position assignment is wrong?
    If employee - position assignment is wrong then I suggest you to use batch input program or use LSMW as you have to change it via personnel action - PA40
    If organizational structure is wrong, then do you have correct organizational structure in another system like test or qa?
    If you have correct organizational structure then you can directly transport it from one system to other but if you don't then you first need to correct the organizational structure and then run LSMW or batch input.
    Regards;
    Okan

  • How can I move a large number of pics from icloud Photos Beta to a PC without having to select each photo?

    How can I move a large number of pics from icloud Photos Beta to a PC without having to select each photo?

    Hi,
    can you please explain why the solution from steve is not the right solution for you.
    regards
    Peter

  • How do you delete a phone number from an iphone that is listed under other and not in the contacts list?

    When I text a contact in my iphone 4s the name will show up like it should but it has the persons current phone number and another or their old number listed under other. Its not in my contacts on my laptop anywhere so how do I delete that old number, I have looked in my phone contacts its not there but its like the email addressess show up to if you start typing an email address will show up even if its not one in your contacts.

    Did you manage to resolve this issue?
    I called Apple Care, tried various things that did not work, then completely reset my iPhone 5 and restored from a recent backup. That worked for a day or so, then the definct "other" number was again offered when I started typing the name of a contact whom I wanted to text.

  • Oracle Error 01034 After attempting to delete a large number of rows

    I sent the command to delete a large number of rows from a table in an oracle database (Oracle 10G / Solaris). The database files are located at /dbo partition. Before the command the disk space utilization was at 84% and now it is at 100%.
    SQL Command I ran:
    delete from oss_cell_main where time < '30 jul 2009'
    If I try to connect to the database now I get the following error:
    ORA-01034: ORACLE not available
    df -h returns the following:
    Filesystem size used avail capacity Mounted on
    /dev/md/dsk/d6 4.9G 5.0M 4.9G 1% /db_arch
    /dev/md/dsk/d7 20G 11G 8.1G 59% /db_dump
    /dev/md/dsk/d8 42G 42G 0K 100% /dbo
    I tried to get the space back by deleting all the data in the table oss_cell_main :
    drop table oss_cell_main purge
    But no change in df output.
    I have tried solving it myself but could not find sufficient directed information. Even pointing me to the right documentation will be higly appreciated. I have already looking at the following:
    du -h :
    du -h8K ./lost+found
    1008M ./system/69333
    1008M ./system
    10G ./rollback/69333
    10G ./rollback
    27G ./data/69333
    27G ./data
    1K ./inx/69333
    2K ./inx
    3.8G ./tmp/69333
    3.8G ./tmp
    150M ./redo/69333
    150M ./redo
    42G .
    I think its the rollback folder that has increased in size immensely.
    SQL> show parameter undo
    NAME TYPE VALUE
    undo_management string AUTO
    undo_retention integer 10800
    undo_tablespace string UNDOTBS1
    select * from dba_tablespaces where tablespace_name = 'UNDOTBS1'
    TABLESPACE_NAME BLOCK_SIZE INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS
    MAX_EXTENTS PCT_INCREASE MIN_EXTLEN STATUS CONTENTS LOGGING FOR EXTENT_MAN
    ALLOCATIO PLU SEGMEN DEF_TAB_ RETENTION BIG
    UNDOTBS1 8192 65536 1
    2147483645 65536 ONLINE UNDO LOGGING NO LOCAL
    SYSTEM NO MANUAL DISABLED NOGUARANTEE NO
    Note: I can reconnect to the database for short periods of time by restarting the database. After some restarts it does connect but for a few minutes only but not long enough to run exp.

    Check the alert log for errors.
    Select file_name, bytes from dba_data_files order by bytes;
    Try to shrink some datafiles to get space back.

  • How can I trash a large number of Emails quickly from my iPod touch rather than using the one-at-a-time Edit method?

    How can I trash a large number of Emails quickly from my iPod touch rather than using the one-at-a-time Edit method?

    Once you tap on edit, you can select multiple emails, the tap archive.

  • I have accidentally deleted a large number of develped images in Lightroom before I did a backup. I reimported the original raw files back into Lightroom hoping the develop settings would be re-established but no luck. Notice system mau have done an auto-

    Question?
    I have accidentally deleted a large number of develped images in Lightroom before I did a backup. I reimported the original raw files back into Lightroom hoping the develop settings would be re-established but no luck. Notice system mau have done an auto-backup as have an lrcat-journal file. Can I use this to restore my develop settings. I also have jpgs generated from all the deleted images.

    Hello,
    if you have a backup of your catalog you can do the following:
    1. Backup your catalog first
    2. Restore your backup catalog to some location
    3. Open your current catalog and select "files->import from another catalog".
    4. Select your backup catalog and your lost images. LR ask you if you want to overwrite the current settings or save them as a virtual copy.
    As an alternativ you can open your backup catalog, select the "lost" images and save the development settings as xmp sidecar fiels (using ctrl-s). Then open your current catalog, seletct the images and use "Metadata->Read Metadata from files".

Maybe you are looking for

  • Macbook Pro Earphone/Headphone Problem

    Hello. Whenever I plug my earphone/headphone into the headphone jack, the music or sound coming out of the earphones will increase quickly and then suddenly drop back to its 'normal' sound. This happens within 1-2 seconds of plugging it in. I contact

  • Po list containing discount

    Hi MM experts Could any one help, How to List PO based on discounts with discount value? Thanks in advance Regards Senthilnathan

  • I want to display the character alt+0183 in my JLabel

    This is driving me crazy... can anyone help?? thanks Tom

  • IOS 4.2 and 3G signal strength

    I have been having a really hard time with my 3G maintaining solid reception at home. Granted, I live in a mountainous area, but it's one of those circumstances where other phones on the same AT&T network are getting much stronger signals and I'm bar

  • BT FON - I can see the neighbours PC?

    I can see my neighbours PC listed in my Windows Network, when I try to access it, it is blank, but I can see his computers name.  Does the same work for him, will he be able to see all the devices I have connected and the names of those devices? I ta