35
© 2009 IBM Corporation November 19, 2009 Query tuning for DB2® for z/OS® developers and DBAs Raymond Willoughby Product Manager [email protected] Saghi Amirsoleymani Solutions Architect [email protected] A PDF of these slides can be downloaded from: ibm.com/developerworks/data/events/idmbriefings.html

Query tuning for DB2® for z/OS® developers and DBAs

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

© 2009 IBM CorporationNovember 19, 2009

Query tuning for DB2® for z/OS® developers and DBAsRaymond Willoughby

Product Manager [email protected]

Saghi AmirsoleymaniSolutions Architect [email protected]

A PDF of these slides can be downloaded from:

ibm.com/developerworks/data/events/idmbriefings.html

Information Management

© 2009 IBM Corporation2

Agenda

Introduction and prereqs

Walk through use case scenarios

– Query tuning during application development

– Query tuning from monitoring environment

– Workload analysis for version to version migration

– General workload analysis

Summary, questions, and survey

Information Management

© 2009 IBM Corporation3

Single Query and Workload Offerings

Optim Query Tuner

Tune SQL pre-production while costs and impact are low

Optim Query Workload Tuner

Optimize workload for peak performance

Development Environment Production Environment

Information Management

© 2009 IBM Corporation4

Eclipse shell-integrated

① No charge in OSC and not planned to be part of Data Studio (no-charge) -- these were technology previews

Contents of Query Tuning offeringsFunction Optimization Service

Center 1.1 FP6(FP7 4Q/2009)

SQL PA for z/OS

Data Studio (standalone)

Dec 2009 (planned)

Query Tuner for

LUW

Query Tuner for z/OS

Query Workload Tuner for z/OS

Queries from all sources Yes Yes Yes Yes Yes

Query Formatter Yes Yes Yes Yes Yes Yes

Query Annotation Yes ① Yes Yes Yes

Access Plan Graph Yes EEE Yes Yes Yes Yes

Visual Plan Hint Yes ① Yes Yes

Query Statistics Advisor Yes Yes Yes Yes Yes

Workload Statistics Advisor Yes ① Yes

Profile Based Monitoring Yes Yes

Query Index Advisor Limited Yes Yes Yes

Workload Index Advisor Yes

Query Advisor Yes 100+ Yes Yes Yes

Workload Query Advisor Yes

Access Path Advisor Yes Yes Yes Yes

Query Env Capture Yes z/OS only Yes Yes

Workload Env Capture Yes Yes

Statistics Migration Limited Yes Ltd Ltd

DBRM Library Support Yes

PL/I, Cobol, C Code spt Yes

Query Costing Yes

QMF Governor Intercept Yes

Reports Batch Yes Yes Yes Yes

Information Management

© 2009 IBM Corporation5

Supported servers and prereqs

Data servers– DB2 for z/OS Version 8, 9– DB2 for Linux, UNIX, and Windows Version 9.5, 9.7

Client machine prereqs– Microsoft Windows

http://www.01.ibm.com/support/docview.wss?rs=64&uid=swg27013774

. DB2 for z/OS prereqs -– http://www-01.ibm.com/support/docview.wss?rs=4069&uid=swg27015328

Information Management

© 2009 IBM Corporation6

Development scenario

Information Management

© 2009 IBM Corporation7

Minimize Production Slowdowns for Java applicationsTune in development by combining Optim Development Studio and Query Tuner

Visualize query hot spots– Most frequently executed– Longest running

Get expert advice – View formatted queries with

statistical annotations– Improve query structure– Improve statistics quality and

collection efficiency– Get index recommendations

Validate improvement – Replace SQL– Run application– Compare performance results

Advisor overview

Recommendations

Find hot spots

Get expert advice

Compare results

Information Management

© 2009 IBM Corporation8

Foster cross collaboration

Challenge – Disconnect between application and

data group

Solution- Simplified query report – Overview– Recommended Actions– Input SQL statement– Access Plan Summary

• Transformed/Optimized query• Predicates• Table Access• Join Operation

– Table and Index Catalog Information: table, column and index

Planned for December!

Information Management

© 2009 IBM Corporation9

Demo

