SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
An Introduction to SQL Tuning for a
DB2 for z/OS Environment


Willie Favero
Data Warehouse on System z Swat Team (DB2 SME)
Session #8762
Tuesday, March 1, 2011: 3:00 PM - 4:00 PM




                         Copyright © 2011 IBM Corporation   © 2010 IBM Corporation
                                All rights reserved
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 user's 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 IBM's application programming interfaces.


                                                                              Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                                                                                                                                         Slide 2 of 59
                                                                                     All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 3 of 59
                                    All rights reserved
Acknowledgements
    Terry Purcell - DB2 for z/OS Query Optimization
       – “Why did the DB2 for z/OS optimizer choose that access path?”
              • IDUG 2010
       – “What's new from the optimizer in DB2 10 for z/OS?”
              • IDUG 2010
       – “What's 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 Corporation
Tuning DB2 for z/OS Access                                               Slide 4 of 59
                                            All rights reserved
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 s
On                               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
                                                 Va
Memories 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 Corporation
Tuning DB2 for z/OS Access
                                      All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                              Slide 6 of 59
                                                        All rights reserved
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 Corporation
Tuning DB2 for z/OS Access
                                                     All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                           Slide 8 of 59
                                         All rights reserved
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 Corporation
Tuning DB2 for z/OS Access
                                    All rights reserved
The Process


                             Monitor


                                                                            Do
                             Tune                                         Forever




                             Repeat

                                           The “Tools” available just keep on getting better


                                       Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                                            Slide 10 of 59
                                              All rights reserved
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 Corporation
Tuning DB2 for z/OS Access
                                          All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 12 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access
                                        All rights reserved
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 Corporation
Tuning DB2 for z/OS Access
                                                   All rights reserved
Where Could One Spend Their Time Tuning?




                                     SQL



Processor

Disk

Operating System                                     Database
                                                      Design
Network

Local Work

Database System
                                                                BTW, this is my opinion…
                             Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                                      Slide 15 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access
                                                             All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                  Slide 17 of 59
                                          All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                      Slide 18 of 59
                                                    All rights reserved
Pause for
                             Questions


                               Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                        Slide 19 of 59
                                      All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 20 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 21 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                    Slide 22 of 59
                                                  All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 23 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 24 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                  Slide 25 of 59
                                                All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                         Slide 26 of 59
                                                       All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                           Slide 27 of 59
                                                  All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                           Slide 28 of 59
                                                  All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                           Slide 29 of 59
                                                  All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                           Slide 30 of 59
                                                  All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                           Slide 31 of 59
                                                  All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                   Slide 32 of 59
                                                         All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                              Slide 33 of 59
                                           All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                     Slide 34 of 59
                                           All rights reserved
Pause
                             simply for effect




                                 Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                          Slide 35 of 59
                                        All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                           Slide 36 of 59
                                         All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                      Slide 37 of 59
                                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                     Slide 38 of 59
                                                           All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                     Slide 39 of 59
                                                   All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 40 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                    Slide 41 of 59
                                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                   Slide 42 of 59
                                                 All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                       Slide 43 of 59
                                               All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                   Slide 44 of 59
                                                   All rights reserved
Statement Removal
    Least Recently Used (LRU) algorithm used to remove
    statements from cache




                             NOT FIFO




                             Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                      Slide 45 of 59
                                    All rights reserved
Pause
                             This time, a new thought
                             and to catch my breath




                                    Copyright © 2011 IBM Corporation
Tuning DB2 for z/OS Access                                             Slide 46 of 59
                                           All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 47 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                      Slide 48 of 59
                                    All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                    Slide 49 of 59
                                           All rights reserved
IBM Smart Analytics Optimizer
            Capitalizing on the best of relational and the best of columnar databases

What 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 Corporation
Tuning DB2 for z/OS Access                                                                  Slide 50 of 59
                                               All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                           Slide 51 of 59
                                                         All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                              Slide 52 of 59
                                            All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                                                           Slide 53 of 59
                                                                     All rights reserved
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 Corporation
Tuning DB2 for z/OS Access                                                                                 Slide 54 of 59
                                                              All rights reserved

