SlideShare a Scribd company logo
1 of 64
Download to read offline
SQL Tuning in Oracle 10g:
The Do’s and Don’ts
Mughees A. Minhas
Group Product Manager
Database Manageability
Oracle Corp.
Outline
y Introduction
y Manual Tuning Challenges
y SQL Tuning & Access Advisor Overview
y SQL Tuning Advisor
– Automatic SQL Tuning
– Usage scenarios
– User interface
y SQL Access Advisor
– Usage scenarios
– User interface
y Tips, Do’s, Don’ts
y Conclusion
Introduction
y Automatic SQL Tuning solution consists of
– SQL Tuning Advisor
– SQL Access Advisor
y Provides comprehensive, automatic, and cost-
effective solution for application tuning
y Reduces SQL tuning time by up to 80%
y Reduces management cost
Manual Tuning Challenges
y Requires expertise in several domains
– SQL optimization: adjust the execution plan
– Access design: provide fast data access
– SQL design: use appropriate SQL constructs
y Time consuming
– Each SQL statement is unique
– Potentially large number of statements to tune
y Never ending task
– SQL workload always evolving
– Plan regressions
Manual Tuning Example
Packaged App Tuning Scenario
Manual Tuning
1. Get explain plan
2. Examine query objects and their sizes
3. Review and compare explain plan statistics with execution
statistics (stored in V$SQL view)
4. Identify the problem, e.g., “first rows” issue because only recent
data is ever displayed despite large history being queried
5. Contact application vendor
6. Produce test case for vendor
7. Get a patch with appropriate code modifications from the
vendor
8. Install the patch in next maintenance cycle
SQL Tuning & Access Advisor
Overview
How do I tune
my SQL
workload?
SQL Tuning &
Access Advisors
Solution
Component
of CBO
Provides
implementation
script
No expert
required
DBA
SQL
Workload
SQL Tuning Advisor
Oracle 10g Automates the SQL
Tuning Process
I can do it
for you !
SQL Tuning
Advisor
DBA
High-Load
SQL
ADDM
SQL
Workload
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
Recommendations
SQL Tuning
Advisor
Automatic Tuning Optimizer (ATO)
y It is the query optimizer running in tuning mode
– Uses same plan generation process but performs
additional steps that require significantly more time
y It performs verification steps
– To validate statistics and its own estimates
y Uses dynamic sampling and partial executions to validate
y 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
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
Recommendations
SQL Tuning
Advisor
Statistics Analysis
y Motivation
– Statistics are key input to the query optimizer
y Their availability and accuracy is very important
y In Oracle10g, the Automatic Statistics
Collection maintains statistics up to date…
– But it may not be enabled or properly configured!
y 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
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
Recommendations
SQL Tuning
Advisor
SQL Profiling
y Motivation
– Empower query optimizer to find better plan by
gathering additional information on query behavior
y The query optimizer has time constraints
– Makes compromises while finding right plan
y 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
SQL Profile
y Contains auxiliary information collected by the
ATO for a SQL statement
– Customized optimizer settings
y Based on past execution history (e.g., first_rows vs. all_rows)
– Compensation for missing or stale statistics
– Compensation for errors in optimizer estimates
y Estimation errors occur due to data skews and correlations,
complex filters and joins
y Doesn’t require any change to the SQL text
– Ideal for Packaged Apps
y Persistence: Works across shutdowns & upgrades
y Transportable across databases (10.2)
SQL Profiling Flow
Optimizer
(Tuning Mode)
create
submit
SQL Profiling
Optimizer
(Normal Mode)
output
submit
SQL
Profile
SQL Tuning
Advisor
Database
Users
Well-Tuned
Plan
After …
use
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
Recommendations
SQL Tuning
Advisor
Access Path Analysis
y Motivation
– Adding an index may significantly improve the
performance of a SQL statement
y Problem: A critical access path is missing
– Index not created or mistakenly dropped
y ATO explores the use of new indexes
– Recommends index if major performance boost
provided
– Also recommends running SQL Access Advisor to get
comprehensive index analysis for entire workload
y SQL Access Advisor also uses this analysis mode
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
Recommendations
SQL Tuning
Advisor
SQL Structure Analysis
y Motivation
– Help application developers identify poorly written
SQL statements
– Suggest restructuring of SQL for efficiency
y Problem categories
– Semantic changes of SQL operators (e.g., use
UNION ALL instead of UNION)
y 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)
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
SQL Tuning Set (STS)
y Motivation
– Enable user to tune custom set of SQL statements
y New object in Oracle10g for capturing and
managing SQL workload
y Stores SQL statements along with:
– Execution context: parsing user, bind values, etc.
– Execution statistics: buffer gets, CPU time, elapse
time, number of executions, etc.
y Transportable across databases (10.2)
y Created from any SQL source
– AWR, cursor cache, user-defined workload, STS
SQL Tuning Set Benefits
y Allows selective, on-demand, custom SQL
workload tuning
y Simplifies tuning of large number of SQL
statements
y Is persistent
y Facilitates workload capture/management
y Provides a common infrastructure for dealing
with SQL workloads
– Can be used as a source for different tuning tasks
SQL Tuning Advisor User
Interface
y GUI: Enterprise Manager
y Launch SQL Tuning Advisor from a SQL
Source page
– ADDM Finding page, or
– Top SQL page, or
– SQL Tuning Set (STS) page
y View/Implement SQL Tuning
Recommendations
y Command line: DBMS_SQLTUNE package
SQL Source: ADDM Finding
SQL Source: Top SQL
SQL Source: SQL Tuning Set
Enterprise Manager Interface
y Launch SQL Tuning Advisor from a SQL
Source page
– ADDM Finding page, or
– Top SQL page, or
– SQL Tuning Set (STS) page
y View/Implement SQL Tuning
Recommendations
SQL Tuning Recommendations — Overview
DBMS_SQLTUNE PL/SQL Package
y 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
Automatic vs. Manual SQL Tuning
Manual Tuning
1. Get explain plan
2. Examine query objects and their sizes
3. Review and compare explain plan statistics with
execution statistics (stored in V$SQL view)
4. Identify the problem, e.g., “first rows” issue because
only recent data is ever displayed despite large history
being queried
5. Contact application vendor
6. Produce test case for vendor
7. Get a patch with appropriate code modifications from
the vendor
8. Install the patch in next maintenance cycle
Automatic Tuning
1. Run SQL Tuning
Advisor
2. Implement
recommendations.
SQL Access Advisor
SQL Access Advisor
Workload
Indexes Materialized Views
Materialized View Logs
SQL Access
Advisor
SQL Access Advisor Features
y De-mystifies access structure design for optimal
application performance
y Recommends indexes, materialized views, and
materialized view logs to create and/or drop for
faster performance
y Analyzes entire workload and not just independent
SQL statements
y Takes into account impact of new access
structures on DML operations
y Considers storage, creation and maintenance
costs
SQL Access Advisor Features
y Simultaneously considers
– index solutions
– materialized view solutions
– combinations of both
y Optimizes materialized views for
– maximum query rewrite usage
– fast refresh
y Recommends materialized view logs for fast refresh
y Combines similar indexes into single index
y Impact of new access structures on DML considered
y Considers storage, creation & maintenance costs
Usage Scenarios
Workload
User Defined
Hypothetical
Cursor Cache
Filter
Options
STS
SQL Access
Advisor
Filter Options
y Don’t have to use the entire workload
y Filter by
– Application or module name
– Number of SQL statements
– Queries during a specified time window
– Username
– Tables
y must be in this list
y not in this list
SQL Access Advisor User
Interface
y GUI: Enterprise Manager
– Launch SQL Access Advisor from Advisor Central
– Select workload source
– Set options
y Workload
y Recommendation
y Advanced
– Schedule job
– Review job and submit
– Monitor job
– View Recommendations
– Implement Recommendations
y Command line: DBMS_ADVISOR package
Launch SQL Access Advisor
Select Workload Source
Set Workload Options
Set Recommendation Options
Advanced Options
Advanced Tuning Options
y SQL statements will be tuned
according to the resources they use
Schedule Job
Review & Submit
Monitor the Job
View Recommendations
Implement Recommendations
Tips, Do’s, Dont’s
Capturing SQL Workload
y Use cursor cache capture capability of STS
– Run workload
– Capture workload in STS simultaneously
DBMS_SQLTUNE.CAPTURE_CURSOR_CACHE_SQLSET(
sqlset_name => ‘MY_STS’,
time_limit => 3600,
repeat_interval => 60,
sqlset_owner => own);
SQL Profile Cursor Sharing
y Cursor sharing can be enforced at database
or SQL level
– Database level: CURSOR_SHARING=FORCE
– SQL level: Set SQL Profile attribute
FORCE_MATCH=TRUE
DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (
task_name => 'my_sql_tuning_task',
name => 'my_sql_profile',)
force_match => TRUE);
Tuning Considerations
y Resource consumption
– Running SQL advisors consumes CPU, I/O, memory and can
affect system performance
y Potential negative impact of recommendation
– Implementing recommendations may impact system
negatively, e.g., optimizer stats refresh
• Before initiating tuning, answer the following
questions
• How much resources will be consumed by tuning activity?
• Can the system spare resources needed for tuning?
• How can the production system be shielded from possible
negative impact of tuning actions?
Resource Consumption of SQL
Advisors
y SQL Tuning Advisor
– Limited mode: Resource consumption minimal
y Stats, index and SQL restructure analysis is cheap
y Average is less than 1 second per SQL statement
– Comprehensive mode: Resource consumption may be
significant
y SQL Profiling can potentially consume non-trivial resources
y Roughly comparable to amount of resources/time consumed
when executing SQL statement(s)
• SQL Access Advisor
• Resource consumption depends on size of SQL workload
• For small number of SQL, resource consumption not very high
Tuning Options
y Options
– Direct tuning of live system
– Remote tuning
y Live system tuning
– Run SQL Tuning Advisor in Comprehensive mode
– Run SQL Tuning Advisor in Limited mode only if …
y System does not have spare resources to tune SQL
– Run SQL Access Advisor for few SQL at a time
y Perform remote tuning, if …
– Cumulative resources/time consumed by all SQL
statements being tuned significant
– System cannot spare resources
Live System Tuning Tips
1. Ensure tables referenced in SQL have representative
optimizer stats
2. Run SQL Access Advisor
– For individual SQL, set “Recommendation Type” to indexes
– MV not suitable for tuning individual statements
3. Run SQL Tuning Advisor
– Test profile before making it PUBLIC
DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (
task_name => ‘<tuning task name>’,
category => ‘MY_CATEGORY’);
ALTER SESSION SET SQLTUNE_CATEGORY=‘MY_CATEGORY’ ;
– Once satisfied with results set category to DEFAULT
DBMS_SQLTUNE.ALTER_SQL_PROFILE()
Remote Tuning Tips
1. Move SQL to Test
Production System Test System
2. Tune SQL
3. Apply recomm. on production
• Performed to shield production system from
performance impact of running SQL advisors
Remote Tuning Tips
y Move SQL to test
– Use Transportable STS
y DBMS_SQLTUNE.XXX_STGTAB_SQLSET
y Apply recommendation on production
– Use Transportable SQL Profiles
y DBMS_SQLTUNE.XXX_STGTAB_SQLPROF
Automatic SQL Tuning
Summary
SQL Access Advisor
Access Path: Materialized View Logs
SQL Access Advisor
Access Path: Materialized Views
SQL Tuning/Access
Advisor
Access Path: Indexes
SQL Tuning Advisor
SQL Structure
SQL Tuning Advisor
SQL Profile
SQL Tuning Advisor
Statistics
Performed By
Analysis Types
SQL Tuning Advisor and SQL Access Advisor
together completely automate SQL tuning
Conclusion
y SQL Advisors help address critical SQL tuning
challenges
y Provides targeted and automated tuning
y Makes possible comprehensive tuning of
packaged applications
y Eliminates need for highly skilled performance
experts
Thank You!
Q U E S T I O N S
Q U E S T I O N S
A N S W E R S
A N S W E R S
SQL Tuning and Access Advisor Guide

