IBM Query Tuner Report

This report contains a summary of the recommendations from the Query Tuner advisors and tools. Examine the recommendations and corresponding DDL scripts, if applicable, and take appropriate actions to tune your query. You can also examine the formatted query and access plan summary, and cross reference the recommendations generated by the advisors. Use the cataloged table, column, and index information to do further analysis and tuning. Navigate to the different sections using the action buttons and then return to the top of the report using Back to top.



Overview

Recommendation generation timestamp: 2009-08-27T12:14:23
Database server configuration: jdbc:db2://9.30.68.24:50000/TPCD (SQL09051)
Estimated plan cost: 9,842.858 units
Critical problems: 1 statistics recommendations, 0 index recommendations, 0 query recommendations, and 0 access path warnings.
Best practices: 0 statistics recommendations, 1 index recommendations, 1 query recommendations, and 2 access path warnings.

Advice Number Advice Type Tuning Recommendation Description
1 Statistics CRITICAL: Consolidate statistics: Use RUNSTATS to recollect all the relevant statistics for this query for an accurate evaluation Important: if statistics are missing, Query tuner estimates subsequent recommendations based on database default statistics. Click here to review the recommended RUNSTATS script.
2 Index Index recommendation is found for the following tables: TPCDS .CATALOG_RETURNS. The total estimated disk space required is 2.493 MB and the estimated performance improvement is 92.258%. This index recommendation will help improve query performance for general indexing. Click here to review the recommended CREATE INDEX DDL script.
3 Query Provide a predicate on column R_ITEM_SK. Consider adding the following predicate to column R_ITEM_SK in table REPAIR: R_ITEM_SK IS NOT NULL to filter the table earlier and unlock more possible join sequences.Click here to see the affected query text.
4 Access path Avoid table space scan (Operator ID = 6) on table TPCDS.CATALOG_RETURNS. The table is accessed by a table space scan (table scan). When a large number of records are returned, DB2 might be using an inefficient access path. Consider running the statistics advisor or running the index advisor to determine whether creating an index might improve the access path.Click here to see the access plan operator.
This Access path recommendation also applies to the following objects.
5       - TPCDS.REPAIR, (Operator ID = 7)

Back to top



Recommended Action

The tuning advisors recommend the following actions to update the table and index statistics, and to create the necessary indexes to improve the query performance.



Update Statistics Statements

Advice Number Statement Number Statement Text
1 1 RUNSTATS ON TABLE "TPCDS"."REPAIR" ON COLUMNS ( "R_DIAGNOSIS" LIKE STATISTICS ) WITH DISTRIBUTION ON COLUMNS ( "R_ORDER_NUMBER" NUM_FREQVALUES 15 NUM_QUANTILES 25 , "R_ITEM_SK" NUM_FREQVALUES 15 NUM_QUANTILES 25 ) AND SAMPLED DETAILED INDEXES ALL ALLOW WRITE ACCESS
1 2 RUNSTATS ON TABLE "TPCDS"."CATALOG_RETURNS" WITH DISTRIBUTION ON COLUMNS ( "CR_ORDER_NUMBER" NUM_FREQVALUES 15 NUM_QUANTILES 25 , "CR_ITEM_SK" NUM_FREQVALUES 15 NUM_QUANTILES 25 , "CR_RETURN_SHIP_COST" NUM_FREQVALUES 15 NUM_QUANTILES 25 ) AND SAMPLED DETAILED INDEXES ALL ALLOW WRITE ACCESS

Back to recommended action


Create Index Statements

Estimated performance improvement is 92.258%.
Estimated disk space use is 2.493 MB.

Advice Number Statement Number Statement Text
2 1 CREATE UNIQUE INDEX "DB2OE "."IDX908271915160000" ON "TPCDS "."CATALOG_RETURNS" ("CR_ORDER_NUMBER" ASC, "CR_ITEM_SK" ASC) INCLUDE ("CR_RETURN_SHIP_COST") ALLOW REVERSE SCANS

