The Self-Managing Database: Guided Application and SQL Tuning

44

description

Session id: 40713. The Self-Managing Database: Guided Application and SQL Tuning. Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation. Agenda. SQL Tuning Challenges Automatic SQL Tuning Overview Usage Scenarios High load SQL tuning Custom SQL workload tuning - PowerPoint PPT Presentation

Transcript of The Self-Managing Database: Guided Application and SQL Tuning

Page 1: The Self-Managing Database: Guided Application and SQL Tuning
Page 2: The Self-Managing Database: Guided Application and SQL Tuning

The Self-Managing Database:Guided Application and SQL Tuning

Mohamed ZiauddinConsulting Member of Technical Staff

Oracle Corporation

Session id: 40713

Page 3: The Self-Managing Database: Guided Application and SQL Tuning

Agenda

SQL Tuning Challenges Automatic SQL Tuning Overview Usage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 4: The Self-Managing Database: Guided Application and SQL Tuning

Manual SQL Tuning Challenges

DBA

How can I

tune high-load

SQL?

High-LoadSQL

SQL

Workload

DBA

How can I

selecthigh-load

SQL?

Page 5: The Self-Managing Database: Guided Application and SQL Tuning

Manual SQL Tuning Challenges

Requires expertise in several domains– SQL optimization: adjust the execution plan– Access design: provide fast data access– SQL design: use appropriate SQL constructs

Time consuming– Each SQL statement is unique– Potentially large number of statements to tune

Never ending task– SQL workload always evolving– Plan regressions

Page 6: The Self-Managing Database: Guided Application and SQL Tuning

An Example Tuning Scenario

Manual Tuning

1. Get explain plan2. Examine query objects and their sizes3. Review and compare explain plan statistics with

execution statistics (stored in V$SQL view)4. Identify that it is a “first rows” issue because

only recent data is ever displayed despite large history being queried

5. Contact application vendor6. Produce test case for vendor7. Get a patch with “first rows” hint from the

vendor8. Install the patch in next maintenance cycle

Problem: Incorrect Optimizer Mode Selection

Page 7: The Self-Managing Database: Guided Application and SQL Tuning

Intelligent Infrastructure

Application & SQLManagement

System ResourceManagement

SpaceManagement

Backup & RecoveryManagement

StorageManagement

Database Control

Database Management

Oracle 10g – SQL Tuning Solution

Page 8: The Self-Managing Database: Guided Application and SQL Tuning

Oracle 10g Automates the SQL Tuning Process

I can do it for you !

SQL Tuning Advisor

DBAHigh-Load

SQL

ADDM

SQL

Workload

Page 9: The Self-Managing Database: Guided Application and SQL Tuning

Agenda

SQL Tuning Challenges Automatic SQL Tuning Overview Usage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 10: The Self-Managing Database: Guided Application and SQL Tuning

Automatic SQL Tuning Overview

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

Gather Missing or Stale Statistics

DBA

SQL Tuning

RecommendationsSQL Tuning

Advisor

Page 11: The Self-Managing Database: Guided Application and SQL Tuning

Automatic Tuning Optimizer (ATO)

It is the query optimizer running in tuning mode– Uses same plan generation process but performs

additional steps that require lot more time

It performs verification steps– To validate statistics and its own estimates

Uses dynamic sampling and partial executions to validate

It performs exploratory steps– To investigate the use of new indexes that could

provide significant speed-up– To analyze SQL constructs that led to expensive

plan operators

Page 12: The Self-Managing Database: Guided Application and SQL Tuning

Statistics Analysis

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

Gather Missing or Stale Statistics

DBA

SQL Tuning

RecommendationsSQL Tuning

Advisor

Page 13: The Self-Managing Database: Guided Application and SQL Tuning

Statistics Analysis

Motivation– Statistics are key input to the query optimizer

Their availability and accuracy is very important

In Oracle10g, the Automatic statistics collection maintains statistics up to date…

– But it may not be enabled or properly configured!

The ATO verifies statistics that it needs/uses– Generates auxiliary information to compensate for

missing or stale statistics– Generates recommendations to gather statistics

where appropriate

Page 14: The Self-Managing Database: Guided Application and SQL Tuning