More Related Content

Similar to SQL Tuning and Access Advisor Guide

Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Sql server club - performance management methodologies and enhancements in sq...
Sql server club - performance management methodologies and enhancements in sq...Sql server club - performance management methodologies and enhancements in sq...
Sql server club - performance management methodologies and enhancements in sq...Charley Hanania
 
Sql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scaleSql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scaleKlaudiia Jacome
 
Rock Solid SQL Server Management
Rock Solid SQL Server ManagementRock Solid SQL Server Management
Rock Solid SQL Server ManagementTony Bain
 
Business Intelligence Portfolio 2003
Business Intelligence Portfolio 2003Business Intelligence Portfolio 2003
Business Intelligence Portfolio 2003troylrockwell
 
World2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverviewWorld2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverviewFarah Omer
 
A Primer To Sybase Iq Development July 13
A Primer To Sybase Iq Development July 13A Primer To Sybase Iq Development July 13
A Primer To Sybase Iq Development July 13sparkwan
 
New features of sql server 2016 bi features
New features of sql server 2016 bi featuresNew features of sql server 2016 bi features
New features of sql server 2016 bi featuresChris Testa-O'Neill
 
Satya\'s Resume
Satya\'s ResumeSatya\'s Resume
Satya\'s Resumesqlmaster
 
