473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create 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='qwertzuiopasdfg' WHERE ID='yxcvbn123456789'

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 4990
How does the plan look like? Are you having appropriate indexes?

Cheers
Serge
Nov 12 '05 #2
"Serge Rielau" <sr*****@ca.eyebeem.com> wrote in message news:<bo**********@hanover.torolab.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.eyebeem.com> wrote in message news:<bo**********@hanover.torolab.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.google.c om...
"Serge Rielau" <sr*****@ca.eyebeem.com> wrote in message

news:<bo**********@hanover.torolab.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
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...
2
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
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...
0
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...
13
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...
8
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...
14
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...
5
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...
0
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...
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
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...
1
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...
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.