SQL Profiling

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

Gather Missing or Stale Statistics

DBA

SQL Tuning

RecommendationsSQL Tuning

Advisor

Page 15: The Self-Managing Database: Guided Application and SQL Tuning

SQL Profiling

Motivation– Empower the query optimizer to find a better plan

The query optimizer has time constraints– Makes compromises while finding right plan

The ATO is allowed a lot more time– Uses the time to gather customized information

about the SQL statement, known as SQL Profile– Builds a SQL Profile and recommends it– Once implemented, SQL Profile is used by the

query optimizer to generate a well-tuned plan

Page 16: The Self-Managing Database: Guided Application and SQL Tuning

SQL Profiling Flow

Optimizer(Tuning Mode)

createsubmit

SQL Profiling

Optimizer(Normal Mode)

outputsubmit

SQL Profile

SQL TuningAdvisor

DatabaseUsers

Well-Tuned

Plan

After …

use

Page 17: The Self-Managing Database: Guided Application and SQL Tuning

SQL Profile It contains auxiliary information collected by the

ATO for a SQL statement– Customized optimizer settings

Based on past execution history (e.g., first_rows vs. all_rows)

– Compensation for missing or stale statistics– Compensation for errors in optimizer estimates

Estimation errors occur due to data skews and correlations, complex filters and joins

It doesn’t require any change to the SQL text– Ideal for Packaged Apps

It is persistent– Works across shutdowns and upgrades

Page 18: The Self-Managing Database: Guided Application and SQL Tuning

Access Path Analysis

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

Gather Missing or Stale Statistics

DBA

SQL Tuning

RecommendationsSQL Tuning

Advisor

Page 19: The Self-Managing Database: Guided Application and SQL Tuning

Access Path Analysis

Motivation– Adding an index may significantly improve the

performance of a SQL statement

Problem: A critical access path is missing– Index not created or mistakenly dropped

ATO explores the use of new indexes– Recommends an index if it provides a major

performance boost– Also recommends to run SQL Access Advisor to get

comprehensive index analysis based on a workload SQL Access Advisor also uses this analysis mode

Page 20: The Self-Managing Database: Guided Application and SQL Tuning

SQL Structure Analysis

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

Gather Missing or Stale Statistics

DBA

SQL Tuning

RecommendationsSQL Tuning

Advisor

Page 21: The Self-Managing Database: Guided Application and SQL Tuning

SQL Structure Analysis Motivation

– Help application developers identify poorly written SQL statements

– Suggest restructuring of SQL for efficiency

Problem categories– Semantic changes of SQL operators (e.g., use

UNION ALL instead of UNION) Subject to user acceptance of new result

– Syntactic changes to predicates on indexed columns (e.g., remove type mismatch in column = :bind)

– Design issues (e.g., add missing join predicate to eliminate a large Cartesian join)

Page 22: The Self-Managing Database: Guided Application and SQL Tuning

Agenda

SQL Tuning Challenges Automatic SQL Tuning Overview Usage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 23: The Self-Managing Database: Guided Application and SQL Tuning

SQL Tuning Usage Scenarios

SQL Tuning Advisor

ADDM High-load SQL

Cursor Cache

AWR

SQL Tuning Set(STS)

User-defined

Filter / Rank

SQL Sources Manual Selection

Automatic Selection

AWR

Page 24: The Self-Managing Database: Guided Application and SQL Tuning

SQL Tuning Set (STS)

Motivation– Enable user to tune a custom set of SQL statements

It is a new object in Oracle10g for capturing SQL workload

It stores SQL statements along with..– Execution context: parsing user, bind values, etc.– Execution statistics: buffer gets, CPU time, elapse

time, number of executions, etc.

It is created from a SQL source– Sources: AWR, cursor cache, user-defined SQL

workload, another STS

Page 25: The Self-Managing Database: Guided Application and SQL Tuning

SQL Tuning Set Benefits

Allows selective, on-demand, custom SQL workload tuning

It simplifies tuning of a large number of SQL statements

It is persistent Provides a common infrastructure for dealing

with SQL workloads– Can be used as a source for different tuning tasks

Page 26: The Self-Managing Database: Guided Application and SQL Tuning

