Escolar Documentos
Profissional Documentos
Cultura Documentos
6/14/2009
Yevich, Lawson & Assoc. Inc. 2743 S. Veterans Pkwy PMB 226 Springfield, IL 62704 www.ylassoc.com www.db2expert.com www db2expert com
IBM is a registered trademark of International Business Machines Corporation. DB2 is a trademark of IBM Corp. Copyright 1998-2009, YL&A, All rights reserved.
YL&A 1997-2009
6/14/2009
The information contained in this presentation is based on techniques, algorithms, and documentation published by the several authors and companies, and in addition is the result of research. It is therefore subject to change at any time without notice or warning. The information contained in this presentation has not been submitted to any formal tests or review and is distributed on an As is basis without any warranty, either expressed or implied. The use of this information or the implementation of any of these techniques is a client responsibility and depends on the clients ability to evaluate and integrate them into the clients operational environment. While each item may have been reviewed for accuracy in a specific situation, there is no guarantee that the same or similar results will be obtained elsewhere. Clients attempting to adapt these techniques to their own environments do so at their own risks. Foils, handouts, and additional materials distributed as part of this presentation or seminar should be reviewed in their entirety.
YL&A 1997-2009
Abstract
DB2 z/OS V8 and 9 have introduced us to many new EXPLAIN tables. This presentation will introduce users some of the new EXPLAIN tables used by these tools for advanced query analysis, and demonstrate how SQL queries can be used to gather and analyze the advanced information.
YL&A 1997-2009
6/14/2009
EXPLAIN has been enhanced greatly for DB2 V8 and DB2 9 Several EXPLAIN tools are available Visual Explain Optimization p Service Center l Replaces Visual Explain l Works with V8 NFM Data Studio l Visual Explain Plug-Ins However, DB2 EXPLAIN facility is built-in to DB2 No additional tools are needed to perform an EXPLAIN EXPLAIN tables contain access path information Anyone can read the access path information from the EXPLAIN tables
YL&A 1997-2009
A GUI interface to the information in the EXPLAIN tables Provides information about statements in the system Can dynamically EXPLAIN statements Can get Statistics for accessed objects Ability to browse subsystem parameters Compatible with V7 subsystems With V8 subsystems
More information than the PLAN_TABLE provides Cardinality and Filter Factor information Additional of predicate information Some rewritten predicates exposed
n
6/14/2009
YL&A 1997-2009
YL&A 1997-2009
6/14/2009
YL&A 1997-2009
YL&A 1997-2009
6/14/2009
A workstation-based tool Easy interaction with DB2 EXPLAIN and the explain tables Allows you to analyze
l l l l l
n n n n
Replaces Visual Explain Has Many of the features of Visual Explain Compatible with V8 Subsystems in New Function Mode H additional Has dditi l features f t that th t can be b purchased h d
YL&A 1997-2009
n n
PC workstation maybe does not have enough power These tools use a lot of the machine DB2 Connect Enterprise Edition is required Remote connections to mainframe are required This Thi raises i security it concerns l Especially for production SPUFI or QMF is often preferred This is a fast and easy method
YL&A 1997-2009
6/14/2009
Most available in V8 Now very accessible in V9 via Optimization Service Center or SQL Documented in IBM DSN VIEWREF TABLE DSN_VIEWREF_TABLE DB2 9 Performance DSN_QUERY_TABLE Guide DSN_PGRANGE_TABLE DSN_SORTKEY_TABLE DSN_SORT_TABLE DSN_DETCOST_TABLE PLAN_TABLE DSN FILTER TABLE DSN_FILTER_TABLE DSN_PTASK_TABLE DSN_PGROUP_TABLE DSN_STRUCT_TABLE DSN_PREDICAT_TABLE
YL&A 1997-2009
EXPLAIN Tables Explained The DB2 EXPLAIN facility populates the EXPLAIN tables
If any of the EXPLAIN Tables exist for the Userid, then they will
be populated automatically when you EXPLAIN The EXPLAIN Tables can be queried just like any other table
Visual Explain and Optimization Service Center define the EXPLAIN tables
YL&A 1997-2009
6/14/2009
EXPLAIN Tables and Columns of Primary Interest When EXPLAINing there are just a few primary tables and columns that should be initially focused on
WARNING!
YL&A 1997-2009
YL&A 1997-2009
6/14/2009
Warnings About Using the Other EXPLAIN Tables Can quite easily query these tables via SQL Should limit what is viewed in the tables These tables exist in support of the IBM query analysis products IBM can change/eliminate them at any time IBM does NOT support your use of these tables beyond the authorized tools Will not respond to issues about these tables You are using them on your own and at your own risk
YL&A 1997-2009
DSN_FILTER_TABLE Contains information about how predicates are used during query processing
YL&A 1997-2009
6/14/2009
YL&A 1997-2009
There can be multiple rows per query block and plan step
Take the one with the smallest value
YL&A 1997-2009
10
6/14/2009
YL&A 1997-2009
LEFT JOIN TABLE (SELECT MIN(X.ONECOMPROWS) AS ONECOMPROWS FROM DSN_DETCOST_TABLE X WHERE M.PROGNAME = X.PROGNAME AND M.QUERYNO = X.QUERYNO AND P.QBLOCKNO = X.QBLOCKNO AND P.PLANNO = X.PLANNO AND M.BIND_TIME = X.EXPLAIN_TIME) AS D ON 1=1 ORDER BY PROGNAME, B_TM, QQP, MIX, F.PREDNO;
YL&A 1997-2009
11
6/14/2009
YL&A 1997-2009
NJ_CUJOG PF CFE PGRNG JT QB_TYP P_QB TB_TYP B_TM -------- -- --- ----- -- ------ ---- ------ -------------------------NNNNN SELECT 0 T 2007-08-13 15:47:24.150000 NNNNN SELECT 0 T 2007-08-13 15:47:24.150000
The number of rows the optimizer thinks will qualify after only local predicates are applied (take the lowest value)
CORR_NM ROWS_POST_FILTER ATYP A_NM -------- ---------------- ---- --------------A 1.0 I XEMP1 B 14.0 I XDEPT1
IXO --N N
The predicate stage (where processed within DB2). Matching, Screening, Stage 1, or Stage 2
The predicate filter factor (percent of rows to be returned based on this predicate alone)
12
6/14/2009
Simple Query Improvement EXPLAINed! The following query has no Boolean Term predicates
EXPLAIN PLAN SET QUERYNO=1 FOR SELECT * FROM DSN8710.EMP WHERE EMPNO = ? OR ( (EMPNO = ? AND LASTNAME >= ?) OR EMPNO > ? ORDER BY EMPNO, LASTNAME;
PRED_TEXT30 NJ_CUJOG PF CFE PGRNG JT QB_TYP P_QB TB_TYP ------------------------------ -------- -- --- ----- -- ------ ---- -----DSN8710.EMP.EMPNO=(EXPR) NNNNN SELECT 0 T DSN8710.EMP.EMPNO=(EXPR) NNNNN SELECT 0 T DSN8710.EMP.LASTNAME>=(EXPR) NNNNN SELECT 0 T DSN8710.EMP.EMPNO>(EXPR) NNNNN SELECT 0 T
STAGE FF --------- -----------STAGE1 .0238095223 STAGE1 .0238095223 STAGE1 .3333333134 STAGE1 .3333333134 MATCHING .3333333134
13
6/14/2009
Complicated Output The examples shown here are not perfect Output can be influenced by Compound predicates Multi-Index Multi Index access More rows of data than are needed can appear Be careful and adjust queries as needed Joining to additional EXPLAIN tables can further complicate the output
YL&A 1997-2009
Reading the Tables Separately If the output from the Advanced Query is too complicated Can reading each table separately Always y read the PLAN_TABLE _ first to g get the Big g Picture on the access path Reading each table separately Easier to do Have to put the data together yourself Can provide more information than the advanced explain join query query, or even the Explain Products
YL&A 1997-2009
14
6/14/2009
Reading Tables Separately Example Here are queries to read the Filter and Predicate Tables
SELECT SUBSTR(P.PROGNAME, 1, 8) AS PROGNAME ,SUBSTR(DIGITS(P.QUERYNO), 6) CONCAT '-' CONCAT SUBSTR(DIGITS(P.QBLOCKNO), 4) AS QQ, Addition predicate PREDNO, FILTER_FACTOR, BOOLEAN_TERM AS BT, information is pulled: join JOIN, AFTER_JOIN AS AJ, ADDED_PRED AS AP, predicate, after join REDUNDANT_PRED AS RP, KEYFIELD, substr(TEXT,1,40), EXPLAIN_TIME AS B_TMpredicate, added (generated) predicate, and redundant FROM DSN_PREDICAT_TABLE P predicate flags ORDER BY PROGNAME, B_TM, QQ, PREDNO;
YL&A 1997-2009
The predicate number, filter factor and boolean term flag is pulled from the DSN_PREDICATE_TABLE
YL&A 1997-2009
15
6/14/2009
This fourth predicate was generated by DB2 via predicate transitive closure
YL&A 1997-2009
Query text before and after query transformation Qualified partitions for a page range scan The keys y for all sorts in a query Sort operations required Information about query parallelism Information about each query block in a query
YL&A 1997-2009
16
6/14/2009
DSN_STATEMENT_CACHE_TABLE V8
To populate use keyword ALL is on EXPLAIN STMTCACHE DSN_STATEMENT_CACHE_TABLE is created to hold the output of IFCID 316 and IFCID 318 Two different sets of information that can be collected from the SQL statements in the dynamic y statement cache STMTCACHE with the STMTID or STMTTOKEN
Information is written only DSN_STATEMENT_CACHE_TABLE Co Consists s sts o of o one e row o pe per SQ SQL state statement e t in t the e dy dynamic a c state statement e t cac cache e
for which the current authorization ID is authorized to execute.
17
6/14/2009
DSN_STATEMENT_CACHE_TABLE V8
STMT_ID STMT_TOKEN COLLID PROGRAM_NAME INV DROPALT INV_DROPALT INV_REVOKE INV_LRU INV_RUNSTATS CACHED_TS USERS Statement ID, EDM unique token Statement token. User-provided identification string Collection id value is DSNDYNAMICSQLCACHE Program name, Name of package or DBRM that performed the initial PREPARE Invalidated by DROP/ALTER Invalidated by REVOKE Removed from cache by LRU Invalidated by RUNSTATS TS Timestamp when statement was cached Number of current users of statement. These are the users that have prepared or executed the statement during their current unit of work. Number of copies of the statement owned by all threads in the system Precompiler line number from the initial PREPARE User ID - Primary authorization ID of the user that did the initial PREPARE CURRENT SQLID of the user that did the initial prepare
YL&A 1997-2009
DSN_STATEMENT_CACHE_TABLE (cont..) V8
BIND_QUALIFIER BIND_ISO BIND_C BIND_DYNRL BIND DEGRE BIND_DEGRE BIND_SQLRL BIND_CHOLD STAT_TS STAT_EXEC STAT_GPAG STAT_SYNR STAT WRIT STAT_WRIT STAT_EROW STAT_PROW STAT_SORT STAT_INDX STAT_RSCN Bind Qualifier, object qualifier for unqualified table names ISOLATION BIND option: , 'UR' - Uncommitted Read , 'CS' - Cursor Stability , 'RS' - Read Stability , 'RR' - Repeatable Read DATA CURRENTDATA BIND option: - 'Y' - CURRENTDATA(YES) - 'N' - CURRENTDATA(NO) DYNAMICRULES BIND option: - 'B' - DYNAMICRULES(BIND), 'R' - DYNAMICRULES(RUN) CURRENT DEGREE value: - 'A' A - CURRENT DEGREE = ANY , '1' 1 - CURRENT DEGREE = 1 CURRENT RULES value: D' - CURRENT RULES = DB2, 'S' - CURRENT RULES = SQL Cursor WITH HOLD bind option 'Y' - Initial PREPARE was done for a cursor WITH HOLD, 'N' - Initial PREPARE was not done for a cursor WITH HOLD Timestamp of stats when IFCID 318 is started Number of executions of statement. For a cursor statement, this is the number of OPENs Number of getpage operations performed for statement Number of synchronous buffer reads performed for statement N b of Number f buffer b ff write it operations ti performed f d for f statement t t t Number of rows examined for statement Number of rows processed for statement Number of sorts performed for statement Number of index scans performed for statement Number of table space scans performed for statement
YL&A 1997-2009
18
6/14/2009
DSN_STATEMENT_CACHE_TABLE (cont..) V8
STAT_PGRP STAT_ELAP STAT_CPU STAT_SUS_SYNIO STAT_SUS_LOCK STAT_SUS_SWIT STAT_SUS_GLCK STAT_SUS_OTHR STAT_SUS_OTHW STAT_RIDLIMT STAT_RIDSTOR EXPLAIN_TS SCHEMA STMT_TEXT STMT_ROWID Number of parallel groups created for statement Accumulated elapsed time used for statement Accumulated CPU time used for statement Accumulated wait time for synchronous I/O Accumulated wait time for lock and latch request Accumulated wait time for synchronous execution unit switch Accumulated wait time for global locks Accumulated wait time for read activity done by another thread Accumulated wait time for write activity done by another thread Number of times a RID list was not used because the number of RIDs would have exceeded one or more DB2 limits Number of times a RID list was not used because not enough storage was available to hold the list of RIDs When statement cache table is populated CURRENT SCHEMA value Statement text Statement ROWID
YL&A 1997-2009
DSN_STATEMENT_CACHE_TABLE V9
New Columns in V9
BIND RA TOT BIND_RA_TOT
Total number of rebinds that have been issued for the dynamic statement due to REOPT(AUTO)
BIND_TO_TYPE
N REOPT(NONE) or its equivalent 1 REOPT(ONCE) or its equivalent A REOPT(AUTO) ( ) O Current plan is deemed as optimal and no need for further REOPT(AUTO)
YL&A 1997-2009
19
6/14/2009
DSN_STATMENT_CACHE_TABLE Usage
SELECT cached_ts, STAT_EXEC, dec(stat_elap,12,2) as stat_elap, dec(STAT_CPU,12,2) as stat_cpu, left(STMT_TEXT,100) as short_text from UID1.DSN_STATEMENT_CACHE_TABLE where primauth = ABC' and explain_ts > '2008-08-27-00.00.00.000000' order by stat_cpu desc
An example statement extracting elapsed and CPU time f queries for i in i th the d dynamic i SQL cache, h i including l di th the fi first t 100 characters of the SQL text. Could also get STMTID and then obtain the access path information from the cache.
YL&A 1997-2009
Example Output
CACHED_TS STAT_EXEC STAT_ELAP STAT_CPU SHORT_TEXT -------------------------------------------------------------------------------------------------------------------------2008-08-26 01:55:29.340787 341295 7050.42 1924.97 SELECT 2008-08-26 01:55:24 01:55:24.243727 243727 2008-08-26 01:55:30.130466 252134 193977 5508.16 5508 16 2943.68 1741.26 1741 26 930.89 SELECT SELECT
An example statement extracting elapsed and CPU time for queries in the dynamic SQL cache, including the SQL text (just the first few characters in this example).
YL&A 1997-2009
20
6/14/2009