473,729 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subquery Performance

26 New Member
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 1941
docdiesel
297 Recognized Expert Contributor
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
bharadwajrv
26 New Member
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 Recognized Expert Contributor
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
4578
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
8350
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 will work on preparing SQL statements that will create the tables, insert sample record and run the SP. I would hope people will look at my SP and give me any hints on how I can better write the SP.
57
25520
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
5413
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 7.2 environment, the choices the optimizer makes often seem flaky. But this last example really floored me. I was hoping someone could explain why I get worse response time when the optimizer uses two indexes, than when it uses one. Some context:
0
1765
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. i tracked it back to the way the queries are push-downed to the
22
3353
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 (subquery)'. PG always seems to want to do a sequential scan of the bar table. I wish there were a way of telling PG, "use the index on baz in your plan, because I know that the subquery will return very few results". Where it really matters, I have...
5
2239
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" query attempts to build a result set using a correlated subquery. The part causing the error is that the correlated subquery is part of a derived table (joining 3 tables). Trying to run the query takes a long time and the more records in the...
0
3299
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 queries yes or no, I have prepared an example. The example is a database with the following tables: *table person with fields: -persid: autoincrement id -name: name of the person *table material with fields: -materialid: autoincrement id
10
4297
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 application looks for existing rows in the table...if they already exist then it updates otherwise inserts them. The table is pretty large, around 6.5 million rows.
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.