Static SQL and Access Path Review Tips and Tricks Paul Walters Sallie Mae Inc. Session Code: E05 May 12, 2010 08:30 a.m. –

Slides:



Advertisements
Similar presentations
Practical SQL performance tuning, for developers and DBAs Kurt Struyf Competence Partners.
Advertisements

Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
SQL Server performance tuning basics
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
#IDUG Explain Yourself and Improve DB2 Performance Jim Dee BMC Software September 16, :05-10:05 | Platform: DB2 for z/OS.
BMC Solutions for DB2 10 for z/OS Peter Plevka, BMC Software.
Clarity Educational Community Clarity Educational Community Creating and Tuning SQL Queries that Engage Users.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Introduction to Structured Query Language (SQL)
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Common Tuning Opportunities
Access Path Selection in a Relation Database Management System (summarized in section 2)
Oracle 11g Real Application Testing: Avoiding Performance Regressions with SQL Performance Analyzer Khaled Yagoub, Pete Belknap, Benoit Dageville, Karl.
SQL/Monitoring Facility An execution-time monitor for DB2/VM and DB2/VSE © 2008 – 2014 Software Product Research.
DB2 and SQL. Terminology –DB2 : Relational database manager fully integrated into the iSeries O/S. Major difference between iSeries DB2 and DB2 Mainframe.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
Performance Enhancements for DB2 UDB for z/OS Version 8 © Lightyear Consulting, Ltd Performance Enhancements for DB2 UDB for z/OS Version 8 Part.
® IBM Software Group © 2012 IBM Corporation OPTIM Data Studio – Jon Sayles, IBM/Rational November, 2012.
© 2009 IBM Corporation The future runs on System z 2010 DB2 9 Optimizer Jeff Freschl, IBM Silicon Valley Lab.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Chapter 16 Methodology – Physical Database Design for Relational Databases.
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
1 Optimizing Your ColdFusion Applications for Oracle Justin Fidler, CNA, CPS, CCFD Chief Technology Officer Bantu, Inc. 8 May 2001.
Oracle PL/SQL Practices. Critical elements of PL/SQL Best Practices Build your development toolbox Unit test PL/SQL programs Optimize SQL in PL/SQL programs.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 9: Database Administration Jerry Post Copyright © 2003.
Introduction to the new mainframe © Copyright IBM Corp., All rights reserved. Chapter 12 Understanding database managers on z/OS.
10/10/2012ISC239 Isabelle Bichindaritz1 Physical Database Design.
DB2 10 Hash Access: Access Path or Collision Course? Donna Di Carlo BMC Software Session Code: A13 Wednesday, 16 November 2011 | Platform: DB2 for z/OS.
SQL Performance and Optimization l SQL Overview l Performance Tuning Process l SQL-Tuning –EXPLAIN PLANs –Tuning Tools –Optimizing Table Scans –Optimizing.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Methodology – Physical Database Design for Relational Databases.
Module 4 Database SQL Tuning Section 3 Application Performance.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
© IBM Corporation 2005 Informix User Forum 2005 John F. Miller III Explaining SQLEXPLAIN ®
Chapter 12 Subqueries and Merge Statements
© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective.
(SQL - Structured Query Language)
B. Information Technology (Hons.) CMPB245: Database Design Physical Design.
Trouble Shooting and Maintenance Pertemuan 13 Matakuliah: T0413 Tahun: 2009.
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
Database Performance Eric Grancher - Nilo Segura Oracle Support Team IT/DES.
Sorting and Joining.
Query Processing – Implementing Set Operations and Joins Chap. 19.
1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
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.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Improve query performance with the new SQL Server 2016 query store!! Michelle Gutzait Principal Consultant at
CSC314 DAY 9 Intermediate SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall USING AND DEFINING VIEWS  Views provide users controlled.
Session Name Pelin ATICI SQL Premier Field Engineer.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
Tuning Transact-SQL Queries
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Teradata Join Processing
From 4 Minutes to 8 Seconds in an Hour (or a bit less)
David M. Kroenke and David J
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
Chapter 8 Advanced SQL.
Presentation transcript:

Static SQL and Access Path Review Tips and Tricks Paul Walters Sallie Mae Inc. Session Code: E05 May 12, :30 a.m. – 9:30a.m. Platform: DB2 zOS

Agenda Managing Change Data to Review  Plan Tables  Objects  Statistics  SQL Statements  Key Indicators Statistics and System Changes Application Changes Best Practices Plan Stability DB2 V9

Brief History How did we get here? Managing Change – Types of Changes & Preserving Performance DB2 Changes ZPARM Changes Statistics Changes DDL Changes Application Changes Plan Tables to the Rescue E

