Wow, thanks for all the feedback, guys. The latest fixpack applied on
the server is FP5, which technically makes it V7.3, I suppose.
Unfortunately, this version does not allow the 'ON ALL COLUMNS' clause
on the RUNSTATS command. From the doc for V7 found here:
http://www-306.ibm.com/cgi-bin/db2ww....htm#HDRCMD098
I have to assume the runstats command I listed above is the most
comprehensive data gathering flavor of the command. Is this correct?
Many of the responses implied that not all of the necessary statistics
had been gathered, but I am unaware of any means beyond fudging the
stats tables directly, that could give me more accurate statistics.
Below I've tried to supply some of the info mentioned in replies so
far. I was surprised to see so few entries for CLIENTID in the sysstat
table (see below). Could this be the problem?
Here is a more detailed description of the data distribution:
Number of distinct CLIENTID's: 9223
Number ORDERs with a CLIENTID of '277475': 11730
Number of distinct SEARCHCODEs: 73
I was obviously off the mark with my estimate of this cardinality,
however tha majority of the distribution is across a small subset of
the values. The following data is from a query directly against the
table, with count(*) and group by.
Breakdown of SEARCHCODE distribution:
SEARCHCODE 2
---------- -----------
08 2039829
11 649924
12 608037
03 433443
41 307586
60 215766
05 111580
10 89033
51 64315
01 59991
09 54754
88 40005
04 38697
78 37235
81 34786
50 28932
83 26164
68 20312
74 20242
06 17615
80 15499
37 12063
48 10271
71 10217
47 9288
62 9093
33 9048
02 8133
34 8042
28 7392
13 6687
63 4969
27 4778
66 4201
07 2710
35 2547
61 2044
39 1605
52 1558
32 1150
44 1068
15 793
92 779
36 667
53 606
38 605
67 534
86 439
77 281
64 259
16 183
49 180
14 174
73 147
65 119
21 99
23 98
76 85
89 70
25 63
17 49
99 42
20 32
69 30
19 27
24 13
87 13
56 10
18 9
22 7
84 4
54 3
91 3
Below are the two output reports from the DB2EXFMT utility for the two
queries in question, followed by a query against the SYSSTAT table for
the releveant columns:
Here is the output of the db2exfmt utility for the first query:
DB2 Universal Database Version 7.2, 5622-044 (c) Copyright IBM Corp.
1991, 2001
Licensed Material - Program Property of IBM
IBM DATABASE 2 Explain Table Format Tool
******************** EXPLAIN INSTANCE ********************
DB2_VERSION: 07.02.3
SOURCE_NAME: SQLLF000
SOURCE_SCHEMA: NULLID
EXPLAIN_TIME: 2004-02-09-09.34.00.750001
EXPLAIN_REQUESTER: DB2ADMIN
Database Context:
----------------
Parallelism: None
CPU Speed: 6.179837e-007
Comm Speed: 0
Buffer Pool size: 151136
Sort Heap size: 1024
Database Heap size: 4096
Lock List size: 1024
Maximum Lock List: 20
Average Applications: 50
Locks Available: 23142
Package Context:
---------------
SQL Type: Dynamic
Optimization Level: 5
Blocking: Block All Cursors
Isolation Level: Cursor Stability
---------------- STATEMENT 1 SECTION 65 ----------------
QUERYNO: 100
QUERYTAG:
Statement Type: Select
Updatable: No
Deletable: No
Query Degree: 1
Original Statement:
------------------
Select Distinct DATA2
from ORDERS
where SEARCHCODE = '04' and CLIENTID = 277475
With UR
Optimized Statement:
-------------------
SELECT DISTINCT Q1.DATA2 AS "DATA2"
FROM DB2ADMIN.ORDERS AS Q1
WHERE (Q1.CLIENTID = 277475) AND (Q1.SEARCHCODE = '04')
Access Plan:
-----------
Total Cost: 265.69
Query Degree: 1
Rows
RETURN
( 1)
Cost
I/O
|
3.16741
TBSCAN
( 2)
265.69
68.747
|
3.16741
SORT
( 3)
265.688
68.747
|
3.16741
FETCH
( 4)
265.686
68.747
/----+---\
3.16741 5.0301e+006
IXAND TABLE: DB2ADMIN
( 5) ORDERS
218.723
64.0549
/------+-----\
412.105 38661
IXSCAN IXSCAN
( 6) ( 7)
20.4841 197.392
2 62.0549
| |
5.0301e+006 5.0301e+006
INDEX: DB2ADMIN INDEX: DB2ADMIN
ORDERS02 ORDERS13
1) RETURN: (Return Result)
Cumulative Total Cost: 265.69
Cumulative CPU Cost: 6.92502e+007
Cumulative I/O Cost: 68.747
Cumulative Re-Total Cost: 42.4248
Cumulative Re-CPU Cost: 6.86503e+007
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 265.689
Estimated Bufferpool Buffers: 0
Arguments:
---------
BLDLEVEL: (Build level)
DB2 v7.1.0.55 : n011211
ENVVAR : (Environment Variable)
DB2_HASH_JOIN = ON
Input Streams:
-------------
9) From Operator #2
Estimated number of rows: 3.16741
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
2) TBSCAN: (Table Scan)
Cumulative Total Cost: 265.69
Cumulative CPU Cost: 6.92502e+007
Cumulative I/O Cost: 68.747
Cumulative Re-Total Cost: 42.4248
Cumulative Re-CPU Cost: 6.86503e+007
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 265.689
Estimated Bufferpool Buffers: 0
Arguments:
---------
MAXPAGES: (Maximum pages for prefetch)
ALL
PREFETCH: (Type of Prefetch)
NONE
SCANDIR : (Scan Direction)
FORWARD
Input Streams:
-------------
8) From Operator #3
Estimated number of rows: 3.16741
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
Output Streams:
--------------
9) To Operator #1
Estimated number of rows: 3.16741
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
3) SORT : (Sort)
Cumulative Total Cost: 265.688
Cumulative CPU Cost: 6.92479e+007
Cumulative I/O Cost: 68.747
Cumulative Re-Total Cost: 42.4233
Cumulative Re-CPU Cost: 6.8648e+007
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 265.688
Estimated Bufferpool Buffers: 305.376
Arguments:
---------
DUPLWARN: (Duplicates Warning flag)
TRUE
NUMROWS : (Estimated number of rows)
4
ROWWIDTH: (Estimated width of rows)
16
SORTKEY : (Sort Key column)
1: DATA2(A)
TEMPSIZE: (Temporary Table Page Size)
4096
UNIQUE : (Uniqueness required flag)
TRUE
Input Streams:
-------------
7) From Operator #4
Estimated number of rows: 3.16741
Number of columns: 4
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+DATA2+CLIENTID+SEARCHCODE
Output Streams:
--------------
8) To Operator #2
Estimated number of rows: 3.16741
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
4) FETCH : (Fetch)
Cumulative Total Cost: 265.686
Cumulative CPU Cost: 6.92433e+007
Cumulative I/O Cost: 68.747
Cumulative Re-Total Cost: 42.4233
Cumulative Re-CPU Cost: 6.8648e+007
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 106.805
Estimated Bufferpool Buffers: 305.376
Arguments:
---------
MAXPAGES: (Maximum pages for prefetch)
4
MAXPAGES: (Maximum pages for prefetch)
4
PREFETCH: (Type of Prefetch)
NONE
ROWLOCK : (Row Lock intent)
NONE
TABLOCK : (Table Lock intent)
INTENT NONE
Predicates:
----------
2) Residual Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 8.19278e-005
Predicate Text:
--------------
(Q1.CLIENTID = 277475)
3) Residual Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 0.00768594
Predicate Text:
--------------
(Q1.SEARCHCODE = '04')
Input Streams:
-------------
5) From Operator #5
Estimated number of rows: 3.16741
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$
6) From Object DB2ADMIN.ORDERS
Estimated number of rows: 5.0301e+006
Number of columns: 3
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2+CLIENTID+SEARCHCODE
Output Streams:
--------------
7) To Operator #3
Estimated number of rows: 3.16741
Number of columns: 4
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+DATA2+CLIENTID+SEARCHCODE
5) IXAND : (Index ANDing)
Cumulative Total Cost: 218.723
Cumulative CPU Cost: 6.91745e+007
Cumulative I/O Cost: 64.0549
Cumulative Re-Total Cost: 42.4185
Cumulative Re-CPU Cost: 6.86402e+007
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 96.7953
Estimated Bufferpool Buffers: 143.435
Input Streams:
-------------
2) From Operator #6
Estimated number of rows: 412.105
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+CLIENTID
4) From Operator #7
Estimated number of rows: 38661
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+SEARCHCODE
Output Streams:
--------------
5) To Operator #4
Estimated number of rows: 3.16741
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$
6) IXSCAN: (Index Scan)
Cumulative Total Cost: 20.4841
Cumulative CPU Cost: 783315
Cumulative I/O Cost: 2
Cumulative Re-Total Cost: 0.446094
Cumulative Re-CPU Cost: 721854
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 20.0458
Estimated Bufferpool Buffers: 3
Arguments:
---------
MAXPAGES: (Maximum pages for prefetch)
1
PREFETCH: (Type of Prefetch)
NONE
ROWLOCK : (Row Lock intent)
NONE
SCANDIR : (Scan Direction)
FORWARD
TABLOCK : (Table Lock intent)
INTENT NONE
Predicates:
----------
2) Start Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 8.19278e-005
Predicate Text:
--------------
(Q1.CLIENTID = 277475)
2) Stop Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 8.19278e-005
Predicate Text:
--------------
(Q1.CLIENTID = 277475)
Input Streams:
-------------
1) From Object DB2ADMIN.ORDERS02
Estimated number of rows: 5.0301e+006
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+CLIENTID
Output Streams:
--------------
2) To Operator #5
Estimated number of rows: 412.105
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+CLIENTID
7) IXSCAN: (Index Scan)
Cumulative Total Cost: 197.392
Cumulative CPU Cost: 6.70214e+007
Cumulative I/O Cost: 62.0549
Cumulative Re-Total Cost: 41.1259
Cumulative Re-CPU Cost: 6.65486e+007
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 20.046
Estimated Bufferpool Buffers: 140.435
Arguments:
---------
MAXPAGES: (Maximum pages for prefetch)
60
PREFETCH: (Type of Prefetch)
SEQUENTIAL
ROWLOCK : (Row Lock intent)
NONE
SCANDIR : (Scan Direction)
FORWARD
TABLOCK : (Table Lock intent)
INTENT NONE
Predicates:
----------
3) Start Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 0.00768594
Predicate Text:
--------------
(Q1.SEARCHCODE = '04')
3) Stop Key Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 0.00768594
Predicate Text:
--------------
(Q1.SEARCHCODE = '04')
Input Streams:
-------------
3) From Object DB2ADMIN.ORDERS13
Estimated number of rows: 5.0301e+006
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+SEARCHCODE
Output Streams:
--------------
4) To Operator #5
Estimated number of rows: 38661
Number of columns: 2
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+SEARCHCODE
Objects Used in Access Plan:
---------------------------
Schema: DB2ADMIN
Name: ORDERS02
Type: Index
Time of creation: 2003-11-30-12.17.19.593001
Last statistics update: 2004-02-06-12.58.42.468000
Number of columns: 1
Number of rows: 5030097
Width of rows: -1
Number of buffer pool pages: 1134599
Distinct row values: No
Tablespace name: ORDERSI
Tablespace overhead: 9.700000
Tablespace transfer rate: 0.300000
Prefetch page count: 8
Container extent page count: 64
Index clustering statistic: 0.738917
Index leaf pages: 7149
Index tree levels: 3
Index full key cardinality: 9217
Index first key cardinality: 9217
Index first 2 keys cardinality: -1
Index first 3 keys cardinality: -1
Index first 4 keys cardinality: -1
Index sequential pages: 7073
Index page density: 99
Base Table Schema: DB2ADMIN
Base Table Name: ORDERS
Columns in index:
CLIENTID
Schema: DB2ADMIN
Name: ORDERS13
Type: Index
Time of creation: 2003-11-30-12.36.55.343001
Last statistics update: 2004-02-06-12.58.42.468000
Number of columns: 3
Number of rows: 5030097
Width of rows: -1
Number of buffer pool pages: 1134599
Distinct row values: No
Tablespace name: ORDERSI
Tablespace overhead: 9.700000
Tablespace transfer rate: 0.300000
Prefetch page count: 8
Container extent page count: 64
Index clustering statistic: 0.342897
Index leaf pages: 7871
Index tree levels: 3
Index full key cardinality: 184626
Index first key cardinality: 73
Index first 2 keys cardinality: 408
Index first 3 keys cardinality: 184626
Index first 4 keys cardinality: -1
Index sequential pages: 7720
Index page density: 99
Base Table Schema: DB2ADMIN
Base Table Name: ORDERS
Columns in index:
SEARCHCODE
STATUS
TNUMBER
Schema: DB2ADMIN
Name: ORDERS
Type: Table
Time of creation: 2002-09-22-10.50.24.437001
Last statistics update: 2004-02-06-12.58.42.468000
Number of columns: 89
Number of rows: 5030097
Width of rows: 30
Number of buffer pool pages: 1134599
Distinct row values: No
Tablespace name: ORDERST
Tablespace overhead: 9.700000
Tablespace transfer rate: 0.300000
Prefetch page count: 128
Container extent page count: 64
Table overflow record count: 567
And here's the output of DB2EXFMT for the second query:
DB2 Universal Database Version 7.2, 5622-044 (c) Copyright IBM Corp.
1991, 2001
Licensed Material - Program Property of IBM
IBM DATABASE 2 Explain Table Format Tool
******************** EXPLAIN INSTANCE ********************
DB2_VERSION: 07.02.3
SOURCE_NAME: SQLLF000
SOURCE_SCHEMA: NULLID
EXPLAIN_TIME: 2004-02-09-09.34.41.203001
EXPLAIN_REQUESTER: DB2ADMIN
Database Context:
----------------
Parallelism: None
CPU Speed: 6.179837e-007
Comm Speed: 0
Buffer Pool size: 151136
Sort Heap size: 1024
Database Heap size: 4096
Lock List size: 1024
Maximum Lock List: 20
Average Applications: 50
Locks Available: 23142
Package Context:
---------------
SQL Type: Dynamic
Optimization Level: 5
Blocking: Block All Cursors
Isolation Level: Cursor Stability
---------------- STATEMENT 1 SECTION 65 ----------------
QUERYNO: 200
QUERYTAG:
Statement Type: Select
Updatable: No
Deletable: No
Query Degree: 1
Original Statement:
------------------
Select Distinct DATA2
from ORDERS
where SEARCHCODE = '04' || '' and CLIENTID = 277475
With UR
Optimized Statement:
-------------------
SELECT DISTINCT Q1.DATA2 AS "DATA2"
FROM DB2ADMIN.ORDERS AS Q1
WHERE (Q1.CLIENTID = 277475) AND (Q1.SEARCHCODE = ('04' || ''))
Access Plan:
-----------
Total Cost: 274.691
Query Degree: 1
Rows
RETURN
( 1)
Cost
I/O
|
5.64527
TBSCAN
( 2)
274.691
163.773
|
5.64527
SORT
( 3)
274.689
163.773
|
5.64527
FETCH
( 4)
274.685
163.773
/----+---\
412.105 5.0301e+006
RIDSCN TABLE: DB2ADMIN
( 5) ORDERS
20.7172
2
|
412.105
SORT
( 6)
20.7164
2
|
412.105
IXSCAN
( 7)
20.4841
2
|
5.0301e+006
INDEX: DB2ADMIN
ORDERS02
1) RETURN: (Return Result)
Cumulative Total Cost: 274.691
Cumulative CPU Cost: 3.24999e+006
Cumulative I/O Cost: 163.773
Cumulative Re-Total Cost: 1.17398
Cumulative Re-CPU Cost: 1.89969e+006
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 274.69
Estimated Bufferpool Buffers: 0
Arguments:
---------
BLDLEVEL: (Build level)
DB2 v7.1.0.55 : n011211
ENVVAR : (Environment Variable)
DB2_HASH_JOIN = ON
Input Streams:
-------------
8) From Operator #2
Estimated number of rows: 5.64527
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
2) TBSCAN: (Table Scan)
Cumulative Total Cost: 274.691
Cumulative CPU Cost: 3.24999e+006
Cumulative I/O Cost: 163.773
Cumulative Re-Total Cost: 1.17398
Cumulative Re-CPU Cost: 1.89969e+006
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 274.69
Estimated Bufferpool Buffers: 0
Arguments:
---------
MAXPAGES: (Maximum pages for prefetch)
ALL
PREFETCH: (Type of Prefetch)
NONE
SCANDIR : (Scan Direction)
FORWARD
Input Streams:
-------------
7) From Operator #3
Estimated number of rows: 5.64527
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
Output Streams:
--------------
8) To Operator #1
Estimated number of rows: 5.64527
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
3) SORT : (Sort)
Cumulative Total Cost: 274.689
Cumulative CPU Cost: 3.24704e+006
Cumulative I/O Cost: 163.773
Cumulative Re-Total Cost: 1.17215
Cumulative Re-CPU Cost: 1.89674e+006
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 274.689
Estimated Bufferpool Buffers: 178.431
Arguments:
---------
DUPLWARN: (Duplicates Warning flag)
TRUE
NUMROWS : (Estimated number of rows)
6
ROWWIDTH: (Estimated width of rows)
16
SORTKEY : (Sort Key column)
1: DATA2(A)
TEMPSIZE: (Temporary Table Page Size)
4096
UNIQUE : (Uniqueness required flag)
TRUE
Input Streams:
-------------
6) From Operator #4
Estimated number of rows: 5.64527
Number of columns: 4
Subquery predicate ID: Not Applicable
Column Names:
------------
+$RID$+DATA2+CLIENTID+SEARCHCODE
Output Streams:
--------------
7) To Operator #2
Estimated number of rows: 5.64527
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------
+DATA2(A)
4) FETCH : (Fetch)
Cumulative Total Cost: 274.685
Cumulative CPU Cost: 3.24046e+006
Cumulative I/O Cost: 163.773
Cumulative Re-Total Cost: 1.17215
Cumulative Re-CPU Cost: 1.89674e+006
Cumulative Re-I/O Cost: 0
Cumulative First Row Cost: 73.3488
Estimated Bufferpool Buffers: 178.431
Arguments:
---------
MAX RIDS: (Maximum RIDs per list prefetch request)
512
MAXPAGES: (Maximum pages for prefetch)
149
PREFETCH: (Type of Prefetch)
LIST
ROWLOCK : (Row Lock intent)
NONE
TABLOCK : (Table Lock intent)
INTENT NONE
Predicates:
----------
2) Sargable Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 8.19278e-005
Predicate Text:
--------------
(Q1.CLIENTID = 277475)
3) Sargable Predicate
Relational Operator: Equal (=)
Subquery Input Required: Yes
Filter Factor: 0.0136986
Predicate Text:
--------------
(Q1.SEARCHCODE = ('04' || ''))
Input Streams:
-------------
4) From Operator #5
Estimated number of rows: 412.105
Number of columns: 1
Subquery predicate ID: Not Applicable
Column Names:
------------