You are on page 1of 42

Copyright 2013, Oracle and/or its affiliates.

1
Copyright 2013, Oracle and/or its affiliates. 2
Diagnosing SQL Performance
using SQL Health-Check
(SQLHC)
Carlos Sierra
Consulting Technical Advisor
Center of Expertise (CoE)

Copyright 2013, Oracle and/or its affiliates. 3
Carlos Sierra
SQL Tuner handyman: developer, advisor, trainer, support
IT: Oracle(17), UNISYS(12), Ford(3), others(3)
Florida(17), Venezuela(3), Puerto Rico(6), Michigan(1), Mexico(X)
Tools: SQLTXPLAIN(SQLT), SQLHC, TRCANLZR(TRCA), others
Motto: Life is good!


Oracle Server Technologies(ST) Center of Expertise(CoE)
Copyright 2013, Oracle and/or its affiliates. 4
Agenda
SQL Health-Check Tool (SQLHC)
What, Why, When and How?
Health Checks performed
Output sample
Demo
Copyright 2013, Oracle and/or its affiliates. 5
What is the SQL Health-Check Tool?
Stand-alone SQL script
By the Server Technologies (ST) Center of Expertise (CoE)
SQL Health Check (HC) does not install schema objects
Centric to one SQL statement per use

Copyright 2013, Oracle and/or its affiliates. 6
What is the SQL Health Check Tool?
Inputs one SQL_ID
Outputs
Results of several Health Checks
Additional information
Execute as SYS (or DBA)
Works on
11g and 10.2
UNIX, Linux and Windows

Copyright 2013, Oracle and/or its affiliates. 7
Why would I want to use the SQL HC?
Verify environment around one SQL
Executes in a few minutes
Minimum resources utilization
Documents state around one SQL
Does not pollute the application

Copyright 2013, Oracle and/or its affiliates. 8
Why would I want to use the SQL HC?
Acting upon output of relevant Health Checks
may improve execution plan thus performance
Output is small and easy to digest
Requires intermediate SQL Tuning expertise
Safe to use on DML statements

Copyright 2013, Oracle and/or its affiliates. 9
When should I use the SQL HC Tool?
When a quick sanity check of the environment around one
SQL is needed
On a poorly performing SQL
As per AWR or StatsPack reports
On any SQL statement
Out of a Trace or TKPROF
Copyright 2013, Oracle and/or its affiliates. 10
When should I use the SQL HC Tool?
When using SQLTXPLAIN (SQLT) MOS 215187.1 is
not a short term option
When there had been recent changes on the system
And a SQL has regressed in terms of performance
When performance of a SQL is not consistent
Copyright 2013, Oracle and/or its affiliates. 11
How do I use SQL HC Tool?
Download latest version of sqlhc.sql
Out of MOS (Metalink) 1366133.1
Execute connected as SYS
Or a user with DBA privileges
Parameters
Oracle Diagnostics or Oracle Tuning Pack licenses?
SQL_ID for the SQL statement to be analyzed
Copyright 2013, Oracle and/or its affiliates. 12
How do I use the SQL HC Tool?
Review and digest content of HTML output reports
Focus first on Health-Check report (number 1)
Act upon those Observations reported by HC
Some may be more relevant than others in each case
Copyright 2013, Oracle and/or its affiliates. 13
Health Checks performed
Levels
Global
Table
Index
Purpose
Highlight SQL Tuning opportunities
Highlight concerns
Copyright 2013, Oracle and/or its affiliates. 14
Global Health Checks
Using STATISTICS_LEVEL = ALL on LINUX
CBO parameters with non-default values
optimizer_features_enable <> rdbms_version
optimizer_dynamic_sampling between 1 and 3
db_file_multiblock_read_count is set
nls_sort is not binary

Copyright 2013, Oracle and/or its affiliates. 15
Global Health Checks
DBMS_STATS automatic gathering
High version count
Using first rows
Fixed objects missing statistics
Copyright 2013, Oracle and/or its affiliates. 16
Global Health Checks
SQL with policies as per v$vpd_policy
Materialized views with rewrite enabled
Table with bitmap index(es)
Index in plan no longer exists
System statistics not gathered

Copyright 2013, Oracle and/or its affiliates. 17
Global Health Checks
mreadtim < sreadtim
sreadtim < 2
mreadtim < 3
sreadtim > 18
mreadtim > 522
Copyright 2013, Oracle and/or its affiliates. 18
Global Health Checks
SQL Plan Baseline contains non-reproducible Plans
Sizes of SQL Plan History and SQL Plan Baseline
SQL Profile combined VPD policies
Multiple CBO environments
Copyright 2013, Oracle and/or its affiliates. 19
Global Health Checks
INTERNAL_FUNCTION in a Filter Predicate
Plan Operations with Cost 0 and Cardinality 1
SREADTIM differs from actual db file sequential read
MREADTIM differs from actual db file scattered read
Copyright 2013, Oracle and/or its affiliates. 20
Table Health Checks
empty_blocks > blocks
Table DOP is set
Table has indexes with DOP set
Index degree <> Table degree
No statistics