Contenu connexe

Tendances

A First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM ChangesA First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM Changes
Willie Favero
 

Tendances (12)

DB2 10 Migration Planning & Customer experiences - Chris Crone (IDUG India)
DB2 10 Migration Planning & Customer experiences - Chris Crone (IDUG India) DB2 10 Migration Planning & Customer experiences - Chris Crone (IDUG India)
DB2 10 Migration Planning & Customer experiences - Chris Crone (IDUG India)
 
DB2 for z/OS - Starter's guide to memory monitoring and control
DB2 for z/OS - Starter's guide to memory monitoring and controlDB2 for z/OS - Starter's guide to memory monitoring and control
DB2 for z/OS - Starter's guide to memory monitoring and control
 
A First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM ChangesA First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM Changes
 
A Time Traveller’s Guide to DB2: Technology Themes for 2014 and Beyond
A Time Traveller’s Guide to DB2: Technology Themes for 2014 and BeyondA Time Traveller’s Guide to DB2: Technology Themes for 2014 and Beyond
A Time Traveller’s Guide to DB2: Technology Themes for 2014 and Beyond
 
DB2 Accounting Reporting
DB2  Accounting ReportingDB2  Accounting Reporting
DB2 Accounting Reporting
 
DB2 Design for High Availability and Scalability
DB2 Design for High Availability and ScalabilityDB2 Design for High Availability and Scalability
DB2 Design for High Availability and Scalability
 
An Hour of DB2 Tips
An Hour of DB2 TipsAn Hour of DB2 Tips
An Hour of DB2 Tips
 
IBM DB2 Analytics Accelerator Trends & Directions by Namik Hrle
IBM DB2 Analytics Accelerator  Trends & Directions by Namik Hrle IBM DB2 Analytics Accelerator  Trends & Directions by Namik Hrle
IBM DB2 Analytics Accelerator Trends & Directions by Namik Hrle
 
The Five R's: There Can be no DB2 Performance Improvement Without Them!
The Five R's: There Can be no DB2 Performance Improvement Without Them!The Five R's: There Can be no DB2 Performance Improvement Without Them!
The Five R's: There Can be no DB2 Performance Improvement Without Them!
 
DBA101
DBA101DBA101
DBA101
 
Data Sharing using Spectrum Scale Active File Management
Data Sharing using Spectrum Scale Active File ManagementData Sharing using Spectrum Scale Active File Management
Data Sharing using Spectrum Scale Active File Management
 
I Know What You Did THIS Summer
I Know What You Did THIS SummerI Know What You Did THIS Summer
I Know What You Did THIS Summer
 

En vedette (6)

Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizer
 
CICS TS V5 Technical Overview
CICS TS V5 Technical OverviewCICS TS V5 Technical Overview
CICS TS V5 Technical Overview
 
Parallel Sysplex Implement2
Parallel Sysplex Implement2Parallel Sysplex Implement2
Parallel Sysplex Implement2
 
DB2 9.7 Overview
DB2 9.7 OverviewDB2 9.7 Overview
DB2 9.7 Overview
 
Db2 performance tuning for dummies
Db2 performance tuning for dummiesDb2 performance tuning for dummies
Db2 performance tuning for dummies
 
ALL ABOUT DB2 DSNZPARM
ALL ABOUT DB2 DSNZPARMALL ABOUT DB2 DSNZPARM
ALL ABOUT DB2 DSNZPARM
 

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

Relative Capacity por Eduardo Oliveira e Joseph Temple
Relative Capacity por Eduardo Oliveira e Joseph TempleRelative Capacity por Eduardo Oliveira e Joseph Temple
Relative Capacity por Eduardo Oliveira e Joseph Temple
Joao Galdino Mello de Souza
 

Similaire à An Intro to Tuning Your SQL on DB2 for z/OS (20)

Smart analytic optimizer how it works
Smart analytic optimizer   how it worksSmart analytic optimizer   how it works
Smart analytic optimizer how it works
 
IBM z/OS V2R2 Performance and Availability Topics
IBM z/OS V2R2 Performance and Availability TopicsIBM z/OS V2R2 Performance and Availability Topics
IBM z/OS V2R2 Performance and Availability Topics
 
