An Introduction to SQL Tuning for aDB2 for z/OS EnvironmentWillie FaveroData Warehouse on System z Swat Team (DB2 SME)Sess...
Notices This information was developed for products and services offered in the U.S.A. Note to U.S. Government Users Restr...
Trademarks    This presentation contains trade-marked IBM products and    technologies. Refer to the following Web site:  ...
Acknowledgements    Terry Purcell - DB2 for z/OS Query Optimization       – “Why did the DB2 for z/OS optimizer choose tha...
Standard Caveats                                                Bu   ort ort Save stats  S S                              ...
Performance Goals and Measurements                             Performance: the manner in which or the efficiency with    ...
What Is Tuning?    Reducing Wait Times Due to:              • I/O contention, Locks, Logs, etc...    Avoiding or reduce I/...
BTW, When You’re talking I/O…             These two terms are different…    GETPAGE       –How DB2 satisfies your request ...
Establish Goals     “You can’t start a journey without a destination”      “You can’t start a journey without a destinatio...
The Process                             Monitor                                                                           ...
Performance Monitoring Cycle    Devise a Monitoring Strategy       –Estimation, Continuous, Periodic, Fire Fighting    Whe...
What About Traces?    How are you going to start them?       –Auto/Manual    Destination    Trace Intervals    Statistics ...
As an Example… (DB2 for z/OS Trace Facilities)    Accounting       –Individual Application Performance       –Class 1, 2, ...
Other DB2 Traces    Performance       –Monitors Program, Subsystem and Resources       –Many Classes and IFCIDS           ...
Where Could One Spend Their Time Tuning?                                     SQLProcessorDiskOperating System             ...
Access Path Selection                 Statistics from                           Valid SQL                     DB2 Internal...
Statistics    DB2 Catalog tables used for optimization       –SYSIBM.SYSTABLES       –SYSIBM.SYSTABLESPACE       –SYSIBM.S...
Statistics      -1 (negative 1) is not a statistic       –One size does NOT fits all    RUNSTATS       –More statistics ar...
Pause for                             Questions                               Copyright © 2011 IBM CorporationTuning DB2 f...
Unformatted? EXPLAIN PLAN SET QUERYNO = 1 FOR  SELECT DISTINCT ITEM.ITEM_NBR AS ITEM_NBR,  ITEM.PRDT_ID, STOREITEM.WK_STRT...
Formatted? EXPLAIN PLAN SET QUERYNO = 1 FOR  SELECT DISTINCT ITEM.ITEM_NBR AS ITEM_NBR       , ITEM.PRDT_ID       , STOREI...
Analyzing Query    Observe “interesting predicates”       –Optimizer may produce inaccurate filter factor estimate       –...
Query Breakdown  SELECT  …  FROM    SETL_TRANS S         ,BRANCH CUST         ,BRANCH_ADDR A  WHERE S.ADV_ABA_R = ?  AND  ...
Identify Peculiar Predicates  SELECT  …  FROM    SETL_TRANS S         ,BRANCH CUST         ,BRANCH_ADDR A  WHERE S.ADV_ABA...
Why Are They Peculiar?    Predicates with typical default often skewed    AND               S.PROCESS_DT < ‘9999-12-31’   ...
Analyzing Query    Embed information within statement       –Table information              • CARDF              • NPAGES ...
Embed Statistics  SELECT             …  FROM               SETL_TRANS S             CARDF 1,600,254    NPAGES 21,627      ...
Embed Statistics  SELECT             …  FROM               SETL_TRANS S             CARDF 1,600,254    NPAGES 21,627      ...
Embed Statistics  SELECT             …  FROM               SETL_TRANS S             CARDF 1,600,254    NPAGES 21,627      ...
Embed Statistics  SELECT             …  FROM               SETL_TRANS S             CARDF 1,600,254    NPAGES 21,627      ...
Embed Statistics  SELECT             …  FROM               SETL_TRANS S             CARDF 1,600,254    NPAGES 21,627      ...
Range Predicate Interpolation         Table 104. Default filter factors for interpolation           COLCARDF              ...
Range With Parameter Marker  Error is how different the optimizers DEFAULT estimate is from ACTUAL filtering.  3) AND CUST...
Suspicious Predicate Analysis    Conclusion       –The range predicates with parameter markers introduce significant      ...
Pause                             simply for effect                                 Copyright © 2011 IBM CorporationTuning...
Dynamic Statement Cache    Introduced in DB2 V5    Re-uses SQL and access path       –If identical SQL string       –If sa...
Activate Dynamic Statement Cache    Dynamic Statement cache must be active       –Install panel              • CACHE DYNAM...
Literal Replacement        Dynamic SQL with literals can now be re-used in the cache            – Literals replaced with &...
Literal Replacement …    Example:              WHERE ACCOUNT_NUMBER = 123456       –This would be replaced by         WHER...
Start Trace for Cache (1 of 2)    Non-Data-Sharing       -START TRACE(MON) CLASS(1) IFCID(316,317,318)        DEST(SMF)   ...
Start Trace for Cache (2 of 2)    IFCID 316       –First 60 bytes of SQL statement plus identifying information and       ...
Create Tables Used by EXPLAIN    Create necessary EXPLAIN table       –Optimization Service Center (OSC)              or  ...
Get Dynamic Statement Cache    Snapping the statement cache to cache table       –EXPLAIN STMTCACHE ALL              • Can...
Invalidating Statement Cache    Execute RUNSTATS utility with the options       –UPDATE NONE REPORT NO              • This...
Statement Removal    Least Recently Used (LRU) algorithm used to remove    statements from cache                          ...
Pause                             This time, a new thought                             and to catch my breath             ...
REOPT    V8 REOPT options       –Dynamic SQL       –REOPT(NONE, ONCE, ALWAYS)       –Static SQL       –REOPT(NONE, ALWAYS)...
Dynamic SQL REOPT - AUTO    For dynamic SQL with parameter markers    DB2 will automatically re-optimize the SQL when filt...
REOPT(ALWAYS) - REOPT(ONCE)    REOPT(ALWAYS)       –DB2 always uses literal values that are provided for parameter markers...
IBM Smart Analytics Optimizer            Capitalizing on the best of relational and the best of columnar databasesWhat is ...
Summary    Prepare a query for analysis       – Format       – Annotation    Perform query analysis       – Qualified row ...
More information on zEnterprise    IBM zEnterprise Announcement Landing Page:    ibm.com/systems/zenterprise196    IBM zEn...
Thai                                                                 Traditional Chinese                                  ...
Willie Favero                   Senior Certified Consulting IT Software Specialist                                   Dynam...
Upcoming SlideShare
Loading in...5
×

