473,396 Members | 1,966 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.

Poor insert performance

I was trying to copy a range of records from a table to the same table
with a small modification. I was wondering why this takes a long time
compared to just doing a subselect from that table and insert to a new
table (without constraints). Could it be a problem with the constraints
checking capability or the index maintenance? The subselect itself
takes a small time, so that will not be the problem...

Before executing the query I tried to set the constraints checking off
by the following statements; but it doesn't work as I expected:

SET INTEGRITY FOR DB2INST1.ASSPC OFF
SET INTEGRITY FOR DB2INST1.ASSPCACT OFF
SET INTEGRITY FOR DB2INST1.ASSPCACTSIBLING OFF

Any suggestions are welcome...

Regards, Peter

TABLE:
======

CREATE TABLE "DB2INST1"."ASSPC" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH +1
INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE NO CACHE
NO ORDER ),
"VERSIONID" INTEGER NOT NULL WITH DEFAULT 1,
"ASSVS_ID" INTEGER NOT NULL,
"ASSVS_VERSIONID" INTEGER NOT NULL,
"VS_PC_ID" INTEGER NOT NULL,
"VS_PC_VERSIONID" INTEGER NOT NULL,
"CREATE" TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP,
"DELETE" TIMESTAMP,
"UPDATE" TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP,
"MULTIFAC" DECIMAL(4,1)
) IN "USERSPACE1" ;
PRIMARY KEY:
============

ALTER TABLE "DB2INST1"."ASSPC"
ADD CONSTRAINT "CC1084276791058" PRIMARY KEY ("ID", "VERSIONID");

FOREIGN KEYS:
=============

ALTER TABLE "DB2INST1"."ASSPC"
ADD CONSTRAINT "CC1084276820350" FOREIGN KEY ("ASSVS_ID",
"ASSVS_VERSIONID")
REFERENCES "DB2INST1"."ASSVS" ("ID", "VERSIONID")
ON DELETE RESTRICT
ON UPDATE RESTRICT
NOT ENFORCED
ENABLE QUERY OPTIMIZATION;

ALTER TABLE "DB2INST1"."ASSPC"
ADD CONSTRAINT "CC1084276849722" FOREIGN KEY ("VS_PC_ID",
"VS_PC_VERSIONID")
REFERENCES "DB2INST1"."VS_PC" ("ID", "VERSIONID")
ON DELETE RESTRICT
ON UPDATE RESTRICT
NOT ENFORCED
ENABLE QUERY OPTIMIZATION;
Query:
======

INSERT INTO
DB2INST1.ASSPC
(
ID,
VERSIONID,
ASSVS_ID,
ASSVS_VERSIONID,
VS_PC_ID,
VS_PC_VERSIONID,
MULTIFAC
)
(
SELECT
DB2INST1.ASSPC.ID,
2,
DB2INST1.ASSVS.ID AS ASS_VS_ID,
DB2INST1.ASSVS.VERSIONID AS ASS_VS_VERSIONID,
DB2INST1.VS_PC.ID AS VS_PC_ID,
DB2INST1.VS_PC.VERSIONID AS VS_PC_VERSIONID,
DB2INST1.ASSPC.MULTIFAC
FROM
DB2INST1.ORG,
DB2INST1.ORG_VS,
DB2INST1.VS,
DB2INST1.DR,
DB2INST1.VS_PC,
DB2INST1.ACTIVITY,
DB2INST1.ASSPC,
DB2INST1.ASSVS
WHERE
DB2INST1.ORG_VS.ORG_ID = DB2INST1.ORG.ID
AND DB2INST1.ORG_VS.ORG_VERSIONID = DB2INST1.ORG.VERSIONID
AND DB2INST1.VS.DR_ID = DB2INST1.DR.ID
AND DB2INST1.VS.DR_VERSIONID = DB2INST1.DR.VERSIONID
AND DB2INST1.ORG_VS.VS_ID = DB2INST1.VS.ID
AND DB2INST1.ORG_VS.VS_VERSIONID = DB2INST1.VS.VERSIONID
AND DB2INST1.VS_PC.VS_ID = DB2INST1.VS.ID
AND DB2INST1.VS_PC.VS_VERSIONID = DB2INST1.VS.VERSIONID
AND DB2INST1.ASSPC.VS_PC_ID = DB2INST1.VS_PC.ID
AND DB2INST1.ASSPC.VS_PC_VERSIONID = DB2INST1.VS_PC.VERSIONID
AND DB2INST1.ASSVS.ORG_VS_ID = DB2INST1.ORG_VS.ID
AND DB2INST1.ASSVS.ORG_VS_VERSIONID = DB2INST1.ORG_VS.VERSIONID
AND DB2INST1.ASSPC.ASSVS_ID = DB2INST1.ASSVS.ID
AND DB2INST1.ASSPC.ASSVS_VERSIONID = DB2INST1.ASSVS.VERSIONID
AND DB2INST1.ORG.DELETE IS NULL
AND DB2INST1.ORG_VS.DELETE IS NULL
AND DB2INST1.VS.DELETE IS NULL
AND DB2INST1.DR.DELETE IS NULL
AND DB2INST1.VS_PC.DELETE IS NULL
AND DB2INST1.ACTIVITY.DELETE IS NULL
AND DB2INST1.ASSPC.DELETE IS NULL
AND DB2INST1.ASSVS.DELETE IS NULL

AND DB2INST1.ASSPC.VERSIONID = 1
AND DB2INST1.ORG.ID = 1
AND DB2INST1.ORG.VERSIONID = 1
)

