473,563 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

foreign key constraint slows down UPDATE performance

I encountered a performance problem with UPDATE statement and foreign
key constraints.

There are two tables involved: A parent table A and a child table B:

create table A(
ID CHAR(15) NOT NULL CONSTRAINT APK PRIMARY KEY,
val NUMERIC(10))

create table B(ID CHAR(15) NOT NULL CONSTRAINT BPK PRIMARY KEY,
AID CHAR(15),
val NUMERIC(10))

CREATE INDEX B_AID ON B(AID)

ALTER TABLE B
ADD CONSTRAINT TOPARENT FOREIGN KEY(AID)
REFERENCES A ON DELETE CASCADE
Table A is populated with 7100 rows and table B with 41300 rows.

If I run an UPDATE statement like this one:

UPDATE B SET AID='qwertzuiop asdfg' WHERE ID='yxcvbn12345 6789'

then this statement takes an average of about 11ms. If I drop the
foreign key constraint, then it takes only about 2ms in average.
(Adding the constraint again leads to 11ms again)

Is this normal behavior, that the presence of a foreign key constraint
slows down UPDATE performance by a factor of 5? I guess that it is not
normal at all, so what I'm doing wrong? Perhaps A bad configuration?

(I'm using DB2 UDB 8.1 PE with FixPak 2, Windows XP)

Gerald
Nov 12 '05 #1
5 5003
How does the plan look like? Are you having appropriate indexes?

Cheers
Serge
Nov 12 '05 #2
"Serge Rielau" <sr*****@ca.eye beem.com> wrote in message news:<bo******* ***@hanover.tor olab.ibm.com>.. .
How does the plan look like? Are you having appropriate indexes?


Anything wrong with the following plan?

Access Plan:
-----------
Total Cost: 43.0093
Query Degree: 1

Rows
RETURN
( 1)
Cost
I/O
|
0.333333
FILTER
( 2)
43.0093
4
+-------------+----------+--+-------------------+
1 1 0 0.04
TBSCAN TBSCAN FILTER FILTER
( 3) ( 4) ( 9) ( 11)
0.000126588 21.4686 0.00228914 21.5346
0 2 0 2
| | | |
1 1 1 1
TABFNC: SYSIBM TEMP TBSCAN NLJOIN
GENROW ( 5) ( 10) ( 12)
21.4011 0.000126588 21.5319
2 0 2
| | /----+---\
1 1 1 1
UPDATE TABFNC: SYSIBM TBSCAN IXSCAN
( 6) GENROW ( 13) ( 14)
21.3662 21.4686 0.0633543
2 2 0
/----+---\ | |
1 62 1 94
FETCH TABLE: A62_181 TEMP INDEX: A62_181
( 7) B ( 5) APK
10.7125 21.4011
1 2
/----+----\
1 62
IXSCAN TABLE: A62_181
( 8) B
0.0568729
0
|
62
INDEX: A62_181
BPK
Nov 12 '05 #3
Looks OK. We are working to make TEMP(5)l go away, but until then the plan
is fine.

Cheers
Serge
Nov 12 '05 #4
"Serge Rielau" <sr*****@ca.eye beem.com> wrote in message news:<bo******* ***@hanover.tor olab.ibm.com>.. .
Looks OK. We are working to make TEMP(5)l go away, but until then the plan
is fine.


TEMP! This is the deciding clue, Thank You! My system temporary
tablespace was DMS and I changed it now to SMS to see what would
happen, and: the performance problem has gone away!

But I always thought DMS means high-performance. Why does this not
hold for temporary tablespaces?

Gerald
Nov 12 '05 #5
"Gerald Khin" <g.****@ids-scheer.de> wrote in message
news:4c******** *************** ***@posting.goo gle.com...
"Serge Rielau" <sr*****@ca.eye beem.com> wrote in message

news:<bo******* ***@hanover.tor olab.ibm.com>.. .
Looks OK. We are working to make TEMP(5)l go away, but until then the plan is fine.


TEMP! This is the deciding clue, Thank You! My system temporary
tablespace was DMS and I changed it now to SMS to see what would
happen, and: the performance problem has gone away!

But I always thought DMS means high-performance. Why does this not
hold for temporary tablespaces?

Gerald


SMS automatically allocates space as needed. DMS only has the space you
allocate via containers. When using DMS you should increase the size of the
temporary tablespace to several times as big as the largest table (if
possible). DMS will only perform better if you allocate the containers in an
efficient manner (containers placed on separate physical drives and
controllers if possible). There are different optimal configurations for
regular disk and RAID striped disks.
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2616
by: Jeremiah Jacks | last post by:
I just upgraded to MySQL 4.0.14-standard for RedHat Linux and am using = the pre-compiled binaries. I have a database with INNODB tables. When I insert a row into one of the child tables, I get the following = MySQL error: INSERT INTO product_access_level (product_id,access_level_id) VALUES
2
39417
by: Gunnar Vøyenli | last post by:
Hi! For the sake of simplicity, I have three tables, Employee, Department and Work Employee >---- Department \ / \ / ^ ^ Work
31
3336
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific customer subtypes: 1 - business, 2 - home, 3 - university
0
1418
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A stored procedure updates a row in C, adds a row each in B & C. I get an integrity violation. All the foreign keys are deferrable, and the stored...
13
3683
by: Bob Stearns | last post by:
Why is the following constraint invalid? I want to make sure that every row in IS3.ANIMALS_PRIV_INDEXES matches one of those in IS3.table_var_defn with part of the primary key fixed. Since this is illegal with the following message, how do I achieve this result? The last thing below is a working constraint from another table. ALTER TABLE...
8
3516
by: wespvp | last post by:
I am using PostgreSQL 7.4.1 on RedHat 7.2. The query I am executing is something like (I replaced all the return values with 'count'): db=> explain select count(*) from messages m join (select * from message_recipients r join addresses a on a.Address_Key=r.Recipient where a.Address='lra.edi@edi.cma-cgm.com') as foo on...
14
5771
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where the problem is. I keep getting errors like (the first is my debug output): NOTICE: last cycle is: 11 WARNING: Error occurred while executing...
5
2485
by: Bob Stearns | last post by:
For good and sufficient reasons I wish to insure that a primary key of table 1 is not a primary key of table 2. The following does not work: ALTER TABLE IS3.AUCTION_SUPER_CATEGORIES ADD CONSTRAINT code_not_fk check(code not in (select code from IS3.AUCTION_CATEGORIES where auction_id=auction_id)) Is there any way other than a trigger...
0
1410
by: ckiraly | last post by:
Greetings everyone - I am new to MSSQL 2005, and have started a database design project for my company. The issue I have is in a specific instance of foreign key creation. Here is the whole situation: I have a ContactInfo table that has several fields, including a CreatedByUserID, and a LastModifiedUserID, that are both INT fields. I...
0
7583
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...
0
8106
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...
1
7638
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...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
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...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
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
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.