Copyright 2013, Oracle and/or its affiliates. 21
Table Health Checks
No rows
Siebel: small tables with statistics
Small sample size
Old statistics
Extended statistics
Copyright 2013, Oracle and/or its affiliates. 22
Table Health Checks
Columns with no statistics
Columns missing low/high values
Columns with old statistics
More nulls than rows
More distinct values than rows
Copyright 2013, Oracle and/or its affiliates. 23
Table Health Checks
Zero distinct values on columns with value
Incorrect NDV in long char column with histogram
Frequency histograms with less buckets than NDV
Frequency histogram with 1 bucket
Height balanced histogram with no popular values
Copyright 2013, Oracle and/or its affiliates. 24
Table Health Checks
ANALYZE command was used
Tables with stale statistics
SQL with policies as per dba_policies
SQL with policies as per dba_audit_policies
Copyright 2013, Oracle and/or its affiliates. 25
Table Health Checks
Table partitions with no statistics
Table partitions where num rows = 0
Table partitions with outdated statistics
Partitions with no column statistics
Partition columns with outdated statistics
Copyright 2013, Oracle and/or its affiliates. 26
Table Health Checks
Derived statistics in Tables or Partitions
Table has locked statistics
Copyright 2013, Oracle and/or its affiliates. 27
Index Health Checks
No statistics
More rows in index than its table
Clustering factor > rows in table
Statistics on zero while columns have value
Table/Index statistics out of sync

Copyright 2013, Oracle and/or its affiliates. 28
Index Health Checks
NDV on column > num_rows in single-column index
NDV is zero but column has values in single-column index
No column statistics in single-column index
ANALYZE was used

Copyright 2013, Oracle and/or its affiliates. 29
Index Health Checks
NDV <> NDK in single-column index
Index partitions with no statistics
Index partitions where num rows = 0
Index partitions with outdated statistics
Derived statistics in Index or Partitions
Copyright 2013, Oracle and/or its affiliates. 30
Index Health Checks
Indexes with UNUSABLE segments
INVISIBLE Indexes
Index in a Plan with UNUSABLE segments
Index in a Plan is now INVISIBLE
Copyright 2013, Oracle and/or its affiliates. 31
What is the output?
Health-Checks
Diagnostics
Execution Plans
SQL Detail Report
SQL Monitor Report(s)
Event 10053 Trace from Cursor
SQL Dynamic eXtractor (SQLDX)
Copyright 2013, Oracle and/or its affiliates. 32
Health-Checks section
Identification
Observations (Health-Checks results)
SQL Text
Tables Summary
Indexes Summary
Copyright 2013, Oracle and/or its affiliates. 33
Observations section
Global then Table then Index
All observations include a verbose explanation
Some observations have pointers to pertinent MOS documents
Some are more relevant than others for your particular SQL
Test any change before implementing in Production
Copyright 2013, Oracle and/or its affiliates. 34
Tables Summary
Content
Table level CBO statistics
Indexes and Columns counts
Columns with Histograms counts
Average sample sizes for Indexes and Columns
Purpose
Quick quantitative view of Tables statistics health
Ease a compare between two systems believed to be similar
Copyright 2013, Oracle and/or its affiliates. 35
Indexes Summary
Content
Index level CBO statistics
Indication if Index is referenced in an Execution Plan
Columns counts and columns with Histograms counts
Average sample sizes for Columns
Purpose
Quick quantitative view of Indexes statistics health
Ease a compare between two systems believed to be similar


Copyright 2013, Oracle and/or its affiliates. 36
Diagnostics output
Copyright 2013, Oracle and/or its affiliates. 37
Output sample
Copyright 2013, Oracle and/or its affiliates. 38
Output sample
Copyright 2013, Oracle and/or its affiliates. 39
Output sample
Copyright 2013, Oracle and/or its affiliates. 40
D E M O N S T R A T I O N
Copyright 2013, Oracle and/or its affiliates. 41
My Oracle Support Notes and Contact Info
1366133.1 SQL Tuning Health-Check Script (SQLHC)
215187.1 SQLTXPLAIN (SQLT) Tool Download
MOS (Metalink) Notes
carlos.sierra@oracle.com
http://carlos-sierra.net
@csierra_usa
Copyright 2013, Oracle and/or its affiliates. 42

You might also like