I have a DB2 database with three tables, A, B and C.
The database was created thus:
create database DB alias DB AUTOMATIC STORAGE YES ON /home/db2inst1
using codedeset UTF-8 territory en PAGESIZE 32768
- Table A is 28 columns wide with 1.8 mill. rows and PID is primary
key. The columns mostly has int-types, but some are varchar(200-400).
Index: PID - Table B is 7 columns wide with 14 mill. rows and primary key PID_L.
It also has columns C_SOURCE and ROW_COUNT. Index: PID,C_SOURCE - Table C is 20 columns wide with 14 mill. rows and primary key PID_S.
It also has a column ROLE. Index: PID,PID_S
All tables have the column PID
I need a table which aggregates some info in Table B and C. The query to select the appropriate items is:
SELECT
T.*,
(
SELECT
COALESCE(SUM(ROW_COUNT),0)
FROM
C as ITS,
B as ITL
WHERE
ITS.ROLE = 1
AND ITS.PID = ITL.PID
AND ITS.PID_S = ITL.C_SOURCE
AND ITS.PID = T.PID
) AS RR
FROM
A as T;
When this query is run, the DB2 server quickly uses about 3Gb memory. Using top, the CPU usage, however, rarely goes beyond 5%, with some jumps into about 13%. The DB2 server is a RedHat6.2 VM, with 4 cores and 2Ghz per core.
I have let this query run for 24 hours without anything seeming to happen. Other queries, like simple selects and many more, work smoothly.
Questions:
- Do you have any suggestions for a different, more efficient, query that might accomplish the same thing?
- Is it possible that this performance issue has something to do with the configuration of the database?
i would try the “explain” feature, to see, what db2 is making out of your query
db2exfmt -d database -e schema -t -v % -w -1 -s % -# 0 -n % -g OTIC