Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > Oracle
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 28th, 2003, 12:11 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delete records from Oracle 8i goes VERY slow

OK, first of all, I'm not an experienced Oracle Developer, I write mostly in .NET and my current project involves an Oracle 8i database.

We have a production database where a lot of production results are stored in 4 tables t_car_hmi, t_comps_hmi, t_bolts_hmi and t_results_hmi.
Every car can have a lot of comps, every comp can have a lot of bolts, and every bolt can have a lot of results so not very complicated I guess...

We add results via SQL (builded up based on an XML file) and this goes very smoothly.
However, If we want to remove entries from this tables, we have some major speed issues...

I wrote this little procedure based on for loops that goes trough each table




Code:
  BEGIN 
  FOR SERIAL_ID IN (SELECT SERIAL_ID FROM T_CAR_HMI WHERE T_CAR_HMI.MIX >= 
'0464730' AND T_CAR_HMI.MIX <= '0464739') LOOP 
    FOR COMPS_ID IN (SELECT COMPS_ID FROM T_COMPS_HMI WHERE 
T_COMPS_HMI.CAR_ID = SERIAL_ID.SERIAL_ID) LOOP 
      FOR BOLTS_ID IN (SELECT BOLTS_ID FROM T_BOLTS_HMI WHERE 
T_BOLTS_HMI.COMPS_ID = COMPS_ID.COMPS_ID) LOOP 
          DELETE FROM T_RESULTS_HMI WHERE T_RESULTS_HMI.BOLTS_ID = 
BOLTS_ID.BOLTS_ID; 
          DELETE FROM T_BOLTS_HMI WHERE T_BOLTS_HMI.BOLTS_ID = 
BOLTS_ID.BOLTS_ID; 
      END LOOP; 
      COMMIT; 
      DELETE FROM T_COMPS_HMI WHERE T_COMPS_HMI.COMPS_ID = 
COMPS_ID.COMPS_ID; 
    END LOOP; 
    COMMIT; 
    DELETE FROM T_CAR_HMI WHERE T_CAR_HMI.SERIAL_ID = SERIAL_ID.SERIAL_ID; 
  END LOOP; 
  COMMIT; 
END;
This took a minute to complete...

I tried then the following procedure (after rewriting the data to the DB)


Code:
  DELETE FROM t_results_hmi 
  WHERE t_results_hmi.bolts_id in
  (SELECT t_bolts_hmi.bolts_id
  FROM t_bolts_hmi, 
         t_comps_hmi , 
         t_car_hmi 
  WHERE t_bolts_hmi.comps_id = t_comps_hmi.comps_id 
  AND t_comps_hmi.car_id = t_car_hmi.serial_id 
  AND t_car_hmi.mix >= '0464730' 
  AND t_car_hmi.mix <= '0464739');
  COMMIT;

  DELETE FROM t_bolts_hmi 
  WHERE t_bolts_hmi.comps_id in
  (SELECT t_comps_hmi.comps_id 
  FROM   t_comps_hmi , 
         t_car_hmi 
  WHERE t_comps_hmi.car_id = t_car_hmi.serial_id 
  AND t_car_hmi.mix >= '0464730' 
  AND t_car_hmi.mix <= '0464739'); 
  COMMIT;

  DELETE FROM t_comps_hmi 
  WHERE t_comps_hmi.car_id in
  (SELECT t_car_hmi.serial_id
  FROM t_car_hmi 
  WHERE t_car_hmi.mix >= '0464730' 
  AND t_car_hmi.mix <= '0464739'); 
  COMMIT; 

  DELETE FROM t_car_hmi 
  WHERE t_car_hmi.mix >= '0464730' 
  AND t_car_hmi.mix <= '0464739'; 
  COMMIT; 
END;
It took over 4 minutes to complete...

Does anyone have an idea how to increase the speed, because we did this test with 10 records while we have thousands of records in a day...

Thanks;
Dries
  #2 (permalink)  
Old February 5th, 2004, 03:14 PM
Authorized User
 
Join Date: Feb 2004
Location: Leeds, West Yorkshire, United Kingdom.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just a quick query (excuse the pun) but how many records does each table have (very roughly) and how many indexes do you have on these tables?
The reason I'm asking is...
If you have an enormous database, it obviously makes sense that certain rows are indexed, especially if you're creating a lot of joined queries using these rows..

However there's a huge trade-off when performing UPDATE, INSERT and DELETE actions on the database, particularly in situations shown in your sample code.

If this is the case that you have a large number of indexes in tables where you're wanting to delete rows, there's no simple answer only to re-asses what is more important, speed of queries or speed of DDL DML etc?

Take a look at what indexes you have and decide what you need / don't need and re-evaluate whether they can be dropped or kept.

Finally, as possibly a really glib comment, if you're running Oracle 8i on an XP machine ( as I have in the past) this is a really unstable thing to do, not sure of the exact reasons but they really don't like each other. We've had to upgrade to Oracle 9i to overcome the related problems.

Regards

Simon


Don't think, do!
  #3 (permalink)  
Old February 25th, 2004, 07:37 AM
Registered User
 
Join Date: Feb 2004
Location: Mumbai, Maharashtra, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dpmatrix Send a message via Yahoo to dpmatrix
Default

:) WELL, WHENEVER YOU DELETE OR INSERT WITH "IN" CLAUSE IN SQL, JOIN IDS FROM OUTER SQL TO INNER SQL AND YOUR RESULTS WILL SPEED UP !

FOR EXAMPLE

DELETE FROM TABLE1 WHERE A.ID IN
(SELECT B.ID FROM TABLE2 WHERE A.ID=B.ID)

WATCH FOR A.ID=B.ID <--- WHICH IS GOING TO SPEED UP YOUR OPERATION KEEPING THE RESULTS SAME

  #4 (permalink)  
Old March 11th, 2004, 12:41 PM
aas aas is offline
Authorized User
 
Join Date: Mar 2004
Location: Moscow, , Russia.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to aas
Default

Quote:
quote:Originally posted by dpmatrix
 :) WELL, WHENEVER YOU DELETE OR INSERT WITH "IN" CLAUSE IN SQL, JOIN IDS FROM OUTER SQL TO INNER SQL AND YOUR RESULTS WILL SPEED UP !

FOR EXAMPLE

DELETE FROM TABLE1 WHERE A.ID IN
(SELECT B.ID FROM TABLE2 WHERE A.ID=B.ID)

WATCH FOR A.ID=B.ID <--- WHICH IS GOING TO SPEED UP YOUR OPERATION KEEPING THE RESULTS SAME
more the best if your example rewrite as:

  DELETE FROM TABLE1 A
   WHERE EXISTS (SELECT 1
                   FROM TABLE2 B
                  WHERE B.ID=A.ID)

Because, if you have more records where B.ID=A.ID, subquery will take only first record from scope and not be find next.

If do execute command, from your example: for each record of outer query will be selected N records (B.ID=A.ID) from subquery, it's no good ;)

 


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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC connections to Oracle 8i GuidoDB SQL Server 2000 1 January 23rd, 2007 03:17 PM
Oracle 8i database files on Palm wwwdirzala Oracle 0 February 10th, 2005 06:59 AM
Connecting Oracle 8i - OracleDeveloperSuite10g shamsad Oracle 0 April 10th, 2004 05:15 AM
Installing Oracle 8i and Developer 6 mythinky Oracle 2 March 9th, 2004 12:18 AM
connection for Oracle 8i kosla78 ADO.NET 1 September 3rd, 2003 02:41 AM



All times are GMT -4. The time now is 10:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.