Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning...

45

Transcript of Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning...

Page 1: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning
Page 2: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Session id: 40713

The Self-Managing Database:Guided Application and SQL Tuning

Page 3: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Lead Architects

Benoit Dageville

Khaled Yagoub

Mohamed Zait

Mohamed Ziauddin

Page 4: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Agenda

SQL Tuning ChallengesAutomatic SQL Tuning OverviewUsage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 5: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Manual SQL Tuning Challenges

SQLWorkload

DBA

How can I select

high-load SQL?

How can I tune

high-load SQL?

DBAHigh-Load

SQL

Page 6: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load 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 7: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Packaged App Tuning ScenarioProblem: Incorrect Optimizer Mode Selection

Manual Tuning1. 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 queried5. 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

Page 8: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Oracle 10g – SQL Tuning Solution

Intelligent Infrastructure

Application & SQLManagement

System ResourceManagement

SpaceManagement

Backup & RecoveryManagement

StorageManagement

Database ManagementDatabase

Control

Page 9: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Oracle 10g Automates the SQL Tuning Process

I can do it for you !

ADDM DBAHigh-Load

SQL

SQLWorkload

SQL Tuning Advisor

Page 10: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Agenda

SQL Tuning ChallengesAutomatic SQL Tuning OverviewUsage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 11: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Automatic SQL Tuning Overview

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

SQL Tuning Advisor

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Gather Missing or Stale Statistics

SQL TuningRecommendations

DBA

Page 12: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load 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 timeIt performs verification steps

– To validate statistics and its own estimatesUses 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 13: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Statistics Analysis

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

SQL Tuning Advisor

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Gather Missing or Stale Statistics

SQL TuningRecommendations

DBA

Page 14: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Statistics AnalysisMotivation

– Statistics are key input to the query optimizerTheir 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 15: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Profiling

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

SQL Tuning Advisor

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Gather Missing or Stale Statistics

SQL TuningRecommendations

DBA

Page 16: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL ProfilingMotivation

– Empower the query optimizer to find a better planThe query optimizer has time constraints

– Makes compromises while finding right planThe 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 17: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Profiling Flow

Optimizer(Tuning Mode)

createsubmit

SQL Profile

SQL TuningAdvisor use

SQL Profiling

Optimizer(Normal Mode)

outputsubmit

DatabaseUsers

Well-TunedPlan

After …

Page 18: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL ProfileIt contains auxiliary information collected by the ATO for a SQL statement

– Customized optimizer settingsBased 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 19: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Access Path Analysis

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

SQL Tuning Advisor

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Gather Missing or Stale Statistics

SQL TuningRecommendations

DBA

Page 20: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Access Path AnalysisMotivation

– 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 workloadSQL Access Advisor also uses this analysis mode

Page 21: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Structure Analysis

Automatic Tuning Optimizer

SQL Structure Analysis

Access Path Analysis

SQL Profiling

Statistics Analysis

SQL Tuning Advisor

Add Missing Indexes

Modify SQL Constructs

Create a SQL Profile

Gather Missing or Stale Statistics

SQL TuningRecommendations

DBA

Page 22: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Structure AnalysisMotivation

– Help application developers identify poorly written SQL statements

– Suggest restructuring of SQL for efficiencyProblem 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)

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

Page 23: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Agenda

SQL Tuning ChallengesAutomatic SQL Tuning OverviewUsage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 24: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Tuning Usage Scenarios

ADDM High-load SQLAWR

Automatic Selection

Cursor Cache

AWR

SQL Tuning Set(STS)

User-defined

Filter / Rank

SQL Sources Manual Selection

SQL Tuning Advisor

Page 25: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Tuning Set (STS)Motivation

– Enable user to tune a custom set of SQL statementsIt is a new object in Oracle10g for capturing SQL workloadIt 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 26: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Tuning Set Benefits

Allows selective, on-demand, custom SQL workload tuningIt simplifies tuning of a large number of SQL statementsIt is persistentProvides a common infrastructure for dealing with SQL workloads

– Can be used as a source for different tuning tasks

Page 27: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Agenda

SQL Tuning ChallengesAutomatic SQL Tuning OverviewUsage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 28: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load 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 RecommendationsImplement SQL Tuning Recommendations

Page 29: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Source: ADDM Finding

Page 30: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Source: Top SQL

Page 31: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Source: SQL Tuning Set

Page 32: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Tuning Options

Page 33: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load 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 RecommendationsImplement SQL Tuning Recommendations

Page 34: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Tuning Recommendations — Overview

Page 35: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

SQL Tuning Recommendations — Details

Page 36: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load 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 RecommendationsImplement SQL Tuning Recommendations

Page 37: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Implement Recommendations

Page 38: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Implement Recommendations

Page 39: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Agenda

SQL Tuning ChallengesAutomatic SQL Tuning OverviewUsage Scenarios

– High load SQL tuning– Custom SQL workload tuning

User Interface– Enterprise Manager– DBMS_SQLTUNE PL/SQL package

Conclusion

Page 40: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

DBMS_SQLTUNE PL/SQL Package

Contains API for SQL Tuning

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

Attribute

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

– Create Tuning Task– Execute Tuning Task– Display Advisor

Recommendations– Drop Tuning Task

Tuning Task Management STS Management

SQL Profile Management

Page 41: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

ConclusionProblem: Incorrect Optimizer Mode Selection

Automatic Tuning1. Run SQL Tuning

Advisor2. Implement SQL

profile

Manual Tuning1. 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

Page 42: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Recommended Sessions/Demos

Technical Sessions Campground DemosAutomatic SGA Memory Management (Tuesday, 5 PM, Room 103)The Invisible Oracle: Deploying Oracle DB in Embedded Environments (Wednesday, 4:30 PM, Room 103Automatic Health Monitoring(Thursday, 11:00 AM, Room 103Using the Oracle Database 10g SQL Access Advisor (Thursday, 1:00 PM, Room 102)

Proactive Performance Management Automatic Memory ManagementProactive Space ManagementInvisible Installation & DeploymentAutomatic Storage ManagementEasy Upgrade

Page 43: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Reminder –

Please complete the OracleWorld online session survey.

This was Session # 40173

Thank you.

Page 44: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning

Q U E S T I O N SQ U E S T I O N SA N S W E R SA N S W E R S

Page 45: Session id: 40713 - oracle.com · Khaled Yagoub Mohamed Zait Mohamed Ziauddin. Agenda ySQL Tuning Challenges yAutomatic SQL Tuning Overview yUsage Scenarios – High load SQL tuning