Information Management

© 2009 IBM Corporation10

Tuning from a monitoring environment

Information Management

© 2009 IBM Corporation11

Streamline Monitor and Respond ScenariosDB2 profile monitor

Optim Query TunerDB2 Query Monitor

OMEGAMON XE

Information Management

© 2009 IBM Corporation12

Currently executed SQL in Thread Detail View

Press Explain if you want to launchOptim Query Tuner for this query

Information Management

© 2009 IBM Corporation13

Dynamic SQL Statement Cache with Zoom-in Details

Select and zoom-in

Press Explain if you want to launchOptim Query Tuner for this query

Information Management

© 2009 IBM Corporation14

Version to version migration scenario

Information Management

© 2009 IBM Corporation15

Version to Version Migration Saved

Challenge– Performance regression discovered across range of QMF workloads– Client had been using a “trick” to affect optimizer choices that was not available

in the new version– Expected 6-8 months delay plus additional staff costs – Delay in promised value of new database version

Solution – Optim Query Workload Tuner– Handled complexity of queries and workloads

• 30 table joins nested behind several layers of views• Column names changed in views• 100s of queries in multiple workloads

– Saved hours of time formatting, annotating, and analyzing queries – Recommended additional statistics and predicates for better performance – Reduced migration from months to weeks

Order of magnitude reduction in query workload analysis. All workloads as good as or better than prior version.

Information Management

© 2009 IBM Corporation16

Reduce risk of performance regression after migration

Run Access Plan Cost comparison report

Filter Criteria

Obtain Access Plan information

Planned for December!

Information Management

© 2009 IBM Corporation17

View analysis summary based on TOTAL_COST

Identify Problematic Package Tables

SQL statement with the highest

% cost

Prevent problems before they impact the business

Tune a single query or at a

workload level

Identify Problematic SQL statement

Information Management

© 2009 IBM Corporation18

Define Workload or tune single query

Drill into adviceExecute advisors

Information Management

© 2009 IBM Corporation19

Validation against a production system

Accelerate development– Develop, test, and run queries,

procedures, and functions. Enhance developer and DBA productivity– Analyze impact of changes– Enhance problem isolation

Optimize performance proactively– Leverage best practices for new

development– Test before deployment– Adapt ahead of impact – Minimize Production

Slowdowns

Change Database connection

Clone Project

Perform analysis

Information Management

© 2009 IBM Corporation20

Visualize access path – See flow of query processing– See indexes and operations– See optimizer rationale

Assess access path stability to reduce risk of performance regression– Is the optimizer able to apply the filtering early?– Are there indexes that support an efficient path?– Do statistics allow distinction between the choices?

Analyze Access Plans

Information Management

© 2009 IBM Corporation21

General workload analysis

Information Management

© 2009 IBM Corporation22

Define or select workload Execute advisors

Streamlined Analysis

Drill into advice Validate improvement

Information Management

© 2009 IBM Corporation23

Improve Statistics Quality and Collection

Provides advice on – Missing statistics– Conflicting statistics– Out-of-date statistics

Results – Accurate estimated costs – Better query performance– Less CPU consumption – Improved maintenance

window throughput

Generates RUNSTATS control

statements

Indicates conflicting and

missing statistics

Conflicting statistics

explanation

“Half of access path PMRs could be resolved by statistics advisorbefore calling IBM support.”

– IBM Support

Information Management

© 2009 IBM Corporation24

Execute Advisors

Statistics – Get recommendations on the

best statistics to capture to influence access path selection

Query– Get recommendations

regarding how to rewrite the query for better efficiency

Index – Get recommendations on

additional indexes that can reduce database scans

Information Management

© 2009 IBM Corporation25

Improve Query Design

View analysis summaryHighlights relevant components of the

query

Recommendation and rationale

Filter recommendations by severity

Guard against errors and oversights:Further constrain query, increase index utilization, and reduce data reads

Query Advisor checks for– Missing join predicate for referential

constraint– Predicates that can be rewritten as

indexable– Stage 2 predicates that can be

rewritten as stage 1 predicates

Information Management

© 2009 IBM Corporation26

Indexing Advice to Improve Query Efficiency