Modernizing SQL Server the Right Way
Modernizing SQL Server the Right WayModernizing SQL Server the Right Way
Modernizing SQL Server the Right WayJuan Fabian
 
SQL Server Workshop for Developers - Visual Studio Live! NY 2012
SQL Server Workshop for Developers - Visual Studio Live! NY 2012SQL Server Workshop for Developers - Visual Studio Live! NY 2012
SQL Server Workshop for Developers - Visual Studio Live! NY 2012Andrew Brust
 
Microsoft SQL Server - SQL Server Migrations Presentation
Microsoft SQL Server - SQL Server Migrations PresentationMicrosoft SQL Server - SQL Server Migrations Presentation
Microsoft SQL Server - SQL Server Migrations PresentationMicrosoft Private Cloud
 
Monitor and tune for performance
Monitor and tune for performanceMonitor and tune for performance
Monitor and tune for performanceSteve Xu
 
Whatsnew in-my sql-primary
Whatsnew in-my sql-primaryWhatsnew in-my sql-primary
Whatsnew in-my sql-primaryKaizenlogcom
 
Database migration
Database migrationDatabase migration
Database migrationOpris Monica
 

Similar to SQL Tuning and Access Advisor Guide (20)

Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Sql server club - performance management methodologies and enhancements in sq...
Sql server club - performance management methodologies and enhancements in sq...Sql server club - performance management methodologies and enhancements in sq...
Sql server club - performance management methodologies and enhancements in sq...
 
