Novices
SQL Tuning for Smarties, Dummies and Everyone in Between
Jagan Athreya
Director, Database Manageability, Oracle
Arup Nanda
Senior Director, Database Architecture, Starwood Hotels and Resorts
Outline
SQL Tuning
g Challenges
g
SQL Tuning Solutions New Feature Overview
Problem Root Causes and their Solutions
Preventing SQL Problems
Q&A
Development staff
Mostly
y non-Oracle skills Java,, C++
Usually considers the DB as a black box
Writing efficient queries, troubleshooting performance issues
is delegated to DBAs
Response
DBA: Developer should be taking care of this.
Developer: Why is the DBA not aware of this problem?
Manager: DBA will review all queries and approve them.
Challenge
What is the most efficient way to manage this process?
Response
Users: How will the application perform after the changes?
DBA: How do I ensure that our SLA remains intact after the
changes are rolled out?
Challenge
How to reduce business risk while absorbing new
technologies?
Response
DBA:
Will statistics refresh break something?
What will happen if we dont collect?
How often should I collect the statistics ?
What happens
pp
when yyou collect a new set?
Challenge
What is the recommended strategy for managing optimizer
statistics to ensure the best performance?
Outline
SQL Tuning
g Challenges
g
SQL Tuning Solutions New Feature Overview
Problem Root Causes and their Solutions
Preventing SQL Problems
Q&A
10
11
12
DEMO
13
Application Tuning
Automatic SQL Tuning
Well-Tuned SQL
Packaged Apps +
SQL Profile
High-Load
Customizable
C
t
i bl Apps
A
+
SQL Advice
Customizable Apps +
Indexes & MVs +
Partitions
Applications
SQL Profiling
Statistics Analysis
Access Path Analysis
Automatic Tuning
Optimizer
SQL Tuning
Advisor
Adopt Alternati
Alternative
e
Execution Plan
Administrator
Comprehensive
SQL Tuning
Recommendations
15
Query Window
Tune individual SQL statements with STA
Server Explorer
Manage AWR snapshots and ADDM tasks
16
Agenda
SQL Tuning
g Challenges
g
SQL Tuning Solutions New Feature Overview
Problem Root Causes and their Solutions
Preventing SQL Problems
Q&A
17
2.
Application Issues
a.
b.
3.
5.
Missing
Mi
i access structures
t t
Poorly written SQL statements
4.
Stale/Missing statistics
Incomplete statistics
Improper optimizer configuration
pg
database: new optimizer
p
Upgraded
Changing statistics
Rapidly changing data
Parallelism issues
a.
b.
Not p
parallelized ((no scaling
g to large
g data))
Improperly parallelized (partially parallelized, skews)
18
2.
3.
4.
5.
a. Stale/Missing statistics
b. Incomplete statistics
c. Improper optimizer configuration
d. Upgraded database: new optimizer
e. Changing
g g statistics
f. Rapidly changing data
Application Issues
Cursor sharing issues
Resource and contention issues
Parallelism issues
19
Suboptimal Plans
Optimizer Statistics
Table Statistics
CBO
Column Statistics
I d Statistics
Index
S i i
Partition Statistics
System Statistics
20
Novice
Mode
Nightly
Set DBMS_STATS.SET_GLOBAL_PREFS
21
Expert
Mode
Extended Statistics
Extended Optimizer Statistics provides a mechanism
to collect statistics on a group of related columns:
Function-Based Statistics
Multi-Column Statistics
Pending Statistics
Allows validation of statistics before publishing
Disabled by default
To enable,, set table/schema PUBLISH setting
g to FALSE
DBMS_STATS.SET_TABLE_PREFS('SH','CUSTOMERS','PUBLISH','false')
2. Application Issues
3.
4
4.
5.
23
Novice
M d
Mode
24
Performance Page
Top Activity
CPU
I/O
Non-idle waits
Historical analysis
AWR data
Performance Page
g
Real-time analysis
ASH data
More g
granular analysis
y
Enables identification of
transient problem SQL
Top Activity Page
Tune using SQL Tuning Advisor
25
Novice+
Mode
Indexes: B-tree indexes, B-tree cluster indexes, Hash cluster indexes, Global
and local indexes, Reverse key indexes, Bitmap indexes, Function-based
indexes, Domain indexes
Materialized Views:
Primary Key materialized views,
Object materialized views
ROWID materialized views
Complex materialized views
Partitioned Tables:
Range partitioning, Hash partitioning,
List partitioning, Composite partitioning,
Interval Partitioning
Partitioning, REF partitioning
partitioning,
Virtual Column Based partitioning
B-tree index
26
Novice+
Mode
Indexes
Representative
Workload
SQL Access
Advisor
Materialized
views
Automatic Tuning
Optimizer
Access Path
Analysis
Materialized
views logs
Partitioned
objects
27
Expert
Mode
Workload filtering
Limited vs. advanced mode
Tablespaces for access structures
Hypothetical workload tuning
Factoring in the cost of creation
Space limitations for indexes and MVs
28
Optimizer
O
ti i
statistics
t ti ti issues
i
Application Issues
4.
5.
a. Literal usage
a
b. Bind-sensitive SQL with bind peeking
Resource and contention issues
Parallelism issues
29
Expert
Mode
SELECT * FROM
SELECT * FROM
SELECT * FROM
Sharing
Sh
i
Cursors
is good!
Library Cache
30
N
Mode
CBO10g
FTS
99
N
Problem: Binds will affect optimality in any subsequent uses of the stored plan
31
Expert
Mode
1
20
25
Same
Plan
2
22
24
Different
Plan
30
35
Same
Plan,
Expand
Interval
34
43
32
Agenda
SQL Tuning
g Challenges
g
SQL Tuning Solutions New Feature Overview
Problem Root Causes and their Solutions
Preventing SQL Problems
Q&A
33
GB
Parse
NL
NL
Plan history
GB
Plan baseline
NL
GB
NL
HJ
HJ
34
GB
HJ
HJ
HJ
OH Schema
GB
HJ
HJ
HJ
No plan
regressions
CREATE_STORED_OUTLINES=true
OH Schema
CREATE_STORED_OUTLINES=false
GB
HJ
HJ
35
Steps:
1.
2.
3.
4.
5.
SQL Workload
Validating
upgrade with SPA
Compare
SQL Performance
Analysis Report
36
Conclusion
Identify, Resolve, Prevent
1.
2.
3.
4
4.
Production Performance
Prevent
SPA
Change Causing Problems
SPM
Optimizer Statistics Management
B d plans
Bad
l
Diagnosis
Di
i and
dR
Resolution
l ti
Resolve
ADDM, Top Activity, SQL Monitoring
Tuning Advisor
Advisor,
Identify
Top Activity,
Access Advisor,
ADDM,
SQL Monitoring
37
38