An Intro to Tuning Your SQL on DB2 for z/OS

5,538

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,538
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
183
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

An Intro to Tuning Your SQL on DB2 for z/OS

  1. 1. An Introduction to SQL Tuning for aDB2 for z/OS EnvironmentWillie FaveroData Warehouse on System z Swat Team (DB2 SME)Session #8762Tuesday, March 1, 2011: 3:00 PM - 4:00 PM Copyright © 2011 IBM Corporation © 2010 IBM Corporation All rights reserved
  2. 2. Notices This information was developed for products and services offered in the U.S.A. Note to U.S. Government Users Restricted Rights — Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the users responsibility to evaluate and verify the operation of any non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to: IBM Director of Licensing, IBM Corporation, North Castle Drive Armonk, NY 10504-1785 U.S.A. The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk. IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental. COPYRIGHT LICENSE: This information contains sample application programs in source language, which illustrates programming techniques on various operating platforms. You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing, or distributing application programs conforming to IBMs application programming interfaces. Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 2 of 59 All rights reserved
  3. 3. Trademarks This presentation contains trade-marked IBM products and technologies. Refer to the following Web site: http://www.ibm.com/legal/copytrade.shtml Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 3 of 59 All rights reserved
  4. 4. Acknowledgements Terry Purcell - DB2 for z/OS Query Optimization – “Why did the DB2 for z/OS optimizer choose that access path?” • IDUG 2010 – “Whats new from the optimizer in DB2 10 for z/OS?” • IDUG 2010 – “Whats new for SQL Optimization in IBM DB2 9 for z/OS” • IOD 2009 Pat Bossman - DB2 for z/OS Query Optimization – “How to tune a query” • 2010 James Guo – DB2 for z/OS Performance – DB2 9 for z/OS Selected Query Performance Enhancements • IDUG 2007 John J. Campbell - DB2 for z/OS Development – “DB2 for z/OS Hints & Tips for Robust Defensive Performance” • IOD Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 4 of 59 All rights reserved
  5. 5. Standard Caveats Bu ort ort Save stats S S tt Monitor No about the SQL g he oo g Buffer pools EDM What? EDM What? ry Don’t wor It Depen s? d uy ds! eckpoint ru sOn Ch le aid ei any of it sb wM WLM Policy? o ett H Many is better than one???? th w rt er th um as So an ma OS Sort b a ry! Need faster DISK C ny VaMemories Cheap !!! and/or ay Disk is cheap a ge M ile My head Hurts! Why ca n’t it go our M faster Y No S No S o o Sort rt Sort rt Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  6. 6. Performance Goals and Measurements Performance: the manner in which or the efficiency with which something reacts or fulfills its intended purpose. Performance Goals: were we want to be, what we want to achieve Performance Goals should equal your Business Goals Performance Measurements: how we determine if we are making our goals Your Processes and Your Tools Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 6 of 59 All rights reserved
  7. 7. What Is Tuning? Reducing Wait Times Due to: • I/O contention, Locks, Logs, etc... Avoiding or reduce I/O Controlling Virtual Storage Consumption Question Number one Should Be: Where Do I Begin? Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  8. 8. BTW, When You’re talking I/O… These two terms are different… GETPAGE –How DB2 satisfies your request for data from a page I/O –What DB2 uses if page needed is NOT in the buffer pool Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 8 of 59 All rights reserved
  9. 9. Establish Goals “You can’t start a journey without a destination” “You can’t start a journey without a destination” What is your SQL doing? Or not doing? Is it what you want it to do? No, what do you want it to do ? How fast is Fast? OLTP? Batch? Distributed? Data Warehouse? Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  10. 10. The Process Monitor Do Tune Forever Repeat The “Tools” available just keep on getting better Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 10 of 59 All rights reserved
  11. 11. Performance Monitoring Cycle Devise a Monitoring Strategy –Estimation, Continuous, Periodic, Fire Fighting Where to Find Performance Data Reviewing Reports Determine Constraints/Bottlenecks Modify the Application Review Reports –Were objectives met ? –Can the objectives be met ? –What are the trade-off ? Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  12. 12. What About Traces? How are you going to start them? –Auto/Manual Destination Trace Intervals Statistics or Accounting Trace Levels LUW equivalents Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 12 of 59 All rights reserved
  13. 13. As an Example… (DB2 for z/OS Trace Facilities) Accounting –Individual Application Performance –Class 1, 2, 3, 7, 8 Statistics –DB2 System Wide –Class 1, 3, 4, 5, 6 Audit –DB2 Security Control –Class 1-8 All Default to SMF –Can go to GTF or IFI –SMF Record Types 100, 101, 102 –Can Be Started by DB2 at startup Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  14. 14. Other DB2 Traces Performance –Monitors Program, Subsystem and Resources –Many Classes and IFCIDS • Considering tracing specific IFCIDs only –Can only be started by command –Usual Destination is GTF Monitor and Global –For Vendors and IBM Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  15. 15. Where Could One Spend Their Time Tuning? SQLProcessorDiskOperating System Database DesignNetworkLocal WorkDatabase System BTW, this is my opinion… Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 15 of 59 All rights reserved
  16. 16. Access Path Selection Statistics from Valid SQL DB2 Internal Cost DB2 Catalog Formulas DB2 Next Slide Optimizer Cost Cost I/O based SQL optimization CPU Cost TS Scan vs. Index Scan Traversing Rows and Index Scan Pages (MATCHCOLS, Applying CLUSTERRATION) Predicates(RDS vs. Workfile Scans DM) DSNDB07 Cost of sorting Etc…. Etc… = "Least Cost Access Path" Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access All rights reserved
  17. 17. Statistics DB2 Catalog tables used for optimization –SYSIBM.SYSTABLES –SYSIBM.SYSTABLESPACE –SYSIBM.SYSTABSTATS –SYSIBM.SYSCOLDIST –SYSIBM.SYSCOLSTATS –SYSIBM.SYSCOLUMNS –SYSIBM.SYSINDEXES –SYSIBM.SYSINDEXPART –SYSIBM.SYSKEYTARGETS –SYSIBM.SYSKEYTGTDIST –SYSIBM.SYSROUTINES –All catalog tables and catalog table columns that affect the optimizer are explained in the “Performance Monitoring and Tuning Guide” product publication in Chapter 11 Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 17 of 59 All rights reserved
  18. 18. Statistics -1 (negative 1) is not a statistic –One size does NOT fits all RUNSTATS –More statistics are not always better –Running RUNSTATS does have a cost –Consider Statistics Advisor • Optimizer Service Center (deprecated in DB2 9) • Data Studio (stand alone version only) • Optim Query Tuner • Optim Query Workload Tuner Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 18 of 59 All rights reserved
  19. 19. Pause for Questions Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 19 of 59 All rights reserved
  20. 20. Unformatted? EXPLAIN PLAN SET QUERYNO = 1 FOR SELECT DISTINCT ITEM.ITEM_NBR AS ITEM_NBR, ITEM.PRDT_ID, STOREITEM.WK_STRT_DT AS WK_STRT_DT ,STOREITEM.DC_ID AS DC_ID FROM PROD.TIPA004_STITM_PROJ AS STOREITEM , PROD.TITM001_ITEM AS ITEM WHERE ITEM.BUS_UNIT_ID = ‘GS‘ AND ITEM.BUS_UNIT_ID = STOREITEM.BUS_UNIT_ID AND ITEM.MJR_CATG_ID = 00754‘ AND ITEM.INTMD_CATG_ID = 00043‘ AND ITEM.ITEM_NBR = STOREITEM.ITEM_NBR AND ITEM.MJR_CATG_ID = STOREITEM.MJR_CATG_ID AND ITEM.INTMD_CATG_ID = STOREITEM.INTMD_CATG_ID AND STOREITEM.RTL_DEPT_NBR = 1 AND AD_ITEM_FLG = Y‘ AND WK_STRT_DT = 2002-02-08; Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 20 of 59 All rights reserved
  21. 21. Formatted? EXPLAIN PLAN SET QUERYNO = 1 FOR SELECT DISTINCT ITEM.ITEM_NBR AS ITEM_NBR , ITEM.PRDT_ID , STOREITEM.WK_STRT_DT AS WK_STRT_DT , STOREITEM.DC_ID AS DC_ID FROM PROD.TIPA004_STITM_PROJ AS STOREITEM ,PROD.TITM001_ITEM AS ITEM WHERE ITEM.BUS_UNIT_ID = STOREITEM.BUS_UNIT_ID AND ITEM.MJR_CATG_ID = STOREITEM.MJR_CATG_ID AND ITEM.INTMD_CATG_ID = STOREITEM.INTMD_CATG_ID AND ITEM.ITEM_NBR = STOREITEM.ITEM_NBR AND ITEM.BUS_UNIT_ID = ‘GS‘ AND ITEM.MJR_CATG_ID = 00754‘ AND ITEM.INTMD_CATG_ID = 00043‘ AND STOREITEM.AD_ITEM_FLG = Y‘ AND STOREITEM.RTL_DEPT_NBR = 1 AND STOREITEM.WK_STRT_DT = 2002-02-08; Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 21 of 59 All rights reserved
  22. 22. Analyzing Query Observe “interesting predicates” –Optimizer may produce inaccurate filter factor estimate –Range predicates with parameter markers –Predicates using interesting literals • Probable defaults –Complex predicates • Complex OR expressions • Negation predicates • Column expressions • Non-column expressions Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 22 of 59 All rights reserved
  23. 23. Query Breakdown SELECT … FROM SETL_TRANS S ,BRANCH CUST ,BRANCH_ADDR A WHERE S.ADV_ABA_R = ? AND S.PROCESS_DT < 9999-12-31‘ AND S.TYPE_CD IN (A, ‘C’, ‘X’) AND S.CLR_CYCLE_CD IN (EOD, IMD‘, ‘OPN’) AND S.STLMT_DT = ? AND S.ACCT_NUM = CUST.ACCT_NUM AND CUST.CUST_EFCT_DT <= ? AND CUST.CUST_INACTV_DT > ? AND A.ACCT_NUM = CUST.ACCT_NUM AND A.CUST_EFCT_DT <= ? AND A.CUST_INACTV_DT > ? AND A.ADDR_TYP_CD = Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 23 of 59 All rights reserved
  24. 24. Identify Peculiar Predicates SELECT … FROM SETL_TRANS S ,BRANCH CUST ,BRANCH_ADDR A WHERE S.ADV_ABA_R = ? AND S.PROCESS_DT < ‘9999-12-31’ MAX DATE AND S.TYPE_CD IN (A, C, ‘X‘, ‘Z’) AND S.CLR_CYCLE_CD IN (EOD, IMD‘, ‘OPN’) AND S.STLMT_DT = ? AND S.ACCT_NUM = CUST.ACCT_NUM AND CUST.CUST_EFCT_DT <= ? Range with marker AND CUST.CUST_INACTV_DT > ? Range with marker AND A.ACCT_NUM = CUST.ACCT_NUM AND A.CUST_EFCT_DT <= ? Range with marker AND A.CUST_INACTV_DT > ? Range with marker AND A.ADDR_TYP_CD = ‘ COL = blank Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 24 of 59 All rights reserved
  25. 25. Why Are They Peculiar? Predicates with typical default often skewed AND S.PROCESS_DT < ‘9999-12-31’ MAX DATE AND A.ADDR_TYP_CD = ‘ COL = blank Range predicates with parameter markers - Impossible to estimate without literal AND CUST.CUST_EFCT_DT <= ? Range with marker AND CUST.CUST_INACTV_DT > ? Range with marker AND A.CUST_EFCT_DT <= ? Range with marker AND A.CUST_INACTV_DT > ? Range with marker Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 25 of 59 All rights reserved
  26. 26. Analyzing Query Embed information within statement –Table information • CARDF • NPAGES –Column information for predicates • Local predicates • Join predicates –Observe where the filtering is • Selectivity of a predicate is relative to table cardinality Investigate “suspicious” predicates –Determine actual versus estimated filtering –If there is a problem, identify options Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 26 of 59 All rights reserved
  27. 27. Embed Statistics SELECT … FROM SETL_TRANS S CARDF 1,600,254 NPAGES 21,627 ,BRANCH CUST CARDF 31,696 NPAGES 1132 ,BRANCH_ADDR A CARDF 58,627 NPAGES 2791 WHERE S.ADV_ABA_R = ? COLCARDF 19,712 AND S.PROCESS_DT < ‘9999-12-31’ COLCARDF 11 LOW2KEY 2004-03-24 HIGH2KEY 2004-04-05 AND S.TYPE_CD IN (A, C, ‘X‘, ‘Z’) COLCARDF 4 AND S.CLR_CYCLE_CD IN (EOD, IMD, ‘OPN‘)COLCARDF 3 AND S.STLMT_DT = ? COLCARDF 13 AND S.ACCT_NUM = CUST.ACCT_NUM COLCARDF 15360 / 26,527 AND CUST.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND CUST.CUST_INACTV_DT > ? COLCARDF 279 LOW2KEY 2004-03-04 HIGH2KEY 2004-04-07 AND A.ACCT_NUM = CUST.ACCT_NUM COLCARDF 26,527 / 26,527 AND A.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND A.CUST_INACTV_DT > ? COLCARDF 274 LOW2KEY ‘2004-03-04’ HIGH2KEY ‘2004-04-07’ AND A.ADDR_TYP_CD = ‘ ‘ COLCARDF 5 Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 27 of 59 All rights reserved
  28. 28. Embed Statistics SELECT … FROM SETL_TRANS S CARDF 1,600,254 NPAGES 21,627 ,BRANCH CUST CARDF 31,696 NPAGES 1132 ,BRANCH_ADDR A CARDF 58,627 NPAGES 2791 WHERE S.ADV_ABA_R = ? COLCARDF 19,712 AND S.PROCESS_DT < ‘9999-12-31’ COLCARDF 11 LOW2KEY 2004-03-24 HIGH2KEY 2004-04-05 AND S.TYPE_CD IN (A, C, ‘X‘, ‘Z’) COLCARDF 4 AND S.CLR_CYCLE_CD IN (EOD, IMD, ‘OPN‘)COLCARDF 3 AND S.STLMT_DT = ? COLCARDF 13 AND S.ACCT_NUM = CUST.ACCT_NUM COLCARDF 15360 / 26,527 AND CUST.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND CUST.CUST_INACTV_DT > ? COLCARDF 279 LOW2KEY 2004-03-04 HIGH2KEY 2004-04-07 AND A.ACCT_NUM = CUST.ACCT_NUM COLCARDF 26,527 / 26,527 AND A.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND A.CUST_INACTV_DT > ? COLCARDF 274 LOW2KEY ‘2004-03-04’ HIGH2KEY ‘2004-04-07’ AND A.ADDR_TYP_CD = ‘ ‘ COLCARDF 5 Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 28 of 59 All rights reserved
  29. 29. Embed Statistics SELECT … FROM SETL_TRANS S CARDF 1,600,254 NPAGES 21,627 ,BRANCH CUST CARDF 31,696 NPAGES 1132 ,BRANCH_ADDR A CARDF 58,627 NPAGES 2791 WHERE S.ADV_ABA_R = ? COLCARDF 19,712 AND S.PROCESS_DT < ‘9999-12-31’ COLCARDF 11 LOW2KEY 2004-03-24 HIGH2KEY 2004-04-05 AND S.TYPE_CD IN (A, C, ‘X‘, ‘Z’) COLCARDF 4 AND S.CLR_CYCLE_CD IN (EOD, IMD, ‘OPN‘)COLCARDF 3 AND S.STLMT_DT = ? COLCARDF 13 AND S.ACCT_NUM = CUST.ACCT_NUM COLCARDF 15360 / 26,527 AND CUST.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND CUST.CUST_INACTV_DT > ? COLCARDF 279 LOW2KEY 2004-03-04 HIGH2KEY 2004-04-07 AND A.ACCT_NUM = CUST.ACCT_NUM COLCARDF 26,527 / 26,527 AND A.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND A.CUST_INACTV_DT > ? COLCARDF 274 LOW2KEY ‘2004-03-04’ HIGH2KEY ‘2004-04-07’ AND A.ADDR_TYP_CD = ‘ ‘ COLCARDF 5 Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 29 of 59 All rights reserved
  30. 30. Embed Statistics SELECT … FROM SETL_TRANS S CARDF 1,600,254 NPAGES 21,627 ,BRANCH CUST CARDF 31,696 NPAGES 1132 ,BRANCH_ADDR A CARDF 58,627 NPAGES 2791 WHERE S.ADV_ABA_R = ? COLCARDF 19,712 AND S.PROCESS_DT < ‘9999-12-31’ COLCARDF 11 LOW2KEY 2004-03-24 HIGH2KEY 2004-04-05 AND S.TYPE_CD IN (A, C, ‘X‘, ‘Z’) COLCARDF 4 AND S.CLR_CYCLE_CD IN (EOD, IMD, ‘OPN‘)COLCARDF 3 AND S.STLMT_DT = ? COLCARDF 13 AND S.ACCT_NUM = CUST.ACCT_NUM COLCARDF 15360 / 26,527 AND CUST.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND CUST.CUST_INACTV_DT > ? COLCARDF 279 LOW2KEY 2004-03-04 HIGH2KEY 2004-04-07 AND A.ACCT_NUM = CUST.ACCT_NUM COLCARDF 26,527 / 26,527 AND A.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND A.CUST_INACTV_DT > ? COLCARDF 274 LOW2KEY ‘2004-03-04’ HIGH2KEY ‘2004-04-07’ AND A.ADDR_TYP_CD = ‘ ‘ COLCARDF 5 Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 30 of 59 All rights reserved
  31. 31. Embed Statistics SELECT … FROM SETL_TRANS S CARDF 1,600,254 NPAGES 21,627 ,BRANCH CUST CARDF 31,696 NPAGES 1132 ,BRANCH_ADDR A CARDF 58,627 NPAGES 2791 WHERE S.ADV_ABA_R = ? COLCARDF 19,712 AND S.PROCESS_DT < ‘9999-12-31’ COLCARDF 11 LOW2KEY 2004-03-24 HIGH2KEY 2004-04-05 AND S.TYPE_CD IN (A, C, ‘X‘, ‘Z’) COLCARDF 4 AND S.CLR_CYCLE_CD IN (EOD, IMD, ‘OPN‘)COLCARDF 3 AND S.STLMT_DT = ? COLCARDF 13 AND S.ACCT_NUM = CUST.ACCT_NUM COLCARDF 15360 / 26,527 AND CUST.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND CUST.CUST_INACTV_DT > ? COLCARDF 279 LOW2KEY 2004-03-04 HIGH2KEY 2004-04-07 AND A.ACCT_NUM = CUST.ACCT_NUM COLCARDF 26,527 / 26,527 AND A.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 AND A.CUST_INACTV_DT > ? COLCARDF 274 LOW2KEY ‘2004-03-04’ HIGH2KEY ‘2004-04-07’ AND A.ADDR_TYP_CD = ‘ ‘ COLCARDF 5 Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 31 of 59 All rights reserved
  32. 32. Range Predicate Interpolation Table 104. Default filter factors for interpolation COLCARDF Filter factor for OP Filter Factor for LIKE / BETWEEN >= 100,000,000 1 / 10,000 3 / 100,000 >= 10,000,000 1 / 3,000 1 / 10,000 >= 1,000,000 1 / 1,000 3 / 10,000 >= 100,000 1 / 300 1 / 1,000 >= 10,000 1 / 100 3 / 1,000 >= 1,000 1 / 30 1 / 100 >= 100 1 / 10 3 / 100 >= 2 1/3 1 / 10 =1 1 1 >= 0 1/3 1 / 10 Note: Op is one of these operators: <, <=, >, >=. COMMENT: This is DB2’s documented guess for an impossible to estimate Filter factor. Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 32 of 59 All rights reserved
  33. 33. Range With Parameter Marker Error is how different the optimizers DEFAULT estimate is from ACTUAL filtering. 3) AND CUST.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 ESTIMATED FF WITH LITERAL: = 100% ESTIMATE WITH MARKER: 1/30 = 3% ( 97% error ) 4) AND CUST.CUST_INACTV_DT > ? COLCARDF 279 LOW2KEY 2004-03-04 HIGH2KEY 2004-04-07 ESTIMATED FF WITH LITERAL: = 99% ESTIMATE WITH MARKER: 1/10 = 10% ( 89% error ) 5) AND A.CUST_EFCT_DT <= ? COLCARDF 2,496 LOW2KEY 1994-09-02 HIGH2KEY 2004-04-06 ESTIMATED FF WITH LITERAL: = 100% ESTIMATE WITH MARKER: 1/30 = 3% ( 97% error ) 6) AND A.CUST_INACTV_DT > ? COLCARDF 274 LOW2KEY ‘2004-03-04’ HIGH2KEY ‘2004-04-07’ ESTIMATED FF WITH LITERAL: = 99% ESTIMATE WITH MARKER: 1/10 = 10% ( 89% error ) Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 33 of 59 All rights reserved
  34. 34. Suspicious Predicate Analysis Conclusion –The range predicates with parameter markers introduce significant filter factor error. So we should recognize that this filter factor error can cause significant cost estimation problems for the optimizer – possibly resulting in poor access path choice. Which brings us to parameter markers…. Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 34 of 59 All rights reserved
  35. 35. Pause simply for effect Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 35 of 59 All rights reserved
  36. 36. Dynamic Statement Cache Introduced in DB2 V5 Re-uses SQL and access path –If identical SQL string –If same user,… Avoids full prepare (like a BIND) Good programming practice to use parameter marker (?) –? are parameter markers – Ensures SQL is always the same Not all programs use ? –Ruby On Rails generates literals not ? –So SQL can not be re-used in Cache Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 36 of 59 All rights reserved
  37. 37. Activate Dynamic Statement Cache Dynamic Statement cache must be active –Install panel • CACHE DYNAMIC SQL field • Acceptable values: 5000 to 1048576 KB • Initial calculation: EDMSTMTC = (EDMPOOL * 3) + (EDMPOOL/8) or –DSNZPARM • DSN6SPRM macro and CACHEDYN keyword Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 37 of 59 All rights reserved
  38. 38. Literal Replacement Dynamic SQL with literals can now be re-used in the cache – Literals replaced with & (similar to parameter markers but not the same) To enable either you:- – Put CONCENTRATE STATEMENTS WITH LITERALS in the “attribute- string” in the PREPARE’s ATTRIBUTES keyword – Or set LITERALREPLACEMENT in the ODBC initialization file – Or set the keyword enableLiteralReplacement=’YES’ in the JCC Driver Lookup Sequence – Original SQL with literals is looked up in the cache – If not found, literals are replaced and new SQL is looked up in the cache • Additional match on literal usability • Can only match with SQL stored with same attribute, not parameter marker – If not found, new SQL is prepared and stored in the cache Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 38 of 59 All rights reserved
  39. 39. Literal Replacement … Example: WHERE ACCOUNT_NUMBER = 123456 –This would be replaced by WHERE ACCOUNT_NUMBER = & Performance Expectation –Using parameter marker still provides best performance –Biggest performance gain for small SQL with literals that can now have a cache –NOTE: Access path is not optimized to provided literals • True for parameter markers/host variables today • Need to use REOPT for that purpose Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 39 of 59 All rights reserved
  40. 40. Start Trace for Cache (1 of 2) Non-Data-Sharing -START TRACE(MON) CLASS(1) IFCID(316,317,318) DEST(SMF) Data-Sharing -START TRACE(MON) CLASS(1) IFCID(316,317,318) DEST(SMF) SCOPE(GROUP) Verify -DIS TRACE(*) Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 40 of 59 All rights reserved
  41. 41. Start Trace for Cache (2 of 2) IFCID 316 –First 60 bytes of SQL statement plus identifying information and statistics • http://publib.boulder.ibm.com/infocenter/tivihelp/v15r1/index.jsp?topic=/com.ibm.ome gamon.xe_db2.doc/ko2rrd20228.htm IFCID 317 –Used in addition to IFCID 316 to obtain the full SQL statement text • http://publib.boulder.ibm.com/infocenter/tivihelp/v15r1/index.jsp?topic=/com.ibm.ome gamon.xe_db2.doc/ko2rrd20228.htm IFCID 318 –Acts as a switch for IFCID 316 to collect all available information • Stop and Start for new interval Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 41 of 59 All rights reserved
  42. 42. Create Tables Used by EXPLAIN Create necessary EXPLAIN table –Optimization Service Center (OSC) or –Optim Query Tuner (was Optimization Expert) or –DSNTIJOS job in SDSNSAMP or –Described in the product manuals • SQL Reference • Performance Monitoring and Tuning Guide (DB2 9 and above) Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 42 of 59 All rights reserved
  43. 43. Get Dynamic Statement Cache Snapping the statement cache to cache table –EXPLAIN STMTCACHE ALL • Can use SPUFI, DSNTEP2, or anything that allows this SQL statement to be executed • Data sharing member specific • If possible, use SYSADM when issuing SQL statement. Only statements using objects your authid is allowed to access are snapped • If DB2 10 – SQLADM – System DBADM Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 43 of 59 All rights reserved
  44. 44. Invalidating Statement Cache Execute RUNSTATS utility with the options –UPDATE NONE REPORT NO • This combination only invalidate statements in the dynamic statement cache without any data access or computation cost • Invalidates statements in all data sharing members DROP or ALTER the characteristic a statement is dependent REORG REBALANCE Rebuild index on a cached statement’s related table Revoking the statements owner’s privileges –Includes roles Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 44 of 59 All rights reserved
  45. 45. Statement Removal Least Recently Used (LRU) algorithm used to remove statements from cache NOT FIFO Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 45 of 59 All rights reserved
  46. 46. Pause This time, a new thought and to catch my breath Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 46 of 59 All rights reserved
  47. 47. REOPT V8 REOPT options –Dynamic SQL –REOPT(NONE, ONCE, ALWAYS) –Static SQL –REOPT(NONE, ALWAYS) V9 Addition for Dynamic SQL –Bind option REOPT(AUTO) Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 47 of 59 All rights reserved
  48. 48. Dynamic SQL REOPT - AUTO For dynamic SQL with parameter markers DB2 will automatically re-optimize the SQL when filtering of one or more of the predicates changes dramatically such that table join sequence or index selection may change Some statistics cached to improve performance of runtime check Newly generated access path will replace the global statement cache copy First optimization is the same as REOPT(ONCE) Followed by analysis of the values supplied at each execution of the statement Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 48 of 59 All rights reserved
  49. 49. REOPT(ALWAYS) - REOPT(ONCE) REOPT(ALWAYS) –DB2 always uses literal values that are provided for parameter markers REOPT(ONCE) –DB2 reoptimizes cached dynamic SQL statements at execution time for the first execution of the statement based on literal values that are provided for parameter markers Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 49 of 59 All rights reserved
  50. 50. IBM Smart Analytics Optimizer Capitalizing on the best of relational and the best of columnar databasesWhat is it? How is it different z/ OS or The IBM Smart Analytics Optimizer is a workload optimized, appliance-like, add-on, that enables the on toB2 f train of Performance: Unprecedented sianalyses frequently blocked by response times enable integration of business insights into operational es or D thought s s query performance. processes to drive winning strategies. It accelerates select queries, with unprecedented response times. u poor r f Connects to DB2 through zeintegration io Integration: providing transparency i rev timdeep applications. y p Op to all e m ics Self-managed workloads: queries are Se lyt executed in the most efficient way a Transparency: applications connected An to DB2, are entirely unaware of the a rt accelerator S m Simplified administration: appliance- like hands-free operations, eliminating IBM many database tuning tasks Breakthrough Technology Enabling New Opportunities Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 50 of 59 All rights reserved
  51. 51. Summary Prepare a query for analysis – Format – Annotation Perform query analysis – Qualified row estimates realistic? • Accurately estimate filtering at table level? • Accurately estimate filtering for predicates? – Evaluate available choices • Reference table, index, indexed columns report • Develop understanding of “plausible” and “desirable” access paths • Examine EXPLAIN output Take targeted action – Collect additional statistics – Provide additional choices – Consider REOPT, optimization hints, tricks Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 51 of 59 All rights reserved
  52. 52. More information on zEnterprise IBM zEnterprise Announcement Landing Page: ibm.com/systems/zenterprise196 IBM zEnterprise HW Landing Page: ibm.com/systems/zenterprise196 IBM zEnterprise Events Landing Page: ibm.com/systems/breakthrough IBM Software: ibm.com/software/os/systemz/announcements IBM System Storage: ibm.com/systems/storage/product/z.html IBM Global Financing: ibm.com/financing/us/lifecycle/acquire/zenterprise/ Global Technology Services: – vanity: ibm.com/services/zenterprise Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 52 of 59 All rights reserved
  53. 53. Thai Traditional Chinese Russian Gracias Spanish Thank You English Merci French Obrigado Brazilian Portuguese Arabic Bedankt Danke German Nederlands Simplified Chinese Japanese Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 53 of 59 All rights reserved
  54. 54. Willie Favero Senior Certified Consulting IT Software Specialist Dynamic Warehousing on System z Swat Team IBM Silicon Valley Laboratory IBM Academic Initiative Ambassador for System z IBM Certified Database Administrator - DB2 Universal Database V8.1 for z/OS IBM Certified Database Administrator – DB2 9 for z/OS IBM Certified System Administrator – DB2 9 for z/OS IBM Certified Database Administrator – DB2 10 for z/OS IBM zChampion wfavero@attglobal.net Copyright © 2011 IBM CorporationTuning DB2 for z/OS Access Slide 54 of 59 All rights reserved
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×