z/OS Small Enhancements - Episode 2013A
z/OS Small Enhancements - Episode 2013Az/OS Small Enhancements - Episode 2013A
z/OS Small Enhancements - Episode 2013A
 
Workload Management Update for z/OS 1.10 and 1.11
Workload Management Update for z/OS 1.10 and 1.11Workload Management Update for z/OS 1.10 and 1.11
Workload Management Update for z/OS 1.10 and 1.11
 
NLJUG: Content Management, Standards, Opensource & JCP
NLJUG: Content Management, Standards, Opensource & JCPNLJUG: Content Management, Standards, Opensource & JCP
NLJUG: Content Management, Standards, Opensource & JCP
 
z/OS Small Enhancements - Episode 2014A
z/OS Small Enhancements - Episode 2014Az/OS Small Enhancements - Episode 2014A
z/OS Small Enhancements - Episode 2014A
 
z/OS V2R2 Enhancements
z/OS V2R2 Enhancementsz/OS V2R2 Enhancements
z/OS V2R2 Enhancements
 
z/OS Small Enhancements - Episode 2014B
z/OS Small Enhancements - Episode 2014Bz/OS Small Enhancements - Episode 2014B
z/OS Small Enhancements - Episode 2014B
 
IBM Wave for z/VM
IBM Wave for z/VMIBM Wave for z/VM
IBM Wave for z/VM
 
Maximize o valor do z/OS
Maximize o valor do z/OSMaximize o valor do z/OS
Maximize o valor do z/OS
 
Stephan Hummel – IT-Tage 2015 – DB2 In-Memory - Eine Technologie nicht nur fü...
Stephan Hummel – IT-Tage 2015 – DB2 In-Memory - Eine Technologie nicht nur fü...Stephan Hummel – IT-Tage 2015 – DB2 In-Memory - Eine Technologie nicht nur fü...
Stephan Hummel – IT-Tage 2015 – DB2 In-Memory - Eine Technologie nicht nur fü...
 
Como configurar seu zSystem para workloads rebeldes
Como configurar seu zSystem para workloads rebeldesComo configurar seu zSystem para workloads rebeldes
Como configurar seu zSystem para workloads rebeldes
 
Relative Capacity por Eduardo Oliveira e Joseph Temple
Relative Capacity por Eduardo Oliveira e Joseph TempleRelative Capacity por Eduardo Oliveira e Joseph Temple
Relative Capacity por Eduardo Oliveira e Joseph Temple
 
IOD 2012_ADP_092912
IOD 2012_ADP_092912 IOD 2012_ADP_092912
IOD 2012_ADP_092912
 
z/VSE Connectors Introduction, Use Cases, and News
z/VSE Connectors Introduction, Use Cases, and Newsz/VSE Connectors Introduction, Use Cases, and News
z/VSE Connectors Introduction, Use Cases, and News
 
z/OS Small Enhancements - Edition 2020A
z/OS Small Enhancements - Edition 2020Az/OS Small Enhancements - Edition 2020A
z/OS Small Enhancements - Edition 2020A
 
z/VSE Base Installation - Step by Step
z/VSE Base Installation - Step by Stepz/VSE Base Installation - Step by Step
z/VSE Base Installation - Step by Step
 
z/OS Small Enhancements - Episode 2015A
z/OS Small Enhancements - Episode 2015Az/OS Small Enhancements - Episode 2015A
z/OS Small Enhancements - Episode 2015A
 
IBM zAware
IBM zAwareIBM zAware
IBM zAware
 
z/VM Live Guest Relocation Planning and Use
z/VM Live Guest Relocation Planning and Usez/VM Live Guest Relocation Planning and Use
z/VM Live Guest Relocation Planning and Use
 

Plus de Willie Favero

Why computers are cool high school audience - 2010-12-01
Why computers are cool   high school audience - 2010-12-01Why computers are cool   high school audience - 2010-12-01
Why computers are cool high school audience - 2010-12-01
Willie Favero
 