Nov 12 '05 #1
1 2523
nomorems wrote:
I was trying to copy a range of records from a table to the same table
with a small modification. I was wondering why this takes a long time
compared to just doing a subselect from that table and insert to a new
table (without constraints). Could it be a problem with the constraints
checking capability or the index maintenance? The subselect itself
takes a small time, so that will not be the problem...

Before executing the query I tried to set the constraints checking off
by the following statements; but it doesn't work as I expected:

SET INTEGRITY FOR DB2INST1.ASSPC OFF
SET INTEGRITY FOR DB2INST1.ASSPCACT OFF
SET INTEGRITY FOR DB2INST1.ASSPCACTSIBLING OFF

Any suggestions are welcome...

Regards, Peter

TABLE:
======

CREATE TABLE "DB2INST1"."ASSPC" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH +1
INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE NO CACHE
NO ORDER ),
"VERSIONID" INTEGER NOT NULL WITH DEFAULT 1,
"ASSVS_ID" INTEGER NOT NULL,
"ASSVS_VERSIONID" INTEGER NOT NULL,
"VS_PC_ID" INTEGER NOT NULL,
"VS_PC_VERSIONID" INTEGER NOT NULL,
"CREATE" TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP,
"DELETE" TIMESTAMP,
"UPDATE" TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP,
"MULTIFAC" DECIMAL(4,1)
) IN "USERSPACE1" ;
PRIMARY KEY:
============

ALTER TABLE "DB2INST1"."ASSPC"
ADD CONSTRAINT "CC1084276791058" PRIMARY KEY ("ID", "VERSIONID");

FOREIGN KEYS:
=============

ALTER TABLE "DB2INST1"."ASSPC"
ADD CONSTRAINT "CC1084276820350" FOREIGN KEY ("ASSVS_ID",
"ASSVS_VERSIONID")
REFERENCES "DB2INST1"."ASSVS" ("ID", "VERSIONID")
ON DELETE RESTRICT
ON UPDATE RESTRICT
NOT ENFORCED
ENABLE QUERY OPTIMIZATION;

ALTER TABLE "DB2INST1"."ASSPC"
ADD CONSTRAINT "CC1084276849722" FOREIGN KEY ("VS_PC_ID",
"VS_PC_VERSIONID")
REFERENCES "DB2INST1"."VS_PC" ("ID", "VERSIONID")
ON DELETE RESTRICT
ON UPDATE RESTRICT
NOT ENFORCED
ENABLE QUERY OPTIMIZATION;
Query:
======