Basic Explain O DSNWFQB## DSNBFQB## DSNVT##/V9 QUERYNO

Explain Information by Object

A

SELECT * FROM SYSIBM.SYSDUMMY1 WHERE 1 = 2 Explain information by Access

A Complete Picture Program Execution Function Catalog Statistic PT

Plan Tables (Most familiar) PLAN_TABLE  Contains most of the access path selection information that was gathered when the package was bound with EXPLAIN(YES). DSN_STATEMNT_TABLE  Contains COST_CATEGORY, REASON AND costing information PROCSU, PROCMS. The costing numbers are ESTIMATED and can very widely with changes to DB2. DB2 V9 adds a TOTAL_COST DB2 V9 adds PARENT_PLANNO

Plan Tables (Continued) DSN_FILTER_TABLE  Contains information on what stage the predicate is processed (MATCHING, SCREENING, STAGE1 and STAGE2). DSN_PREDICAT_TABLE  Contains FILTERFACTOR, BOOLEAN_TERM indicator and the actual predicate text. DSN_DETCOST_TABLE  Contains detailed cost information (COMPCOST) at each step of the access path (mini plan), an estimate on the number of rows that will be returned after the local predicates are applied (ONECOMPROW) and an estimate of rows returned from DM and RDS (DMROWS,RDSROW). Q

DSN_FILTER_TABLE/DSN_PREDICAT_TABLE

DSN_PREDICAT_TABLE DSN_PREDICAT_TABLE and SYSCOLUMNS and SYSKEYS provide information helpful for index review

DSN_DETCOST_TABLE

OT

Plan Tables (Continued) DSN_VIRTUAL_INDEXES  This table allows for the creation or deletion of indexes virtually. This enables a query to be explained with the virtual change. 10 other EXPLAIN Tables  The additional tables support Explain statements from the dynamic statement cache, sort operations or other Explain details.

SQL Statements and Source Code

Objects Object Structure and Buffer Pool Assignments Statistics DB2 Statistics and Real Time Statistics Package Execution/Function

Managing Change: Statistics and System Changes DB2 V9 Enhancements that require rebinds:  Puffing of the runtime structures – especially with RELEASE(COMMIT)  Required to reestablish SPROCs (with no rebind a 0-10% performance penalty )  Virtual Storage Constraint Relief  Global Query Optimization  Sort Avoidance with Distinct and Group By You bought it might as well drive it

Managing Change: Statistics and System Changes Impacts on Access Path Selection Identification  Model a Control set of structures Off Production  Copy Production DBRMS  Bind Before and After Maintenance  Review Changes PROCMS PROCSU Release Guide Hold Data

Managing Change: Statistics and System Changes I001 No Change W001 C<P Steps W002 C>P Steps W005 Change W003 C<P Stmts W004 C>P Stmts W006 New Package

Managing Change: Statistics and System Changes Managing Rebinds During Upgrades  Wait until the upgrade is stabilized  Rebind the safe and improved packages with PLANMGMT  Execute RUNSTATS – focus on heavily used objects, watch for changes in CLUSTERRATIOF, use “_HIST” tables  Check Access Path Changes with new statistics  Rebind Previously Untouched Packages  Rebind packages bound before new statistics were collected PERFORMANCEPERFORMANCE

Managing Change: Application changes New/Changed Packages  New programs Require top down review  Changed Programs – look for new objects and/or access path changes New/Changed Objects I001 No Change W001 C<P Steps W002 C>P Steps W003 C<P Stmts W004 C>P Stmts W005 Change W006 New Package

Plan Stability DB2 V9 Provides a backup of a access path that can be used for fallback Enabled Globally with ZPARM PLNMGNT or at bind time with PLNMGNT option.  Information Stored in SPT01 and SYSPACKDEP  Rebind Switch  Each Copy is Separately Invalidated  Only Current information is stored in SYSPACKAGE  Dependant versions recorded in SYSPACKDEP(DTYPE P,O)  Can only replace the entire package  How Stale is the Original Copy DB2 Hints are still Relevant

Other DB2 V9 Changes Virtual Indexes – available via APAR in V8 (PK46687) Unicode Plan Tables (PK85068) New Explain Sub-Query Parent Query Block Visual Explain is Deprecated in DB2 V9 Optimization Service Center (OSC) Deprecated in the next Release of DB2 IBM Data Studio is the replacement for OSC

Best Practices Explain(YES) Regular Review Know Your Applications