Sql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scaleSql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scale
 
Vijaya_Lakshmi_Resume1
Vijaya_Lakshmi_Resume1Vijaya_Lakshmi_Resume1
Vijaya_Lakshmi_Resume1
 
Satya Cv
Satya CvSatya Cv
Satya Cv
 
Satya jayanty CV
Satya jayanty CVSatya jayanty CV
Satya jayanty CV
 
Rock Solid SQL Server Management
Rock Solid SQL Server ManagementRock Solid SQL Server Management
Rock Solid SQL Server Management
 
Business Intelligence Portfolio 2003
Business Intelligence Portfolio 2003Business Intelligence Portfolio 2003
Business Intelligence Portfolio 2003
 
World2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverviewWorld2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverview
 
A Primer To Sybase Iq Development July 13
A Primer To Sybase Iq Development July 13A Primer To Sybase Iq Development July 13
A Primer To Sybase Iq Development July 13
 
New features of sql server 2016 bi features
New features of sql server 2016 bi featuresNew features of sql server 2016 bi features
New features of sql server 2016 bi features
 
Satya\'s Resume
Satya\'s ResumeSatya\'s Resume
Satya\'s Resume
 
ShashankJainMSBI
ShashankJainMSBIShashankJainMSBI
ShashankJainMSBI
 
Modernizing SQL Server the Right Way
Modernizing SQL Server the Right WayModernizing SQL Server the Right Way
Modernizing SQL Server the Right Way
 
Auditing Data Access in SQL Server
Auditing Data Access in SQL ServerAuditing Data Access in SQL Server
Auditing Data Access in SQL Server
 