Back to recommended action

Back to top



SQL Statement

Input Query


    WITH DT( COST
     )
     AS (
SELECT CASE WHEN R.R_REPAIR_COST < 100.0
     THEN 'small'
     WHEN R.R_REPAIR_COST < 1000.0
     THEN 'medium'
     ELSE 'expensive'
     END
     FROM TPCDS.REPAIR AS R /* no. of rows=10000 */
     , TPCDS.CATALOG_RETURNS AS C /* no. of rows=144222 */
     WHERE C.CR_RETURN_SHIP_COST > 100
     AND R.R_DIAGNOSIS LIKE '%fire%'
     AND R.R_ORDER_NUMBER > 10
     AND R.R_ORDER_NUMBER = C.CR_ORDER_NUMBER
     AND R.R_ITEM_SK = C.CR_ITEM_SK /* WARNING=Advice #3 */
     )
SELECT DT.COST
     , COUNT(*)
    FROM DT
    GROUP BY DT.COST

Back to top



Access Plan Summary

The following table summarizes the access plan's estimated return rows, estimated costs, the total number of table scan, index scan, join and sort operations, total number of predicates, explain timestamp, total number of cataloged tables referenced and the index usage with percentage of indexes used and percentage of indexes not used. You can examine the table and index scan details and the table access and join predicates being applied.
Note: Subselect (QBLOCK) is available for DB2 for z/OS only.

Subselect (QBLOCK) Estimated Return Rows Estimated Cost Plan Operator Totals Explain Timestamp Cataloged Tables Referenced Catalog Index Usage
Total Cost Total CPU Total IO Table Scan Index Scan Join Sort Predicate Used Indexes (%) Unused Indexes (%) Existing Indexes
- 66.076 9,842.858 512,655,328.000 5,306.000 2 0 1 1 6 2009-08-27T12:13:32 2 0 (0.0%) 3 (100.0%) 3




Database server transformed query for access plan


SELECT  Q4.$C0  AS  "COST", 
     Q4.$C1 
FROM  (SELECT  Q3.$C0, 
     COUNT(*  ) 
FROM  (SELECT 
CASE  WHEN  (Q1.R_REPAIR_COST  <  +100.0)  THEN  'small'  WHEN  (Q1.R_REPAIR_COST  <  +1000.0)  THEN  'medium' 
ELSE  'expensive'  END 
FROM  TPCDS.REPAIR  AS  Q1, 
     TPCDS.CATALOG_RETURNS  AS  Q2 
WHERE  (Q1.R_ORDER_NUMBER  =  Q2.CR_ORDER_NUMBER) 
AND  (Q1.R_ITEM_SK  =  Q2.CR_ITEM_SK) 
AND  (Q1.R_DIAGNOSIS  LIKE  '%fire%') 
AND  (100  <  Q2.CR_RETURN_SHIP_COST) 
AND  (10  <  Q1.R_ORDER_NUMBER))  AS  Q3 
GROUP  BY  Q3.$C0)  AS  Q4 

Back to access plan summary

Predicate for Table Access and Join

Predicates can disqualify rows and reduce the amount of required processing at later stage. The earlier DB2 can evaluate a predicate, the more the query performance can improve. When possible, try to write queries that evaluate the most restrictive predicates first. When predicates with a high filter factor are processed first, unnecessary rows are disqualified as early as possible, which can reduce processing cost at a later stage. Filter factors affect the choice of access paths by estimating the number of rows that qualified by a set of predicates.
Platform Tip: The Query block identifier and plan identifier are available on DB2 for z/OS only.

Query Block: Plan Identifier* Predicate Identifier Predicate Text Used in Join Used in Index Scan Used in Table Scan Filter Factor
- 3 (10 < Q2.CR_ORDER_NUMBER) No No Yes 0.999966
- 4 (Q1.R_ORDER_NUMBER = Q2.CR_ORDER_NUMBER) Yes No No 0.000011
- 5 (Q1.R_ITEM_SK = Q2.CR_ITEM_SK) Yes No No 0.000056
- 6 (Q1.R_DIAGNOSIS LIKE '%fire%') No No Yes 0.100000
- 7 (100 < Q2.CR_RETURN_SHIP_COST) No No Yes 0.660957
- 8 (10 < Q1.R_ORDER_NUMBER) No No Yes 0.999700

