Post by LeoRun runstats on both tables and the associated indexes. Then make
sure you have the explain tables created (the ddl for them in under
~/sqllib/misc/EXPLAIN.DDL I believe). Then, put you query in a file
db2 set current explain mode explain
db2 -tf filename
db2 set current explain mode no
db2exfmt -d database_name -g TIC -1 -o filename.out
Then post the contents of filename.out so we can all see the explain
output. It will make it much easier to solve the problem.
Thanks Leo. I have attached the output below. Please advice.
Bing
DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DATABASE 2 Explain Table Format Tool
******************** EXPLAIN INSTANCE ********************
DB2_VERSION: 08.01.3
SOURCE_NAME: DB2ADVIS
SOURCE_SCHEMA: NULLID
SOURCE_VERSION:
EXPLAIN_TIME: 2003-11-06-18.11.22.180128
EXPLAIN_REQUESTER: DB2ADMIN
Database Context:
----------------
Parallelism: None
CPU Speed: 6.612820e-07
Comm Speed: 1
Buffer Pool size: 138820
Sort Heap size: 758
Database Heap size: 1200
Lock List size: 100
Maximum Lock List: 60
Average Applications: 1
Locks Available: 6780
Package Context:
---------------
SQL Type: Dynamic
Optimization Level: 5
Blocking: Block Unamibiguous Cursors
Isolation Level: Cursor Stability
---------------- STATEMENT 1 SECTION 26 ----------------
QUERYNO: 1
QUERYTAG:
Statement Type: Select
Updatable: No
Deletable: No
Query Degree: 1
Original Statement:
------------------
SELECT C.X,C.Y
FROM COORDINATE AS C, FRAME AS F
WHERE F.TID=1 AND C.FID=F.ID AND F.ID<1000 AND F.ID>0
ORDER BY C.FID,C.AID
Optimized Statement:
-------------------
SELECT Q2.X AS "X", Q2.Y AS "Y", Q2.FID, Q2.AID
FROM DB2ADMIN.FRAME AS Q1, DB2ADMIN.COORDINATE AS Q2
WHERE (0 < Q1.ID) AND (Q1.ID < 1000) AND (Q2.FID = Q1.ID) AND (Q1.TID = 1)
ORDER BY Q2.FID, Q2.AID
Access Plan:
-----------
Total Cost: 11282.7
Query Degree: 1
Rows
RETURN
( 1)
Cost
I/O
|
27342.7
NLJOIN
( 2)
11282.7
448.963
/------+-----\
80.432 339.948
IXSCAN IXSCAN
( 3) ( 4)
25.1445 139.995
1 5.56946
| |
20108 1.7087e+08
INDEX: SYSTEM INDEX: SYSTEM
IDX0311061811220 IDX0311061811220
1) RETURN: (Return Result)
Cumulative Total Cost: 11282.7
Cumulative CPU Cost: 8.86135e+07
Cumulative I/O Cost: 448.963
Cumulative Re-Total Cost: 57.5291
Cumulative Re-CPU Cost: 8.69963e+07
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 100.13
Estimated Bufferpool Buffers: 449.963
Arguments:
---------
BLDLEVEL: (Build level)
DB2 v8.1.0.24 : s030728
Input Streams:
-------------
5) From Operator #2
Estimated number of rows: 27342.7
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q3.Y+Q3.X
2) NLJOIN: (Nested Loop Join)
Cumulative Total Cost: 11282.7
Cumulative CPU Cost: 8.86135e+07
Cumulative I/O Cost: 448.963
Cumulative Re-Total Cost: 57.5291
Cumulative Re-CPU Cost: 8.69963e+07
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 100.13
Estimated Bufferpool Buffers: 449.963
Arguments:
---------
EARLYOUT: (Early Out flag)
NONE
FETCHMAX: (Override for FETCH MAXPAGES)
IGNORE
ISCANMAX: (Override for ISCAN MAXPAGES)
IGNORE
Predicates:
----------
6) Predicate used in Join
Relational Operator: Equal (=)
Subquery Input Required: No
Filter Factor: 4.97315e-05
Predicate Text:
--------------
(Q2.FID = Q1.ID)
Input Streams:
-------------
2) From Operator #3
Estimated number of rows: 80.432
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q1.ID(A)
4) From Operator #4
Estimated number of rows: 339.948
Number of columns: 4
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q2.FID(A)+Q2.AID(A)+Q2.Y(A)+Q2.X(A)
Output Streams:
--------------
5) To Operator #1
Estimated number of rows: 27342.7
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q3.Y+Q3.X
3) IXSCAN: (Index Scan)
Cumulative Total Cost: 25.1445
Cumulative CPU Cost: 218454
Cumulative I/O Cost: 1
Cumulative Re-Total Cost: 0.114397
Cumulative Re-CPU Cost: 172993
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 25.0529
Estimated Bufferpool Buffers: 2
Arguments:
---------
JN INPUT: (Join input leg)
OUTER
MAXPAGES: (Maximum pages for prefetch)
1
PREFETCH: (Type of Prefetch)
NONE
ROWLOCK : (Row Lock intent)
NEXT KEY SHARE
SCANDIR : (Scan Direction)
FORWARD
TABLOCK : (Table Lock intent)
INTENT SHARE
Predicates:
----------
4) Start Key Predicate
Relational Operator: Less Than (<)
Subquery Input Required: No
Filter Factor: 0.333333
Predicate Text:
--------------
(0 < Q1.ID)
5) Stop Key Predicate
Relational Operator: Less Than (<)
Subquery Input Required: No
Filter Factor: 0.333333
Predicate Text:
--------------
(Q1.ID < 1000)
7) Start Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: No
Filter Factor: 0.04
Predicate Text:
--------------
(Q1.TID = 1)
7) Stop Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: No
Filter Factor: 0.04
Predicate Text:
--------------
(Q1.TID = 1)
Input Streams:
-------------
1) From Object SYSTEM.IDX031106181122000
Estimated number of rows: 20108
Number of columns: 3
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q1.ID(A)+Q1.$RID$+Q1.TID
Output Streams:
--------------
2) To Operator #2
Estimated number of rows: 80.432
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q1.ID(A)
4) IXSCAN: (Index Scan)
Cumulative Total Cost: 139.995
Cumulative CPU Cost: 1.14706e+06
Cumulative I/O Cost: 5.56946
Cumulative Re-Total Cost: 89.9584
Cumulative Re-CPU Cost: 1.0916e+06
Cumulative Re-I/O Cost: 3.56946
Cumulative First Row Cost: 75.0767
Estimated Bufferpool Buffers: 71777.7
Arguments:
---------
JN INPUT: (Join input leg)
INNER
MAXPAGES: (Maximum pages for prefetch)
3
PREFETCH: (Type of Prefetch)
NONE
ROWLOCK : (Row Lock intent)
NEXT KEY SHARE
SCANDIR : (Scan Direction)
FORWARD
TABLOCK : (Table Lock intent)
INTENT SHARE
Predicates:
----------
2) Sargable Predicate
Relational Operator: Less Than (<)
Subquery Input Required: No
Filter Factor: 0.0400051
Predicate Text:
--------------
(Q2.FID < 1000)
2) Stop Key Predicate
Relational Operator: Less Than (<)
Subquery Input Required: No
Filter Factor: 0.0400051
Predicate Text:
--------------
(Q2.FID < 1000)
3) Sargable Predicate
Relational Operator: Less Than (<)
Subquery Input Required: No
Filter Factor: 1
Predicate Text:
--------------
(0 < Q2.FID)
3) Start Key Predicate
Relational Operator: Less Than (<)
Subquery Input Required: No
Filter Factor: 1
Predicate Text:
--------------
(0 < Q2.FID)
6) Start Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: No
Filter Factor: 4.97315e-05
Predicate Text:
--------------
(Q2.FID = Q1.ID)
6) Stop Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: No
Filter Factor: 4.97315e-05
Predicate Text:
--------------
(Q2.FID = Q1.ID)
Input Streams:
-------------
3) From Object SYSTEM.IDX031106181122000
Estimated number of rows: 1.7087e+08
Number of columns: 5
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q2.FID(A)+Q2.AID(A)+Q2.Y(A)+Q2.X(A)+Q2.$RID$
Output Streams:
--------------
4) To Operator #2
Estimated number of rows: 339.948
Number of columns: 4
Subquery predicate ID: Not Applicable
Column Names:
------------
+Q2.FID(A)+Q2.AID(A)+Q2.Y(A)+Q2.X(A)
Objects Used in Access Plan:
---------------------------
Schema: SYSTEM
Name: IDX031106181122000
Type: Index
Time of creation: 2003-11-06-18.11.22.183114
Last statistics update:
Number of columns: 2
Number of rows: 20108
Width of rows: -1
Number of buffer pool pages: 1257
Distinct row values: No
Tablespace name: USERSPACE1
Tablespace overhead: 24.100000
Tablespace transfer rate: 0.900000
Source for statistics: Single Node
Prefetch page count: 2560
Container extent page count: 32
Index clustering statistic: 20.000000
Index leaf pages: 142
Index tree levels: 2
Index full key cardinality: 20108
Index first key cardinality: 20108
Index first 2 keys cardinality: -1
Index first 3 keys cardinality: -1
Index first 4 keys cardinality: -1
Index sequential pages: -1
Index page density: -1
Index avg sequential pages: -9
Index avg gap between sequences:-9
Index avg random pages: -9
Fetch avg sequential pages: -9
Fetch avg gap between sequences:-9
Fetch avg random pages: -9
Index RID count: 0
Index deleted RID count: 0
Index empty leaf pages: 0
Schema: SYSTEM
Name: IDX031106181122000
Type: Index
Time of creation: 2003-11-06-18.11.22.183139
Last statistics update:
Number of columns: 4
Number of rows: 170870376
Width of rows: -1
Number of buffer pool pages: 1275801
Distinct row values: Yes
Tablespace name: USERSPACE1
Tablespace overhead: 24.100000
Tablespace transfer rate: 0.900000
Source for statistics: Single Node
Prefetch page count: 2560
Container extent page count: 32
Index clustering statistic: 20.000000
Index leaf pages: 1794140
Index tree levels: 4
Index full key cardinality: 170870376
Index first key cardinality: 170870376
Index first 2 keys cardinality: -1
Index first 3 keys cardinality: -1
Index first 4 keys cardinality: -1
Index sequential pages: -1
Index page density: -1
Index avg sequential pages: -9
Index avg gap between sequences:-9
Index avg random pages: -9
Fetch avg sequential pages: -9
Fetch avg gap between sequences:-9
Fetch avg random pages: -9
Index RID count: 0
Index deleted RID count: 0
Index empty leaf pages: 0