#IDUG Explain Yourself and Improve DB2 Performance Jim Dee BMC Software September 16, 2014 9:05-10:05 | Platform: DB2 for z/OS.

Slides:



Advertisements
Similar presentations
Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Advertisements

Microsoft Dynamics® AX 2012
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Introduction to SQL Tuning Brown Bag Three essential concepts.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
BY LECTURER/ AISHA DAWOOD DW Lab # 4 Overview of Extraction, Transformation, and Loading.
Database Languages Chapter 7. The Relational Algebra.
© IBM Corporation Informix Chat with the Labs John F. Miller III Unlocking the Mysteries Behind Update Statistics STSM.
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
IBM Software Group ® Recommending Materialized Views and Indexes with the IBM DB2 Design Advisor (Automating Physical Database Design) Jarek Gryz.
BMC Solutions for DB2 10 for z/OS Peter Plevka, BMC Software.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
Toward Online Schema Evolution for Non-Stop Systems Amol Deshpande, University of Maryland Michael Hicks, University of Maryland.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
DB Audit Expert v1.1 for Oracle Copyright © SoftTree Technologies, Inc. This presentation is for DB Audit Expert for Oracle version 1.1 which.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
Gain Performance & Scalability With RightNow Analytics
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
® IBM Software Group © 2013 IBM CorporationLast Update: August 2013 Workshops RDz Workbench – Using the Data Source Explorer Workshops.
© 2010 IBM Corporation Information Management Performance Enhancements for DB2 V10.1 Anthony Reina - Accelerated Value Specialist
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
Database Design for DNN Developers Sebastian Leupold.
® IBM Software Group © 2012 IBM Corporation OPTIM Data Studio – Jon Sayles, IBM/Rational November, 2012.
Static SQL and Access Path Review Tips and Tricks Paul Walters Sallie Mae Inc. Session Code: E05 May 12, :30 a.m. –
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
DB2 for z/OS Query Optimization  IBM Corporation  IBM Corporation 2003 Tampa Bay Relational Users Group IBM Silicon Valley Lab, U.S.A.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
1 Chapter 7 Optimizing the Optimizer. 2 The Oracle Optimizer is… About query optimization Is a sophisticated set of algorithms Choosing the fastest approach.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Oracle Data Integrator Transformations: Adding More Complexity
Introduction to the new mainframe © Copyright IBM Corp., All rights reserved. Chapter 12 Understanding database managers on z/OS.
© Copyright 2014 BMC Software, Inc.1 — Chief Architect for DB2, BMC IBM Information Champion 2015 May / 2015 Jim Dee Stop Wasting Time With Utilities!
Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
© Copyright 2014 BMC Software, Inc.1 — Chief Architect for DB2, BMC IBM Information Champion 2015 May / 2015 Jim Dee Explain Yourself and Improve DB2 Performance!
Topics Related to Attribute Values Objectives of the Lecture : To consider sorting relations by attribute values. To consider Triggers and their use for.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Query Optimizer (Chapter ). Optimization Minimizes uses of resources by choosing best set of alternative query access plans considers I/O cost,
© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database /
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Confidencial - TRACASA Automatize test [e- Reporting]
Cognos 8 BI Configuration, Administration, and Upgrade Cognos 8 BI.
Virtual techdays INDIA │ august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Copyright © 2016, SAS Institute Inc. All rights reserved. HIDDEN GEMS IN SAS ENTERPRISE GUIDE.
Common SQL Performance Issues AND HOW TO AVOID OR FIX THEM.
 CONACT UC:  Magnific training   
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
CHAPTER 9 File Storage Shared Preferences SQLite.
Agenda What is a DB2 Hint? Why may a DB2 Hint be needed? How do you know the Hint was used? Doing a Static Hint with the tried and true method What are.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
SAP Tuning 실무 SK㈜ ERP TFT.
Session Name Pelin ATICI SQL Premier Field Engineer.
SQL Server Statistics and its relationship with Query Optimizer
Rev Up Your SQL Application with Enhanced Statistics!
Cardinality Estimator 2014/2016
Recommending Materialized Views and Indexes with the IBM DB2 Design Advisor (Automating Physical Database Design) Jarek Gryz.
Sql Saturday Philadelphia
Presentation transcript:

#IDUG Explain Yourself and Improve DB2 Performance Jim Dee BMC Software September 16, :05-10:05 | Platform: DB2 for z/OS

#IDUG Key Points Understand new EXPLAIN capabilities, added in DB2 10 and 11, and how to exploit them. Explore the ability to save access path history, and how to use it to analyze trends and to detect unwanted access path changes. Understand the mechanism of SYSSTATEFEEDBACK and how it can be used to guide RUNSTATS executions. Discuss selectivity profiles and how to use them to improve the operation of the DB2 optimizer. 2