Back to access plan summary

Table Access

Each time a table is accessed by the query, multiple predicate can be applied. For DB2 z/OS, the estimated costs are displayed at the mini plan level and there is no estimated cost available for index access when the value is "N".
Tip: The operator identifier is represented by an Operator ID for DB2 for Linux, UNIX, and Windows, and by "Query block: Plan ID" for DB2 for z/OS.

Operator Identifier** Table Name (Correlation ID) Index Access Estimated Qualified Rows Cumulative Total Cost Cumulative CPU Cost Cumulative IO Cost Predicate ID (How is applied) Advice Number
6 TPCDS.CATALOG_RETURNS 
(Q2)
- 95,321.289 9,629.491 459,063,968.000 5,155.000
  • 3 (SARG)
  • 7 (SARG)
4
7 TPCDS.REPAIR 
(Q1)
- 999.700 182.229 26,591,966.000 151.000
  • 6 (SARG)
  • 8 (SARG)
5

Back to access plan summary

Join Operation

Each table scan can be used with multiple predicate identifiers. On DB2 for z/OS, the estimated costs are displayed at the plan level.
Tip: the join identifier is represented by an operator ID for DB2 for Linux, UNIX, and Windows, and by a "Query Block: Plan ID" for DB2 for z/OS.

Join Identifier** Join Left Operand Join Right Operand Join Method Is Join Data Sorted Estimated Qualified Rows Cumulative Total Cost Cumulative CPU Cost Cumulative IO Cost Predicate Identifier Advice Number
5 TPCDS.CATALOG_RETURNS
(Correlation ID=Q2)
TPCDS.REPAIR
(Correlation ID=Q1)
HSJOIN No 660.759 9,841.513 511,488,480.000 5,306.000 4, 5 5

Back to access plan summary

Back to top

Method for applying the predicate.



Table and Index Catalog Information

The following list displays the referenced table statistics in the query access plan. All columns and indexes for the referenced tables are also listed. You can examine the table size, associated primary and foreign keys, cardinality and index columns information; and use the table and index statistics to plan for and reorganize tables and indexes with the REORG utility.

There are 2 referenced tables, 0 used indexes (0.0%), 3 unused indexes (100.0%), and a total of 3 indexes.


Referenced tables, sorted by table name.

**Tablespace name, qualified with database name when on a DB2 for z/OS data server.

Table Name Tablespace Name Foreign Key -> Parent Key Number of Columns Table Cardinality Number of Pages Average Row Size Stats Last Updated
TPCDS.CATALOG_RETURNS USERSPACE1 27 144,222 5,154 143 2009-08-19T12:45:13
TPCDS.REPAIR TS00001 8 10,000 150 60 2009-08-19T12:45:12

Back to table and index catalog info

All table columns, sorted by table name and physical column order