WITH STMT1(COLLID,PROGNAME,BIND_TIME) AS (SELECT COLLID,NAME,MAX(BINDTIME) FROM SYSIBM.SYSPACKAGE WHERE LOCATION = ' ' AND BINDTIME > CURRENT TIMESTAMP - 84 HOURS AND TYPE <> 'T' AND EXPLAIN = 'Y' AND (COLLID LIKE 'PLSF%') GROUP BY COLLID,NAME ),STMT2(COLLID,PROGNAME,BIND_TIME) AS (SELECT S1.COLLID,S1.PROGNAME, COALESCE(MAX(PT.BIND_TIME),' ') FROM PDBA0.PLAN_TABLE AS PT, STMT1 AS S1 WHERE PT.COLLID = S1.COLLID AND PT.PROGNAME = S1.PROGNAME AND PT.BIND_TIME < S1.BIND_TIME AND PT.OPTHINT = ' ' GROUP BY S1.COLLID,S1.PROGNAME) Identify Packages BINDTIME with Explain Yes and The previous BIND_TIME from the Plan_Table

,STMT_REV(COLLID,PROGNAME,BIND_TIME,CSCNT,CPCNT, PSCNT,PPCNT,WARNING) AS (SELECT COLLID,PROGNAME,BIND_TIME,SUM(CSCNT) AS CSCNT,SUM(CPCNT) AS CPCNT,SUM(PSCNT) AS PSCNT,SUM(PPCNT) AS PPCNT,CASE WHEN SUM(PSCNT) = 0 THEN 'W006' WHEN SUM(CSCNT) > SUM(PSCNT) THEN 'W004' WHEN SUM(CSCNT) < SUM(PSCNT) THEN 'W003' WHEN SUM(CPCNT) > SUM(PPCNT) THEN 'W002' WHEN SUM(CPCNT) < SUM(PPCNT) THEN 'W001' ELSE NULL END AS WARNING FROM First Cut W001 C<P Steps W002 C>P Steps W003 C<P Stmts W004 C>P Stmts W006 New Package

(SELECT S1.COLLID,S1.PROGNAME,S1.BIND_TIME,COUNT(DISTINCT QUERYNO) AS CSCNT,COUNT(*) AS CPCNT,0 AS PSCNT,0 AS PPCNT FROM STMT1 AS S1, PDBA0.PLAN_TABLE AS PT WHERE PT.PROGNAME = S1.PROGNAME AND PT.COLLID = S1.COLLID AND PT.BIND_TIME = S1.BIND_TIME AND PT.OPTHINT = ' ' GROUP BY S1.COLLID,S1.PROGNAME,S1.BIND_TIME UNION ALL SELECT S1.COLLID,S1.PROGNAME,S1.BIND_TIME,0 AS CSCNT,0 AS CPCNT,COUNT(DISTINCT QUERYNO) AS PSCNT,COUNT(*) AS PPCNT FROM STMT1 AS S1, STMT2 AS S2, PDBA0.PLAN_TABLE AS PT WHERE PT.PROGNAME = S2.PROGNAME AND PT.COLLID = S2.COLLID AND S1.PROGNAME = S2.PROGNAME AND S1.COLLID = S2.COLLID AND PT.BIND_TIME = S2.BIND_TIME AND PT.OPTHINT = ' ' GROUP BY S1.COLLID,S1.PROGNAME,S1.BIND_TIME ) AS DATA GROUP BY COLLID,PROGNAME,BIND_TIME) Total Steps and Statements from the Current and Previous Explain output

,CDATA(COLLID,PROGNAME,BIND_TIME, SEQ,QUERYNO,QBLOCKNO,PLANNO,MIXOPSEQ,DATA) AS (SELECT S1.COLLID,S1.PROGNAME,S1.BIND_TIME, CSEQ.SEQ,QUERYNO,QBLOCKNO,PLANNO,MIXOPSEQ, {COLUMN1 CONCAT COLUMN2….} FROM STMT1 AS S1, PDBA0.PLAN_TABLE AS PT, TABLE (SELECT COUNT(*)+1 AS SEQ FROM PDBA0.PLAN_TABLE AS PT1 WHERE PT.PROGNAME = PT1.PROGNAME AND PT.COLLID = PT1.COLLID AND PT.BIND_TIME = PT1.BIND_TIME AND PT.OPTHINT = PT1.OPTHINT AND DIGITS(PT.QUERYNO) CONCAT DIGITS(PT.QBLOCKNO) CONCAT DIGITS(PT.PLANNO) CONCAT DIGITS(PT.MIXOPSEQ) > DIGITS(PT1.QUERYNO) CONCAT DIGITS(PT1.QBLOCKNO) CONCAT DIGITS(PT1.PLANNO) CONCAT DIGITS(PT1.MIXOPSEQ) ) AS CSEQ WHERE PT.PROGNAME = S1.PROGNAME AND PT.COLLID = S1.COLLID AND PT.BIND_TIME = S1.BIND_TIME AND PT.OPTHINT = ' ') Select the Current Explain Data with a New Sequence Number