#IDUG SQL Tuning – like Whac-a-Mole? There’s always a new problem As soon as you think you have them all fixed, a new one pops up 3

#IDUG EXPLAIN Tables 4

#IDUG New EXPLAIN Features Access path stability SYSPACKCOPY added in DB2 10 APCOMPARE and APREUSE added in DB2 10 APREUSE(WARN) added in DB2 11 – allows statement level control New columns were added to the DSN_VIRTUAL_INDEXES table, and a new DSN_VIRTUAL_KEYTARGETS table was added Support for Index on Expression, XML indexes, Index Include Column, and null suppressed indexes EXPLAIN (ONLY) EXPLAIN PACKAGE 5

#IDUG EXPLAIN History 6 BINDPLAN_TABLE SYSPACKAGE SYSPACKCOPY LOCATION COLLID NAME VERSION LOCATION COLLID NAME VERSION COPYID PLAN_TABLE_ HISTORY Trigger or SQL SQL Reporting

#IDUG What Can I Get Out of My EXPLAIN Table? 7 SELECT SUBSTR(PL.COLLID,1,10) AS COLLID, SUBSTR(PL.PROGNAME,1,10) AS PROGNAME, DATE(PL.EXPLAIN_TIME) AS DATE, TIME(PL.EXPLAIN_TIME) AS TIME, COUNT(PL.QUERYNO) AS "STMT COUNT", DEC(SUM(ST.TOTAL_COST),8,2) AS "TOTAL COST" FROM SJD.PLAN_TABLE PL, SJD.DSN_STATEMNT_TABLE ST WHERE PL.PROGNAME = ST.PROGNAME AND PL.COLLID = ST.COLLID AND PL.EXPLAIN_TIME = ST.EXPLAIN_TIME AND PL.QUERYNO = ST.QUERYNO GROUP BY PL.COLLID, PL.PROGNAME, PL.EXPLAIN_TIME ORDER BY PL.PROGNAME;

#IDUG Sample Results for a Very Simple Example COLLID PROGNAME DATE TIME STMT COUNT TOTAL COST MYCOLL MYPACK 05/08/ MYCOLL MYPACK 05/08/ DSNE610I NUMBER OF ROWS DISPLAYED IS 2

#IDUG Can I Detect Changed Costs? 9 SELECT ST1.QUERYNO AS QUERYNO, COALESCE(DEC(ST1.TOTAL_COST,8,2),0) AS "OLD COST", COALESCE(DEC(ST2.TOTAL_COST,8,2),0) AS "NEW COST" FROM SJD.DSN_STATEMNT_TABLE ST1 FULL JOIN SJD.DSN_STATEMNT_TABLE ST2 ON ST1.QUERYNO = ST2.QUERYNO WHERE ST1.COLLID = 'MYCOLL' AND ST2.COLLID = 'MYCOLL' AND ST1.PROGNAME = 'MYPACK' AND ST2.PROGNAME = 'MYPACK' AND DATE(ST1.EXPLAIN_TIME) = ' ' AND TIME(ST1.EXPLAIN_TIME) = ' ' AND DATE(ST2.EXPLAIN_TIME) = ' ' AND TIME(ST2.EXPLAIN_TIME) = ' ' AND ST1.TOTAL_COST <> ST2.TOTAL_COST ORDER BY QUERYNO;

#IDUG Can I Detect Changed Costs? QUERYNO OLD COST NEW COST DSNE610I NUMBER OF ROWS DISPLAYED IS 2

#IDUG Optimizer Help for RUNSTATS 11 BIND DSN_STAT_ FEEDBACK Analysis EXECUTION Available in CM SYSIBM. SYSSTATFEEDBACK Available in NFM RUNSTATS Note: Use profiles!

#IDUG The Stats Feedback Tables DSN_STATS_FEEDBACK QUERYNO APPLNAME PROGNAME COLLID GROUP_MEMBER EXPLAIN_TIME SECTNOI VERSION Most of SYSSTATFEEDBACK Columns SYSSTATFEEDBACK TBCREATOR TBNAME IXCREATOR IXNAME COLNAME NUMCOLUMNS COLGROUPCOLNO TYPE DBNAME TSNAME REASON BLOCK_RUNSTATS REMARKS LASTDATE 12

