473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Subquery Performance

Hi...

i need to know which approach is good in-terms of performance while deleting the records from two tables...

Here is my table struct:
Expand|Select|Wrap|Line Numbers
  1. Master table (table1)
  2. -------------------------------
  3. MasterTable_ID (PK)
  4. App_ID (FK)
  5.  
  6.  
  7. Tran table (table2)
  8. -------------------------------
  9. Tran_ID (PK)
  10. MasterTable_ID (FK)
  11.  

I need to delete list of records (from both table1 and table2) associated for a given App_ID...

so there are two possibility

[1] First get list of records from Table1 for a given App_ID and delete its associated records in table2 (using loop) and in last-step delete records from table1


[2] use Subquery to delete all records from Table2 and delete records from table1

(there will be max 30 trans-records in table2 for a given MasterTable record)

I think [2] is appropriate, but how do i convince my QA team subquery does not have performance issue (or is i'm wrong here)

Cheers
Venu
Oct 23 '07 #1
3 1920
docdiesel
297 Expert 100+
Hi Venu,

why don't you alter the foreign key constraint to ON DELETE CASCADE ? That way you just have to delete the rows on the main table and DB2 will delete all related rows in other tables automatically. Additionally, this is done in one transaction so you're safe to have an always integer database.

Regards, Bernd
Oct 23 '07 #2
Hi Bernd,

thanks for your reply...

Sorry i forgot to mention that - there is limitation on database, i'm not allowed to create any stored-procedure, triggers and on on in database..... i only need to handle this using SQL statement from the front-end application... ( I know it is weird, but QA does not allow to do this…They say it is maintenance overhead )

Can u advise me on using the Subquery performance...

Thanks
Venu

Hi Venu,

why don't you alter the foreign key constraint to ON DELETE CASCADE ? That way you just have to delete the rows on the main table and DB2 will delete all related rows in other tables automatically. Additionally, this is done in one transaction so you're safe to have an always integer database.

Regards, Bernd
Oct 24 '07 #3
docdiesel
297 Expert 100+
Hi,

sounds to me that the overhead is not in maintenance but in bureaucracy, but however ...

Always leave the control to DB2. Don't try to put this into your program, using loops etc. If your program crashes, you'll never know what happend (or not) to your tables. Further, use a transaction to make sure the database doesn't get messed up. Try something like this:

Expand|Select|Wrap|Line Numbers
  1. START    TRANSACTION;
  2. DELETE   from Tran_table
  3.   WHERE  Tran_table.MasterTable_ID = Master_table.MasterTable_ID
  4.   AND    Master_table.App_ID = x ;
  5. DELETE   from Master_table where App_ID = x ;
  6. COMMIT;
If there're 30 or so tran records per master record, and there's just a couple of rows to delete in Master_table, this should be no problem. Besides, if there's no CASCADE DELETE in the database design, I hope there's at least an index to speed things up?

If there's still a problem with QA, then tell them that it's part of their job to ensure the databases integrity, and that this is always best done from within the database, e.g. using transactions and proper database design.

Good luck,

Bernd
Oct 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
12
by: serge | last post by:
I have an SP that is big, huge, 700-800 lines. I am not an expert but I need to figure out every possible way that I can improve the performance speed of this SP. In the next couple of weeks I...
57
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
0
by: Joerg Ammann | last post by:
hi, os: aix 4.3.3 DB2: version 7 FP3 we are using a federated DB setup, datasource and fed-Db are both V7FP3 (in fact they are on the same server) and are having massiv performance problems....
22
by: Kevin Murphy | last post by:
I'm using PG 7.4.3 on Mac OS X. I am disappointed with the performance of queries like 'select foo from bar where baz in (subquery)', or updates like 'update bar set foo = 2 where baz in...
5
by: steven.fafel | last post by:
I am running 2 versions of a correlated subquery. The two version differ slightly in design but differ tremendously in performance....if anyone can answer this, you would be awesome. The "bad"...
0
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex...
10
by: shsandeep | last post by:
The ETL application loaded around 3000 rows in 14 seconds in a Development database while it took 2 hours to load in a UAT database. UAT db is partitioned. Dev db is not partitioned. the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.