Agenda

SQL Tuning Challenges Automatic SQL Tuning Overview Usage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 27: The Self-Managing Database: Guided Application and SQL Tuning

Enterprise Manager Interface

Launch SQL Tuning Advisor from a SQL Source page

– ADDM Finding page, or– Top SQL page, or– SQL Tuning Set (STS) page

View SQL Tuning Recommendations Implement SQL Tuning Recommendations

Page 28: The Self-Managing Database: Guided Application and SQL Tuning

SQL Source: ADDM Finding

Page 29: The Self-Managing Database: Guided Application and SQL Tuning

SQL Source: Top SQL

Page 30: The Self-Managing Database: Guided Application and SQL Tuning

SQL Source: SQL Tuning Set

Page 31: The Self-Managing Database: Guided Application and SQL Tuning

SQL Tuning Options

Page 32: The Self-Managing Database: Guided Application and SQL Tuning

Enterprise Manager Interface

Launch SQL Tuning Advisor from a SQL Source page

– ADDM Finding page, or– Top SQL page, or– SQL Tuning Set (STS) page

View SQL Tuning Recommendations Implement SQL Tuning Recommendations

Page 33: The Self-Managing Database: Guided Application and SQL Tuning

SQL Tuning Recommendations — Overview

Page 34: The Self-Managing Database: Guided Application and SQL Tuning

SQL Tuning Recommendations — Details

Page 35: The Self-Managing Database: Guided Application and SQL Tuning

Enterprise Manager Interface

Launch SQL Tuning Advisor from a SQL Source page

– ADDM Finding page, or– Top SQL page, or– SQL Tuning Set (STS) page

View SQL Tuning Recommendations Implement SQL Tuning Recommendations

Page 36: The Self-Managing Database: Guided Application and SQL Tuning

Implement Recommendations

Page 37: The Self-Managing Database: Guided Application and SQL Tuning

Implement Recommendations

Page 38: The Self-Managing Database: Guided Application and SQL Tuning

Agenda

SQL Tuning Challenges Automatic SQL Tuning Overview Usage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 39: The Self-Managing Database: Guided Application and SQL Tuning

DBMS_SQLTUNE PL/SQL Package

Contains API for SQL Tuning

– Create Tuning Task– Execute Tuning Task– Display Advisor

Recommendations– Drop Tuning Task

– Create STS– Populate STS– Query STS Contents– Drop STS

– Accept SQL Profile– Drop SQL Profile– Alter SQL Profile

Attribute

Tuning Task Management STS Management

SQL Profile Management

Page 40: The Self-Managing Database: Guided Application and SQL Tuning

Conclusion

Manual Tuning

1. Get explain plan2. Examine query objects and their sizes3. Review and compare explain plan statistics

with execution statistics (stored in V$SQL view)

4. Identify that it is a “first rows” issue because only recent data is ever displayed despite large history being queried

5. Contact application vendor6. Produce test case for vendor7. Get a patch with “first rows” hint from the

vendor8. Install the patch in next maintenance cycle

Automatic Tuning

1. Run SQL Tuning Advisor

2. Implement SQL profile

Problem: Incorrect Optimizer Mode Selection

Page 41: The Self-Managing Database: Guided Application and SQL Tuning

Recommended Sessions/Demos

Automatic SGA Memory Management (Tuesday, 5 PM, Room 103)

The Invisible Oracle: Deploying Oracle DB in Embedded Environments (Wednesday, 4:30 PM, Room 103

Automatic Health Monitoring (Thursday, 11:00 AM, Room 103

Proactive Performance Management

Automatic Memory Management

Proactive Space Management

Invisible Installation & Deployment

Automatic Storage Management

Easy Upgrade

Technical Sessions Campground Demos

Page 42: The Self-Managing Database: Guided Application and SQL Tuning

Reminder –

Please complete the OracleWorld online session survey.

This was Session # 40173

Thank you.

Page 43: The Self-Managing Database: Guided Application and SQL Tuning

AQ&Q U E S T I O N SQ U E S T I O N S

A N S W E R SA N S W E R S

Page 44: The Self-Managing Database: Guided Application and SQL Tuning