Home » RDBMS Server » Performance Tuning » delete procedure taking time (oracle,9i,unix)
delete procedure taking time [message #486980] Tue, 21 December 2010 20:45 Go to next message
vickey_sagar1
Messages: 77
Registered: August 2007
Location: pune
Member

Hi All,

Below pl/sql procedure is taking more than 1 hour. Count in history table is 55156678 and table is having two indexes. Could you please let me know what things i need check.

DECLARE
   v_pub_date_cnt   NUMBER;
   v_pub_date_min   erp_booking_hist.publish_date%TYPE;
BEGIN
   BEGIN
      SELECT   COUNT (DISTINCT publish_date), MIN (publish_date)
        INTO   v_pub_date_cnt, v_pub_date_min
        FROM   erp_booking_hist;
   EXCEPTION
      WHEN OTHERS
      THEN
         v_pub_date_cnt := 0;
   END;

   IF v_pub_date_cnt > 5
   THEN
      DELETE FROM   erp_booking_hist
            WHERE   publish_date = v_pub_date_min;

      COMMIT;
   END IF;
END;


Thanks,
sagar
Re: delete procedure taking time [message #486981 is a reply to message #486980] Tue, 21 December 2010 20:52 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Remove complete EXCEPTION handler & run the modified code.

FWIW - No PL/SQL is required.
Can accomplish the same results by using only SQL.

[Updated on: Tue, 21 December 2010 22:12]

Report message to a moderator

Re: delete procedure taking time [message #486985 is a reply to message #486981] Tue, 21 December 2010 22:42 Go to previous messageGo to next message
vickey_sagar1
Messages: 77
Registered: August 2007
Location: pune
Member

Could you let me know the query.
Re: delete procedure taking time [message #486986 is a reply to message #486985] Tue, 21 December 2010 22:45 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please realize that we don't have your tables & we don't have your data.
Therefore we can't run, test or improve your posted SQL.
It would be helpful if you provided DDL (CREATE TABLE ...) for tables involved.
It would be helpful if you provided DML (INSERT INTO ...) for test data.
It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/
It would be helpful if you provided expected/desired results & a detailed explanation how & why the test data gets transformed or organized.

How many rows do you expect/desire to be deleted by posted PL/SQL?
Re: delete procedure taking time [message #486988 is a reply to message #486986] Tue, 21 December 2010 22:59 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
DELETE FROM erp_booking_hist
WHERE  publish_date = (SELECT min_publish_date
                       FROM   (SELECT MIN(publish_date) min_publish_date,
                                      COUNT(publish_date)
                               FROM   erp_booking_hist
                               HAVING COUNT(publish_date) > 5))

/  


assumes no time component exists within PUBLISH_DATE
Re: delete procedure taking time [message #486992 is a reply to message #486988] Tue, 21 December 2010 23:11 Go to previous messageGo to next message
vickey_sagar1
Messages: 77
Registered: August 2007
Location: pune
Member

publish date value is like '10/12/2010 07:24:49 PM'
Re: delete procedure taking time [message #486993 is a reply to message #486992] Tue, 21 December 2010 23:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SELECT min_publish_date
FROM   (SELECT MIN(publish_date) min_publish_date,
               COUNT(publish_date)
        FROM   erp_booking_hist
        HAVING COUNT(publish_date) > 5)
/  

[Updated on: Tue, 21 December 2010 23:22]

Report message to a moderator

Re: delete procedure taking time [message #486998 is a reply to message #486986] Wed, 22 December 2010 00:01 Go to previous message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
Looks like you could be trying to delete 10% or more of the table (5M rows). Deleting that many rows is going to take a heap of time, because every block impacted must be rewritten, which in turn generates the same amount of IO on the UNDO segments and the Archive logs.

It would almost certainly be faster to rebuild the table from scratch. Or perhaps you could partition the table on the PUBLISH_DATE and TRUNCATE PARTITION instead of deleting.

Ross Leishman
Previous Topic: Change in explain plan due to Oracle upgrade
Next Topic: Temp tablespace full
Goto Forum:
  


Current Time: Wed May 01 02:15:12 CDT 2024