Table Name Column Number Column Name Column Type Length Nullable Column Cardinality
TPCDS.CATALOG_RETURNS 0 CR_RETURNED_DATE_SK INTEGER 4 Y 2069.0
  1 CR_RETURNED_TIME_SK INTEGER 4 Y 70656.0
  2 CR_ITEM_SK INTEGER 4 N 17856.0
  3 CR_REFUNDED_CUSTOMER_SK INTEGER 4 Y 57857.0
  4 CR_REFUNDED_CDEMO_SK INTEGER 4 Y 96257.0
  5 CR_REFUNDED_HDEMO_SK INTEGER 4 Y 7169.0
  6 CR_REFUNDED_ADDR_SK INTEGER 4 Y 45057.0
  7 CR_RETURNING_CUSTOMER_SK INTEGER 4 Y 76801.0
  8 CR_RETURNING_CDEMO_SK INTEGER 4 Y 144222.0
  9 CR_RETURNING_HDEMO_SK INTEGER 4 Y 7169.0
  10 CR_RETURNING_ADDR_SK INTEGER 4 Y 47105.0
  11 CR_CALL_CENTER_SK INTEGER 4 Y 7.0
  12 CR_CATALOG_PAGE_SK INTEGER 4 Y 7297.0
  13 CR_SHIP_MODE_SK INTEGER 4 Y 21.0
  14 CR_WAREHOUSE_SK INTEGER 4 Y 6.0
  15 CR_REASON_SK INTEGER 4 Y 36.0
  16 CR_ORDER_NUMBER INTEGER 4 N 94208.0
  17 CR_RETURN_QUANTITY INTEGER 4 Y 101.0
  18 CR_RETURN_AMOUNT DECIMAL (7,2) Y 76801.0
  19 CR_RETURN_TAX DECIMAL (7,2) Y 26113.0
  20 CR_RETURN_AMT_INC_TAX DECIMAL (7,2) Y 92161.0
  21 CR_FEE DECIMAL (7,2) Y 10369.0
  22 CR_RETURN_SHIP_COST DECIMAL (7,2) Y 62465.0
  23 CR_REFUNDED_CASH DECIMAL (7,2) Y 66561.0
  24 CR_REVERSED_CHARGE DECIMAL (7,2) Y 56833.0
  25 CR_STORE_CREDIT DECIMAL (7,2) Y 54273.0
  26 CR_NET_LOSS DECIMAL (7,2) Y 93185.0
TPCDS.REPAIR 0 R_REPAIR_TICKET_SK INTEGER 4 N 10000.0
  1 R_ITEM_SK INTEGER 4 Y 5988.0
  2 R_ORDER_NUMBER INTEGER 4 Y 6976.0
  3 R_CALL_CENTER_SK INTEGER 4 Y -1.0
  4 R_REPAIR_CUSTOMER_SK INTEGER 4 Y -1.0
  5 R_REPAIR_ADDR_SK INTEGER 4 Y -1.0
  6 R_REPAIR_COST DECIMAL (7,2) Y -1.0
  7 R_DIAGNOSIS VARCHAR 3,000 Y 1.0

Back to table and index catalog info

All indexes, sorted by table name, referenced index name, unreferenced index name, and key column sequence

Table Name Index Name Index Type Unique Rule Used in Plan Leaf Pages Index Levels Cluster Ratio (%) Clustering First Key Cardinality Full Key Cardinality Key Column Key Order Column Cardinality Statistics Last Updated
TPCDS.CATALOG_RETURNS SYSIBM.SQL090429132203100 Regular Primary index No 764 3 -1 No 17,856.000 144,222.000 CR_ITEM_SK Asc 17856.0 2009-08-19T12:45:13
                      CR_ORDER_NUMBER Asc 94208.0 2009-08-19T12:45:13
TPCDS.REPAIR DB2OE.IDX904072054270000 Regular Duplicate allowed No 59 2 -1 No 5,988.000 9,998.000 R_ITEM_SK Asc 5988.0 2009-08-19T12:45:12
                      R_REPAIR_COST Asc -1.0 2009-08-19T12:45:12
  SYSIBM.SQL090403183259280 Regular Primary index No 42 2 -1 No 10,000.000 10,000.000 R_REPAIR_TICKET_SK Asc 10000.0 2009-08-19T12:45:12

Back to table and index catalog info

Back to top



Query Tuner Report Log

The following log records the runtime information including the client version, server license, and which tuning advisors are used to obtain query tuning recommendations.

Server license entitlement and version: IBM Optim Query Workload Tuner for DB2, Version 2.2
Query Tuner client version: 2.2.0.1
Report completion timestamp: 2009-08-27T12:14:24.


Advisor Run Status
Statistics Success
Index Success
Query Success
Access path Success

Back to top