,PDATA(COLLID,PROGNAME, SEQ,QUERYNO,QBLOCKNO,PLANNO,MIXOPSEQ, DATA) AS (SELECT S2.COLLID,S2.PROGNAME, PSEQ.SEQ,QUERYNO,QBLOCKNO,PLANNO,MIXOPSEQ, {COLUMN1 CONCAT COLUMN2….} FROM STMT2 AS S2, PDBA0.PLAN_TABLE AS PT, TABLE (SELECT COUNT(*)+1 AS SEQ FROM PDBA0.PLAN_TABLE AS PT1 WHERE PT.PROGNAME = PT1.PROGNAME AND PT.COLLID = PT1.COLLID AND PT.BIND_TIME = PT1.BIND_TIME AND PT.OPTHINT = PT1.OPTHINT AND DIGITS(PT.QUERYNO) CONCAT DIGITS(PT.QBLOCKNO) CONCAT DIGITS(PT.PLANNO) CONCAT DIGITS(PT.MIXOPSEQ) > DIGITS(PT1.QUERYNO) CONCAT DIGITS(PT1.QBLOCKNO) CONCAT DIGITS(PT1.PLANNO) CONCAT DIGITS(PT1.MIXOPSEQ) ) AS PSEQ WHERE PT.PROGNAME = S2.PROGNAME AND PT.COLLID = S2.COLLID AND PT.BIND_TIME = S2.BIND_TIME AND PT.OPTHINT = ' ') Select the Previous Explain Data with a New Sequence Number

SELECT CHAR(C.COLLID,10) AS COLLID,CHAR(C.PROGNAME,10) AS PROGNAME C.BIND_TIME, CASE WHEN SR.WARNING IS NULL AND C.DATA <> P.DATA THEN C.SEQ ELSE 0 END AS SEQ, CASE WHEN SR.WARNING IS NULL AND C.DATA <> P.DATA THEN 'W005' ELSE SR.WARNING END AS WARNING,SR.CSCNT,SR.CPCNT, SR.PSCNT,SR.PPCNT, CASE WHEN SR.WARNING IS NULL AND C.DATA <> P.DATA THEN C.QUERYNO ELSE 0 END AS QUERYNO, CASE WHEN SR.WARNING IS NULL AND C.DATA <> P.DATA THEN C.QBLOCKNO ELSE 0 END AS QBLOCKNO, CASE WHEN SR.WARNING IS NULL AND C.DATA <> P.DATA THEN C.PLANNO ELSE 0 END AS PLANNO, CASE WHEN SR.WARNING IS NULL AND C.DATA <> P.DATA THEN C.MIXOPSEQ ELSE 0 END AS MIXOPSEQ FROM CDATA AS C LEFT OUTER JOIN PDATA AS P ON P.COLLID = C.COLLID AND P.PROGNAME = C.PROGNAME AND P.SEQ = C.SEQ INNER JOIN STMT_REV AS SR ON SR.COLLID = C.COLLID AND SR.PROGNAME = C.PROGNAME AND SR.BIND_TIME = C.BIND_TIME WHERE (C.DATA <> P.DATA OR WARNING IS NOT NULL)

UNION SELECT CHAR(C.COLLID,10) AS COLLID,CHAR(C.PROGNAME,10) AS PROGNAME, C.BIND_TIME,0 AS SEQ, 'I001' AS WARNING,SR.CSCNT,SR.PSCNT, SR.CPCNT,SR.PPCNT, 0 AS QUERYNO, 0 AS QBLOCKNO, 0 AS PLANNO, 0 AS MIXOPSEQ FROM CDATA AS C INNER JOIN STMT_REV AS SR ON SR.COLLID = C.COLLID AND SR.PROGNAME = C.PROGNAME AND SR.BIND_TIME = C.BIND_TIME WHERE WARNING IS NULL AND NOT EXISTS (SELECT 1 FROM PDATA AS P WHERE P.COLLID = C.COLLID AND P.PROGNAME = C.PROGNAME AND P.SEQ = C.SEQ AND P.DATA <> C.DATA) ORDER BY 3 DESC FOR FETCH ONLY WITH UR UNION the Remainder/Un changed Packages

Reference Material Redbooks  Data Integrity with DB2 for z/OS  DB2 9 for z/OS Performance Topics Manuals  DB2 V9 Performance Monitoring and Tuning Guide Web  DB2 for z/OS Exchange at IBM.COM 

Session: E05 Static SQL and Access Path Review Tips and Tricks Paul Walters Sallie Mae Inc.