#IDUG The Stats Feedback Columns Of Interest COLNAME Name of the single column associated with the recommendation NUMCOLUMNS Number of columns if the recommendation is for more than one column COLGROUPCOLNO Binary field: array of halfwords which are COLNO references TYPE CHAR(1), representing the type of statistic to collect ‘C’ (cardinality), ‘F’ (frequency), ‘H’ (histogram), ‘I’ (index), ‘T’ (table) REASON CHAR(8), representing the reason for the recommendation ‘BASIC’, ‘KEYCARD’, ‘LOWCARD’, ‘NULLABLE, ‘DEFAULT, ‘RANGEPRD’, ‘PARALLEL’, ‘CONFLICT’, ‘COMPFFIX’ 13

#IDUG How To Get Stats Help To see DSN_STAT_FEEDBACK results, you must create the table before running EXPLAIN Available in DB2 11 CM DSNSAMP(DSNTESC) To see SYSSTATFEEDBACK, you must ensure that the STATSFDBK_SCOPE zparm is set to something other than NONE STATSINT zparm – REAL TIME STATS field on DSNTIPO (Operator Functions) – specifies time in minutes between externalizations ACCESS DB MODE(STATS) updates SYSSTATFEEDBACK from memory – externalizes RTS also 14

#IDUG What If You Want to Try This Gradually? You can use the STATSFDBK_SCOPE zparm to restrict stats feedback collection NONE, STATIC, DYNAMIC, or ALL (default) Specified in the STATISTICS FEEDBACK field in install panel DSNTIPO (Operator Functions) You can use the STATS_FEEDBACK column in SYSTABLES to disable statistics feedback for the table Can set it to “N” or “Y” You can set the BLOCK_RUNSTATS column to ‘Y’ Process that generates RUNSTATS must honor this 15

#IDUG Other Considerations For Stats Feedback Stats Feedback doesn’t work in certain cases: VOLATILE DGTT CGTT Use of Hints, APREUSE, APCOMPARE may interfere during EXPLAIN 16

#IDUG Selectivity Profiles 17

#IDUG Is There a Problem? 18

#IDUG What is the SQL Doing? 19 CUSTOMER 5 million rows ORDER 50 million rows …WHERE A.CUSTID = B.CUSTID …WHERE A.CUST_COUNTRY = :H

#IDUG Is There a Problem? 20

#IDUG A Little More Research… 21

#IDUG A Little More Research… 22 SELECT STATSTIME, INT(FIRSTKEYCARDF) AS FIRSTKEYCARD, INT(FULLKEYCARDF) AS FULLEYCARD, DEC(CLUSTERRATIOF, 3, 1) AS CLUSTERRATIO FROM SYSIBM.SYSINDEXES WHERE CREATOR = 'SJDID001' AND NAME = 'CUSTADDR'; STATSTIME FIRSTKEYCARD FULLEYCARD CLUSTERRATIO DSNE610I NUMBER OF ROWS DISPLAYED IS 1 SELECT COUNT(*) FROM SJDID001.CUSTOMER WHERE CUST_COUNTRY = ‘CK'; SELECT COUNT(*) FROM SJDID001.CUSTOMER WHERE CUST_COUNTRY = ‘DE';

#IDUG How Do You Correct This? Two EXPLAIN tables involved DSN_PREDICAT_TABLE and DSN_PREDICATE_SELECTIVITY You should create these with a new schema, to separate them functionally You can update DSN_PREDICATE_SELECTIVITY with the critical filter factor information A row for “CUST_COUNTRY = ‘CK’, with WEIGHT =.5, SELECTIVITY =.80 A row for “CUST_COUNTRY = ‘DE’, with WEIGHT =.1, SELECTIVITY =.19 ASSUMPTION must be set to ‘OVERRIDE’ for these rows The optimizer will assume default filtering for all other predicates 23

#IDUG How Do You Correct This? Now, you must insert a row into the DSN_USERQUERY_TABLE table, as for a hint This is not created with the EXPLAIN tables…DSNSAMP(DSNTESH) Copy QUERY_TEXT from SYSPACKSTMT Set SELECTIVTY_OVERRIDE to ‘Y’ Set ACCESSPATH_HINT to ‘N’ (this is not a hint) Set OPTION_OVERRIDE to ‘N’ (assuming you don’t want to override a BIND option) BIND QUERY LOOKUP(YES) Populates the appropriate catalog tables BIND for your package will now consider the new filter factors 24

#IDUG Bibliography “DB2 11 for z/OS Managing Performance”, SC “DB2 11 for z/OS SQL Reference”, SC “DB2 11 for z/OS Installation and Migration Guide”, GC

#IDUG Jim Dee BMC Software B17 Explain Yourself and Improve DB2 Performance!