SQL Server Workshop for Developers - Visual Studio Live! NY 2012
SQL Server Workshop for Developers - Visual Studio Live! NY 2012SQL Server Workshop for Developers - Visual Studio Live! NY 2012
SQL Server Workshop for Developers - Visual Studio Live! NY 2012
 
Microsoft SQL Server - SQL Server Migrations Presentation
Microsoft SQL Server - SQL Server Migrations PresentationMicrosoft SQL Server - SQL Server Migrations Presentation
Microsoft SQL Server - SQL Server Migrations Presentation
 
Monitor and tune for performance
Monitor and tune for performanceMonitor and tune for performance
Monitor and tune for performance
 
Whatsnew in-my sql-primary
Whatsnew in-my sql-primaryWhatsnew in-my sql-primary
Whatsnew in-my sql-primary
 
Database migration
Database migrationDatabase migration
Database migration
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

SQL Tuning and Access Advisor Guide

  • 1.
  • 2. SQL Tuning in Oracle 10g: The Do’s and Don’ts Mughees A. Minhas Group Product Manager Database Manageability Oracle Corp.
  • 3. Outline y Introduction y Manual Tuning Challenges y SQL Tuning & Access Advisor Overview y SQL Tuning Advisor – Automatic SQL Tuning – Usage scenarios – User interface y SQL Access Advisor – Usage scenarios – User interface y Tips, Do’s, Don’ts y Conclusion
  • 4. Introduction y Automatic SQL Tuning solution consists of – SQL Tuning Advisor – SQL Access Advisor y Provides comprehensive, automatic, and cost- effective solution for application tuning y Reduces SQL tuning time by up to 80% y Reduces management cost
  • 5. Manual Tuning Challenges y Requires expertise in several domains – SQL optimization: adjust the execution plan – Access design: provide fast data access – SQL design: use appropriate SQL constructs y Time consuming – Each SQL statement is unique – Potentially large number of statements to tune y Never ending task – SQL workload always evolving – Plan regressions
  • 6. Manual Tuning Example Packaged App Tuning Scenario Manual Tuning 1. Get explain plan 2. Examine query objects and their sizes 3. Review and compare explain plan statistics with execution statistics (stored in V$SQL view) 4. Identify the problem, e.g., “first rows” issue because only recent data is ever displayed despite large history being queried 5. Contact application vendor 6. Produce test case for vendor 7. Get a patch with appropriate code modifications from the vendor 8. Install the patch in next maintenance cycle
  • 7. SQL Tuning & Access Advisor Overview How do I tune my SQL workload? SQL Tuning & Access Advisors Solution Component of CBO Provides implementation script No expert required DBA SQL Workload
  • 9. Oracle 10g Automates the SQL Tuning Process I can do it for you ! SQL Tuning Advisor DBA High-Load SQL ADDM SQL Workload
  • 10. 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 Recommendations SQL Tuning Advisor
  • 11. Automatic Tuning Optimizer (ATO) y It is the query optimizer running in tuning mode – Uses same plan generation process but performs additional steps that require significantly more time y It performs verification steps – To validate statistics and its own estimates y Uses dynamic sampling and partial executions to validate y 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
  • 12. 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 Recommendations SQL Tuning Advisor
  • 13. Statistics Analysis y Motivation – Statistics are key input to the query optimizer y Their availability and accuracy is very important y In Oracle10g, the Automatic Statistics Collection maintains statistics up to date… – But it may not be enabled or properly configured! y 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
  • 14. 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 Recommendations SQL Tuning Advisor
  • 15. SQL Profiling y Motivation – Empower query optimizer to find better plan by gathering additional information on query behavior y The query optimizer has time constraints – Makes compromises while finding right plan y 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
  • 16. SQL Profile y Contains auxiliary information collected by the ATO for a SQL statement – Customized optimizer settings y Based on past execution history (e.g., first_rows vs. all_rows) – Compensation for missing or stale statistics – Compensation for errors in optimizer estimates y Estimation errors occur due to data skews and correlations, complex filters and joins y Doesn’t require any change to the SQL text – Ideal for Packaged Apps y Persistence: Works across shutdowns & upgrades y Transportable across databases (10.2)
  • 17. SQL Profiling Flow Optimizer (Tuning Mode) create submit SQL Profiling Optimizer (Normal Mode) output submit SQL Profile SQL Tuning Advisor Database Users Well-Tuned Plan After … use
  • 18. 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 Recommendations SQL Tuning Advisor
  • 19. Access Path Analysis y Motivation – Adding an index may significantly improve the performance of a SQL statement y Problem: A critical access path is missing – Index not created or mistakenly dropped y ATO explores the use of new indexes – Recommends index if major performance boost provided – Also recommends running SQL Access Advisor to get comprehensive index analysis for entire workload y SQL Access Advisor also uses this analysis mode
  • 20. 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 Recommendations SQL Tuning Advisor
  • 21. SQL Structure Analysis y Motivation – Help application developers identify poorly written SQL statements – Suggest restructuring of SQL for efficiency y Problem categories – Semantic changes of SQL operators (e.g., use UNION ALL instead of UNION) y 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)
  • 22. 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
  • 23. SQL Tuning Set (STS) y Motivation – Enable user to tune custom set of SQL statements y New object in Oracle10g for capturing and managing SQL workload y Stores SQL statements along with: – Execution context: parsing user, bind values, etc. – Execution statistics: buffer gets, CPU time, elapse time, number of executions, etc. y Transportable across databases (10.2) y Created from any SQL source – AWR, cursor cache, user-defined workload, STS
  • 24. SQL Tuning Set Benefits y Allows selective, on-demand, custom SQL workload tuning y Simplifies tuning of large number of SQL statements y Is persistent y Facilitates workload capture/management y Provides a common infrastructure for dealing with SQL workloads – Can be used as a source for different tuning tasks
  • 25. SQL Tuning Advisor User Interface y GUI: Enterprise Manager y Launch SQL Tuning Advisor from a SQL Source page – ADDM Finding page, or – Top SQL page, or – SQL Tuning Set (STS) page y View/Implement SQL Tuning Recommendations y Command line: DBMS_SQLTUNE package
  • 26. SQL Source: ADDM Finding
  • 28. SQL Source: SQL Tuning Set
  • 29. Enterprise Manager Interface y Launch SQL Tuning Advisor from a SQL Source page – ADDM Finding page, or – Top SQL page, or – SQL Tuning Set (STS) page y View/Implement SQL Tuning Recommendations
  • 31. DBMS_SQLTUNE PL/SQL Package y 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
  • 32. Automatic vs. Manual SQL Tuning Manual Tuning 1. Get explain plan 2. Examine query objects and their sizes 3. Review and compare explain plan statistics with execution statistics (stored in V$SQL view) 4. Identify the problem, e.g., “first rows” issue because only recent data is ever displayed despite large history being queried 5. Contact application vendor 6. Produce test case for vendor 7. Get a patch with appropriate code modifications from the vendor 8. Install the patch in next maintenance cycle Automatic Tuning 1. Run SQL Tuning Advisor 2. Implement recommendations.
  • 34. SQL Access Advisor Workload Indexes Materialized Views Materialized View Logs SQL Access Advisor
  • 35. SQL Access Advisor Features y De-mystifies access structure design for optimal application performance y Recommends indexes, materialized views, and materialized view logs to create and/or drop for faster performance y Analyzes entire workload and not just independent SQL statements y Takes into account impact of new access structures on DML operations y Considers storage, creation and maintenance costs
  • 36. SQL Access Advisor Features y Simultaneously considers – index solutions – materialized view solutions – combinations of both y Optimizes materialized views for – maximum query rewrite usage – fast refresh y Recommends materialized view logs for fast refresh y Combines similar indexes into single index y Impact of new access structures on DML considered y Considers storage, creation & maintenance costs
  • 37. Usage Scenarios Workload User Defined Hypothetical Cursor Cache Filter Options STS SQL Access Advisor
  • 38. Filter Options y Don’t have to use the entire workload y Filter by – Application or module name – Number of SQL statements – Queries during a specified time window – Username – Tables y must be in this list y not in this list
  • 39. SQL Access Advisor User Interface y GUI: Enterprise Manager – Launch SQL Access Advisor from Advisor Central – Select workload source – Set options y Workload y Recommendation y Advanced – Schedule job – Review job and submit – Monitor job – View Recommendations – Implement Recommendations y Command line: DBMS_ADVISOR package
  • 40. Launch SQL Access Advisor
  • 45. Advanced Tuning Options y SQL statements will be tuned according to the resources they use
  • 52. Capturing SQL Workload y Use cursor cache capture capability of STS – Run workload – Capture workload in STS simultaneously DBMS_SQLTUNE.CAPTURE_CURSOR_CACHE_SQLSET( sqlset_name => ‘MY_STS’, time_limit => 3600, repeat_interval => 60, sqlset_owner => own);
  • 53. SQL Profile Cursor Sharing y Cursor sharing can be enforced at database or SQL level – Database level: CURSOR_SHARING=FORCE – SQL level: Set SQL Profile attribute FORCE_MATCH=TRUE DBMS_SQLTUNE.ACCEPT_SQL_PROFILE ( task_name => 'my_sql_tuning_task', name => 'my_sql_profile',) force_match => TRUE);
  • 54. Tuning Considerations y Resource consumption – Running SQL advisors consumes CPU, I/O, memory and can affect system performance y Potential negative impact of recommendation – Implementing recommendations may impact system negatively, e.g., optimizer stats refresh • Before initiating tuning, answer the following questions • How much resources will be consumed by tuning activity? • Can the system spare resources needed for tuning? • How can the production system be shielded from possible negative impact of tuning actions?
  • 55. Resource Consumption of SQL Advisors y SQL Tuning Advisor – Limited mode: Resource consumption minimal y Stats, index and SQL restructure analysis is cheap y Average is less than 1 second per SQL statement – Comprehensive mode: Resource consumption may be significant y SQL Profiling can potentially consume non-trivial resources y Roughly comparable to amount of resources/time consumed when executing SQL statement(s) • SQL Access Advisor • Resource consumption depends on size of SQL workload • For small number of SQL, resource consumption not very high
  • 56. Tuning Options y Options – Direct tuning of live system – Remote tuning y Live system tuning – Run SQL Tuning Advisor in Comprehensive mode – Run SQL Tuning Advisor in Limited mode only if … y System does not have spare resources to tune SQL – Run SQL Access Advisor for few SQL at a time y Perform remote tuning, if … – Cumulative resources/time consumed by all SQL statements being tuned significant – System cannot spare resources
  • 57. Live System Tuning Tips 1. Ensure tables referenced in SQL have representative optimizer stats 2. Run SQL Access Advisor – For individual SQL, set “Recommendation Type” to indexes – MV not suitable for tuning individual statements 3. Run SQL Tuning Advisor – Test profile before making it PUBLIC DBMS_SQLTUNE.ACCEPT_SQL_PROFILE ( task_name => ‘<tuning task name>’, category => ‘MY_CATEGORY’); ALTER SESSION SET SQLTUNE_CATEGORY=‘MY_CATEGORY’ ; – Once satisfied with results set category to DEFAULT DBMS_SQLTUNE.ALTER_SQL_PROFILE()
  • 58. Remote Tuning Tips 1. Move SQL to Test Production System Test System 2. Tune SQL 3. Apply recomm. on production • Performed to shield production system from performance impact of running SQL advisors
  • 59. Remote Tuning Tips y Move SQL to test – Use Transportable STS y DBMS_SQLTUNE.XXX_STGTAB_SQLSET y Apply recommendation on production – Use Transportable SQL Profiles y DBMS_SQLTUNE.XXX_STGTAB_SQLPROF
  • 60. Automatic SQL Tuning Summary SQL Access Advisor Access Path: Materialized View Logs SQL Access Advisor Access Path: Materialized Views SQL Tuning/Access Advisor Access Path: Indexes SQL Tuning Advisor SQL Structure SQL Tuning Advisor SQL Profile SQL Tuning Advisor Statistics Performed By Analysis Types SQL Tuning Advisor and SQL Access Advisor together completely automate SQL tuning
  • 61. Conclusion y SQL Advisors help address critical SQL tuning challenges y Provides targeted and automated tuning y Makes possible comprehensive tuning of packaged applications y Eliminates need for highly skilled performance experts
  • 63. Q U E S T I O N S Q U E S T I O N S A N S W E R S A N S W E R S