Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

Embed Size (px)

Citation preview

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    1/42

    Copyright 2013, Oracle and/or its affiliates.1

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    2/42

    Copyright 2013, Oracle and/or its affiliates.2

    Diagnosing SQL Performanceusing SQL Health-Check

    (SQLHC)

    Carlos SierraConsulting Technical Advisor

    Center of Expertise (CoE)

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    3/42

    Copyright 2013, Oracle and/or its affiliates.3

    Carlos Sierra

    SQL Tuner handyman: developer, advisor, trainer, sup

    IT: Oracle(17), UNISYS(12), Ford(3), others(3)

    Florida(17), Venezuela(3), Puerto Rico(6), Michigan(1),

    Tools: SQLTXPLAIN(SQLT), SQLHC, TRCANLZR(TRC

    Motto: Life is good!

    Oracle Server Technologies(ST) Center of Expertise(CoE)

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    4/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    5/42Copyright 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 objec

    Centric to one SQL statement per use

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    6/42Copyright 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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    7/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    8/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    9/42

    Copyright 2013, Oracle and/or its affiliates.9

    When should I use the SQL HC Tool?

    When a quick sanity check of the environment aroun

    SQL is needed On a poorly performing SQL

    As per AWR or StatsPack reports

    On any SQL statement

    Out of a Trace or TKPROF

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    10/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    11/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    12/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    13/42

    Copyright 2013, Oracle and/or its affiliates.13

    Health Checks performed

    Levels

    Global Table

    Index

    Purpose

    Highlight SQL Tuning opportunities

    Highlight concerns

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    14/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    15/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    16/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    17/42

    Copyright 2013, Oracle and/or its affiliates.17

    Global Health Checks

    mreadtim < sreadtim

    sreadtim < 2 mreadtim < 3

    sreadtim > 18

    mreadtim > 522

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    18/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    19/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    20/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    21/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    22/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    23/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    24/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    25/42

    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

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    26/42

    Copyright 2013, Oracle and/or its affiliates.26

    Table Health Checks

    Derived statistics in Tables or Partitions

    Table has locked statistics

    I d H lth Ch k

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    27/42

    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

    I d H lth Ch k

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    28/42

    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 inde No column statistics in single-column index

    ANALYZE was used

    I d H lth Ch k

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    29/42

    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

    I d H lth Ch k

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    30/42

    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

    Wh t i th t t?

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    31/42

    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)

    Health Checks section

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    32/42

    Copyright 2013, Oracle and/or its affiliates.32

    Health-Checks section

    Identification

    Observations (Health-Checks results) SQL Text

    Tables Summary

    Indexes Summary

    Observations section

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    33/42

    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 docu

    Some are more relevant than others for your particula

    Test any change before implementing in Production

    Tables Summary

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    34/42

    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 simila

    Indexes Summary

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    35/42

    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 simila

    Diagnostics output

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    36/42

    Copyright 2013, Oracle and/or its affiliates.36

    Diagnostics output

    Output sample

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    37/42

    Copyright 2013, Oracle and/or its affiliates.37

    Output sample

    Output sample

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    38/42

    Copyright 2013, Oracle and/or its affiliates.38

    Output sample

    Output sample

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    39/42

    Copyright 2013, Oracle and/or its affiliates.39

    Output sample

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    40/42

    Copyright 2013, Oracle and/or its affiliates.40

    D E M O N S T R A T I O

    My Oracle Support Notes and Contact

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    41/42

    Copyright 2013, Oracle and/or its affiliates.41

    My Oracle Support Notes and Contact

    1366133.1SQL Tuning Health-Check Script (SQLHC) 215187.1SQLTXPLAIN (SQLT) Tool Download

    MOS (Metalink) Notes

    carlos.sierra@ora

    http://carlos-sierra @csierra_usa

  • 8/11/2019 Diagnosing SQL Performance Using SQL Health-Check (SQLHC)

    42/42

    Copyright 2013, Oracle and/or its affiliates.42