Improve query efficiency– Indexing foreign keys in queries

that do not have indexes defined– Identifying index filtering and

screening– Support for index only access – Indexing to avoid sorts

Simplify use– Consolidate indexes and provide

a single recommendation – Enables what-if analysis– Provides DDL to create indexes– Run immediately or save

Test before deployment– Utilize virtual index capabilities

built into the DB2 engine

Information Management

© 2009 IBM Corporation27

Demo

Information Management

© 2009 IBM Corporation28

Lifecycle Approach to Query Optimization

Tune query workloads proactively– Grab high cost queries from performance monitors– Optimize database and query design, statistics collection – Improve query responsiveness and database efficiency

Fast response to emergent problems– Reduce reliance on availability of specialized skills– Get fast, targeted advice on problem resolution– Replace poorly performing SQL without changing the

application using Optim pureQuery Runtime

Improve query design from the beginning– Application DBAs and database savvy developers– Single query tuning to improve database and query design– Integration with Optim Development Studio

Refine

Respond

Develop

Value delivery to multiple roles DBAs, Developers, Performance, Quality Assurance, …

Information Management

© 2009 IBM Corporation29

Resources

Integrated Data Management Community– http://www.ibm.com/developerworks/spaces/optim

Query Tuning solutions developerWorks discussion forum– http://www.ibm.com/developerworks/forums/forum.jspa?forumID=1798

IBM Optim Query Workload Tuner web page– https://www-01.ibm.com/software/data/db2imstools/db2tools/opti-

expert-zos/

SQL Tuning, Not just for hardcore DBAs anymore– http://www.ibmdmmagazinedigital.com/dmmagazine/

Redbooks at www.redbooks.ibm.com– DB2 9 for z/OS Performance Topics SG24-7473– IBM DB2 9 for z/OS: New Tools for Query Optimization SG24-7421

Information Management

© 2009 IBM Corporation30

Registration links and slides available soon at: ibm.com/developerworks/data/events/idmbriefings.html

Tell your colleagues about this upcoming Tech Briefing!

Query tuning for z/OS developers and DBAs – November 19, 2009Better performance translates to greater revenue, greater customer satisfaction, and

greater ability to meet SLAs. But it is easier said than done, particularly with contemporary environments like Java. Ever been up late trying to pinpoint a performance problem? Or worse, trying to find where the problem might be buried in all of the data? Tired of the finger pointing among staff when performance is an issue? Find out how you can create exception monitoring metrics, track and measure performance indicators and quickly diagnose performance problems when they aris using DB2 Performance Expert and Extended Insight Feature to make the process easier and more efficient.

Don’t leave yet. Please fill out the survey!

© 2009 IBM CorporationNovember 19, 2009

Questions?

Information Management

© 2009 IBM Corporation32

Information Management

© 2009 IBM Corporation33

Backup

Information Management

© 2009 IBM Corporation34

IBM Optim Query Tuner & Query Workload Tuner for DB2 z/OS Prerequisites for customer environment

DB2 for z/OS, V8 (5625-DB2) PUT Level 0807, or later, plus PTF/APARs UK42083, UK42085, UK42086, UK42088, UK42092, UK38896, PK92329, PK95645, PK96728 and PK96729 DB2 for z/OS, V9 (5635-DB2) PUT Level 0807, or later, plus PTF/APARs UK42084, UK42089, UK42093, PK92329, PK95645, and PK96729 DB2 VUE V8 (5697-N29) PUT Level 0807, or later, plus PTF/APARs UK42083, UK42085, UK42086, UK42088, UK42092, UK38896, PK92329, PK95645, PK96728 and PK96729 DB2 VUE V9 (5697-P12) PUT Level 0807, or later, plus PTF/APARs UK42084, UK42089, UK42093, PK92329, PK95645, and PK96729

Information Management

© 2009 IBM Corporation35

Gather High Cost Queries and Workloads

DB2

Plan table

Statement table

Catalog plan or package

Statement cache

Profile monitor

Optim Development Studio

QMF and QMF HPO

DB2 Query Monitor

OMEGAMON XE for DB2

File, text, or exported workload

User defined category

Define or select workload