Redbooks with live links 2010 12-06
Redbooks with live links 2010 12-06Redbooks with live links 2010 12-06
Redbooks with live links 2010 12-06
Willie Favero
 

Plus de Willie Favero (10)

Social Networking 2 - Final
Social Networking 2 - FinalSocial Networking 2 - Final
Social Networking 2 - Final
 
Social Networking 1 - Final
Social Networking 1 - FinalSocial Networking 1 - Final
Social Networking 1 - Final
 
Social Networking 3 - Final
Social Networking 3 - Final Social Networking 3 - Final
Social Networking 3 - Final
 
Speaking at a conference
Speaking at a conferenceSpeaking at a conference
Speaking at a conference
 
Data Warehousing: What's Available on System z Today
Data Warehousing: What's Available on System z TodayData Warehousing: What's Available on System z Today
Data Warehousing: What's Available on System z Today
 
DB2 for z/OS Version 8 Upgrade Planning Paper
DB2 for z/OS Version 8 Upgrade Planning PaperDB2 for z/OS Version 8 Upgrade Planning Paper
DB2 for z/OS Version 8 Upgrade Planning Paper
 
Why computers are cool high school audience - 2010-12-01
Why computers are cool   high school audience - 2010-12-01Why computers are cool   high school audience - 2010-12-01
Why computers are cool high school audience - 2010-12-01
 
Compression for DB2 for z/OS
Compression for DB2 for z/OS Compression for DB2 for z/OS
Compression for DB2 for z/OS
 
Redbooks with live links 2010 12-06
Redbooks with live links 2010 12-06Redbooks with live links 2010 12-06
Redbooks with live links 2010 12-06
 
Paralellism with DB2 for z/OS (2010)
Paralellism with DB2 for z/OS (2010)Paralellism with DB2 for z/OS (2010)
Paralellism with DB2 for z/OS (2010)
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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

  • 1. An Introduction to SQL Tuning for a DB2 for z/OS Environment Willie Favero Data Warehouse on System z Swat Team (DB2 SME) Session #8762 Tuesday, March 1, 2011: 3:00 PM - 4:00 PM Copyright © 2011 IBM Corporation © 2010 IBM Corporation All rights reserved
  • 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 user's 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 IBM's application programming interfaces. Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 2 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 3 of 59 All rights reserved
  • 4. Acknowledgements Terry Purcell - DB2 for z/OS Query Optimization – “Why did the DB2 for z/OS optimizer choose that access path?” • IDUG 2010 – “What's new from the optimizer in DB2 10 for z/OS?” • IDUG 2010 – “What's 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 Corporation Tuning DB2 for z/OS Access Slide 4 of 59 All rights reserved
  • 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 s On 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 Va Memories 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 6 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 8 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 10. The Process Monitor Do Tune Forever Repeat The “Tools” available just keep on getting better Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 10 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 12 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 15. Where Could One Spend Their Time Tuning? SQL Processor Disk Operating System Database Design Network Local Work Database System BTW, this is my opinion… Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 15 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 17 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 18 of 59 All rights reserved
  • 19. Pause for Questions Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 19 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 20 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 21 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 22 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 23 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 24 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 25 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 26 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 27 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 28 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 29 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 30 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 31 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 32 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 33 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 34 of 59 All rights reserved
  • 35. Pause simply for effect Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 35 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 36 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 37 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 38 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 39 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 40 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 41 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 42 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 43 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 44 of 59 All rights reserved
  • 45. Statement Removal Least Recently Used (LRU) algorithm used to remove statements from cache NOT FIFO Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 45 of 59 All rights reserved
  • 46. Pause This time, a new thought and to catch my breath Copyright © 2011 IBM Corporation Tuning DB2 for z/OS Access Slide 46 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 47 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 48 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 49 of 59 All rights reserved
  • 50. IBM Smart Analytics Optimizer Capitalizing on the best of relational and the best of columnar databases What 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 Corporation Tuning DB2 for z/OS Access Slide 50 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 51 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 52 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 53 of 59 All rights reserved
  • 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 Corporation Tuning DB2 for z/OS Access Slide 54 of 59 All rights reserved