INSERT INTO
DB2INST1.ASSPC
(
ID,
VERSIONID,
ASSVS_ID,
ASSVS_VERSIONID,
VS_PC_ID,
VS_PC_VERSIONID,
MULTIFAC
)
(
SELECT
DB2INST1.ASSPC.ID,
2,
DB2INST1.ASSVS.ID AS ASS_VS_ID,
DB2INST1.ASSVS.VERSIONID AS ASS_VS_VERSIONID,
DB2INST1.VS_PC.ID AS VS_PC_ID,
DB2INST1.VS_PC.VERSIONID AS VS_PC_VERSIONID,
DB2INST1.ASSPC.MULTIFAC
FROM
DB2INST1.ORG,
DB2INST1.ORG_VS,
DB2INST1.VS,
DB2INST1.DR,
DB2INST1.VS_PC,
DB2INST1.ACTIVITY,
DB2INST1.ASSPC,
DB2INST1.ASSVS
WHERE
DB2INST1.ORG_VS.ORG_ID = DB2INST1.ORG.ID
AND DB2INST1.ORG_VS.ORG_VERSIONID = DB2INST1.ORG.VERSIONID
AND DB2INST1.VS.DR_ID = DB2INST1.DR.ID
AND DB2INST1.VS.DR_VERSIONID = DB2INST1.DR.VERSIONID
AND DB2INST1.ORG_VS.VS_ID = DB2INST1.VS.ID
AND DB2INST1.ORG_VS.VS_VERSIONID = DB2INST1.VS.VERSIONID
AND DB2INST1.VS_PC.VS_ID = DB2INST1.VS.ID
AND DB2INST1.VS_PC.VS_VERSIONID = DB2INST1.VS.VERSIONID
AND DB2INST1.ASSPC.VS_PC_ID = DB2INST1.VS_PC.ID
AND DB2INST1.ASSPC.VS_PC_VERSIONID = DB2INST1.VS_PC.VERSIONID
AND DB2INST1.ASSVS.ORG_VS_ID = DB2INST1.ORG_VS.ID
AND DB2INST1.ASSVS.ORG_VS_VERSIONID = DB2INST1.ORG_VS.VERSIONID
AND DB2INST1.ASSPC.ASSVS_ID = DB2INST1.ASSVS.ID
AND DB2INST1.ASSPC.ASSVS_VERSIONID = DB2INST1.ASSVS.VERSIONID
AND DB2INST1.ORG.DELETE IS NULL
AND DB2INST1.ORG_VS.DELETE IS NULL
AND DB2INST1.VS.DELETE IS NULL
AND DB2INST1.DR.DELETE IS NULL
AND DB2INST1.VS_PC.DELETE IS NULL
AND DB2INST1.ACTIVITY.DELETE IS NULL
AND DB2INST1.ASSPC.DELETE IS NULL
AND DB2INST1.ASSVS.DELETE IS NULL

AND DB2INST1.ASSPC.VERSIONID = 1
AND DB2INST1.ORG.ID = 1
AND DB2INST1.ORG.VERSIONID = 1
)

SET INTEGRITY OFF pretty much takes the table out of the game. You will
not be able to operate DML (such as INSERT or SELECT) on the table.
Altering the constraints to NOT ENFORCED will do the trick.
After the INSERT you can then SET INTEGRITY OFF,
ALTER the constraints back to ENFORCED,
and then validate them in one shot by flipped SET INTEGRITY back on
either using the options of your choice.
If you don't use SET INTEGRITY OFF each ALTER TABLE statement willchech
the modified constraint right away, potentially resulting in more scans
=> longer time to finish.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

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

Similar topics

18
by: pb648174 | last post by:
Greeting, below is the complete SQL taken from aspfaq.com (retrieved from this newsgroup I believe) The query takes about two minutes to run. Does anybody have a better set based way (sub-second...
10
by: AC Slater | last post by:
I have 1 table (out of many) that has very poor performance when performing a select into on. The select statement is called multiple times. We've found each call to take almost 1 second... we...
1
by: Evan Smith | last post by:
My database is suffering from poor performance of late. Reports that used to run in a reasonable time, now take a while. The explain output show that the query is fully indexed, and the statistics...
3
by: sac | last post by:
I am using DB2 v8.1 on UNIX. At times the database shows extremely poor performance. I do not have dba/admin rights nor do I have the web based client for db2 v8.1. I have only command line...
4
by: Bill Thorne | last post by:
We have a COM object that has been wrappered for use in .NET and which can make calls which can take a while to execute. These are mainframe integration calls that might perform a lot of data...
20
by: John Mark Howell | last post by:
I had a customer call about some C# code they had put together that was handling some large arrays. The performance was rather poor. The C# code runs in about 22 seconds and the equivalent...
4
by: Jim Devenish | last post by:
I have converted an Access back-end to SQL Server back-end but am having some problems. The Access to Access application has been running well for some years. I have successfully copied all the...
1
by: Billy | last post by:
Hi All, I'm attempting to use the MapNetworkDrive <snippedbelow from entire code below with very poor performance results. Basically, I have very small 73kb text files that are rewritten daily...
4
by: joa2212 | last post by:
Hello everybody, I'm posting this message because I'm quiet frustrated. We just bought a software from a small software vendor. In the beginning he hosted our application on a small server at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.