You can use the DB2 EXPLAIN statement to determine the access paths for the SELECT parts of your statements. DB2 EXPLAIN helps you answer questions about Query Performance & Query Optimization; the answers give you the information that you need to make performance improvements. EXPLAIN indicates whether Db2 used an index to access data, whether sorts were performed, whether parallel processing was used, and so on. The information in the plan table can help you when you need to perform the following tasks:
Three key tables for EXPLAIN are PLAN_TABLE, DSN_STATEMNT_TABLE & DSN_FUNCTION_TABLE.
CREATE TABLE [userid].PLAN_TABLE LIKE DEFAULT.PLAN_TABLE;
EXPLAIN PLAN SET QUERYNO = 1 FOR [your sql statement here]
SELECT * FROM PLAN_TABLE WHERE QUERYNO = 1 ORDER BY TIMESTAMP, QUERYNO, QBLOCKNO, PLANNO, MIXOPSEQ WITH UR;
Look at these fields for important information:
Query to find Total Cost: SELECT SUBSTR(PL.COLLID,1,10) AS COLLID, SUBSTR(PL.PROGNAME,1,10) AS PROGNAME, DATE(PL.EXPLAIN_TIME) AS DATE, TIME(PL.EXPLAIN_TIME) AS TIME, COUNT(PL.QUERYNO) AS "STMT COUNT", DEC(SUM(ST.TOTAL_COST),8,2) AS "TOTAL COST" FROM SJD.PLAN_TABLE PL, SJD.DSN_STATEMNT_TABLE ST WHERE PL.PROGNAME = ST.PROGNAME AND PL.COLLID = ST.COLLID AND PL.EXPLAIN_TIME = ST.EXPLAIN_TIME AND PL.QUERYNO = ST.QUERYNO GROUP BY PL.COLLID, PL.PROGNAME, PL.EXPLAIN_TIME ORDER BY PL.PROGNAME; Result: ————+---------+---------+---------+---------+------------- COLLID PROGNAME DATE TIME STMT COUNT TOTAL COST +---------+---------+---------+---------+----------------- MYCOLL MYPACK 05/08/2014 11.19.38 5 10.10 MYCOLL MYPACK 05/08/2014 17.36.17 8 19.11 Query to Compare Old & New Cost: SELECT ST1.QUERYNO AS QUERYNO, COALESCE(DEC(ST1.TOTAL_COST,8,2),0) AS "OLD COST", COALESCE(DEC(ST2.TOTAL_COST,8,2),0) AS "NEW COST" FROM SJD.DSN_STATEMNT_TABLE ST1 FULL JOIN SJD.DSN_STATEMNT_TABLE ST2 ON ST1.QUERYNO = ST2.QUERYNO WHERE ST1.COLLID = 'MYCOLL' AND ST2.COLLID = 'MYCOLL' AND ST1.PROGNAME = 'MYPACK' AND ST2.PROGNAME = 'MYPACK' AND DATE(ST1.EXPLAIN_TIME) = '2014-05-08' AND TIME(ST1.EXPLAIN_TIME) = '17.36.17' AND DATE(ST2.EXPLAIN_TIME) = '2014-05-15' AND TIME(ST2.EXPLAIN_TIME) = '13.05.14' AND ST1.TOTAL_COST <> ST2.TOTAL_COST ORDER BY QUERYNO; Result: ---------+---------+---------+---------+----- QUERYNO OLD COST NEW COST ---------+---------+---------+---------+----- 353 .15 .11 360 8.07 16.24 Query to find Total Cost and Explain Time: SELECT QUERYNO, TOTAL_COST, EXPLAIN_TIME FROM SJD.DSN_STATEMNT_TABLE WHERE PROGNAME = 'ID14SQP' AND COLLID = 'ID14SQL' ORDER BY TOTAL_COST DESC, EXPLAIN_TIME DESC; Result: -----+---------+---------+---------+---------+---------+---- QUERYNO TOTAL_COST EXPLAIN_TIME -----+---------+---------+---------+---------+---------+---- 88 +0.5616997729372477E+05 2014-11-02-18.03.04.993751 131 +0.1453335050780900E+01 2014-11-02-18.03.04.993751 131 +0.1453335050780900E+01 2014-10-27-16.55.51.641367 SELECT QUERYNO, COALESCE(DEC(TOTAL_COST,8,0),0) AS "COST", EXPLAIN_TIME FROM SJD.DSN_STATEMNT_TABLE WHERE COLLID = ‘ID14SQL' AND PROGNAME = ‘ID14SQP' ORDER BY EXPLAIN_TIME DESC; Result: ---------+---------+---------+---------+---------+ QUERYNO COST EXPLAIN_TIME ---------+---------+---------+---------+---------+ 88 434758 2014-11-02-18.03.04.993751 88 23184 2014-10-27-16.55.51.641367
A well-maintained product backlog is crucial for successful product development. It serves as a single…
Incremental value to the customer refers to the gradual delivery of small, functional parts of…
A Product Market refers to the group of potential customers who might be interested in…
The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…
The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…
Choosing the right Scrum Master Certification depends on your current experience and career goals. If…