Top Banner

of 79

Sqltune Presentation Ow07 130395

Apr 14, 2018

Download

Documents

Cesar Arriola
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/29/2019 Sqltune Presentation Ow07 130395

    1/79

  • 7/29/2019 Sqltune Presentation Ow07 130395

    2/79

  • 7/29/2019 Sqltune Presentation Ow07 130395

    3/79

    DBAs New Best Friend: Advanced SQL Tuning

    Features of Oracle Database 11g

    Peter Belknap, Sergey Koltakov, Jack Raitto

  • 7/29/2019 Sqltune Presentation Ow07 130395

    4/79

    The following is intended to outline our generalproduct direction. It is intended for information

    purposes only, and may not be incorporated into anycontract. It is not a commitment to deliver anymaterial, code, or functionality, and should not be

    relied upon in making purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracles

    products remains at the sole discretion of Oracle.

  • 7/29/2019 Sqltune Presentation Ow07 130395

    5/79

    Agenda

    SQL Tuning Challenges

    Oracle Database 11g Solutions

    Automatic SQL Tuning

    Real-time SQL Monitoring

    Partition Advisor

    Q & A

  • 7/29/2019 Sqltune Presentation Ow07 130395

    6/79

    SQL Tuning Challenges

    Oracle Database 10g introduced SQL advisors tosimplify application and SQL tuning

    Remaining challenges

    SQL Tuning still reactive

    Painful to find and investigate long-running SQL

    Partitioning excluded from schema optimization advice

    Oracle Database 11g solutions Automatic SQL Tuning

    Real-time SQL Monitoring

    Partition Advisor component of SQL Access Advisor

  • 7/29/2019 Sqltune Presentation Ow07 130395

    7/79

    The Self-Managing Database

    Automatic SQL Tuning

  • 7/29/2019 Sqltune Presentation Ow07 130395

    8/79

    Challenges of Manual SQL Tuning

    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

    Plans are complicated

    Each SQL statement is unique and each execution can be different

    Potentially large number of statements to tune

    Testing proposed changes is labor-intensive

    Many possible ways to a solution

    Never ending task SQL workload always evolving

    Plan regressions

  • 7/29/2019 Sqltune Presentation Ow07 130395

    9/79

    Simplifying SQL TuningSQL Tuning Advisor, since Oracle Database 10g

    Add Missing

    Indexes

    Modify SQL

    Constructs

    Create a SQL

    Profile

    Automatic Tuning Optimizer

    SQL StructureAnalysis

    Access PathAnalysis

    SQLProfiling

    StatisticsAnalysis Gather Missing orStale Statistics

    DBA

    SQL Tuning

    Recommendations

    SQL TuningAdvisor

  • 7/29/2019 Sqltune Presentation Ow07 130395

    10/79

    Improvements in Oracle Database 11gBetter SQL Profiling

    Add Missing Indexes

    Modify SQL Constructs

    Create a SQL

    Profile

    show verifiedbenefit

    Automatic Tuning Optimizer

    SQL StructureAnalysis

    Access Path

    Analysis

    SQLProfiling

    Statistics

    Analysis

    Gather Missing or Stale

    Statistics

    DBA

    SQL Tuning

    Recommendations

    SQL TuningAdvisor

    Fix potential regressionafter upgrade Verify benefit through

    test-execution

  • 7/29/2019 Sqltune Presentation Ow07 130395

    11/79

    Testing SQL Profiles (1)Measuring actual benefit with test-execution

    P1

    Nave: Execute in Order

    Finish, P2 wins!P2

    But what if P1 never completes?

    Timeout!P1

    But then I take 2 CPUs, and N in the general case

    It would be great to run them concurrently.

    P1

    P2 P2 wins, kill P1!

  • 7/29/2019 Sqltune Presentation Ow07 130395

    12/79

    Testing SQL Profiles (2)Measuring actual benefit with test-execution

    Solution: Tournament Execution

    P1 P2Round 1:

    15 sec 15 sec

    P1

    P2

    Round 2:

    30 sec 16 sec

    Your winner, with a knockout in the second round, P2!

  • 7/29/2019 Sqltune Presentation Ow07 130395

    13/79

    SQL Tuning in Oracle Database 10gEnd-to-end Workflow

    Workload

    SQL Tuning Candidates

    SQL TuningAdvisor

    ADDM

    AWR

    one hour

    Generate

    Recommendations

    DBA

    Invoke

    Advisor

    Implement

    DBA

    A good end-to-end solution,

    but manual intervention is required

    Evaluate

    Recommendations

    DBA

  • 7/29/2019 Sqltune Presentation Ow07 130395

    14/79

    Automatic SQL Tuning in Oracle 11gThe Self-Managing Database

    Its Automatic!

    Choose

    Candidate

    SQL

    oneweek

    Workload

    SQL Tuning

    Candidates

    Test SQL ProfilesImplement

    SQL Profiles

    Generate

    Recommendations

    AWRDBA

    View Reports /

    Control

    Process

  • 7/29/2019 Sqltune Presentation Ow07 130395

    15/79

    Picking Candidate SQL (1)

    S4, 1 minute

    Weeks Top SQL,Ordered by DB

    TimeS3, 5 minutes

    S2, 8 minutes

    S1, 10 minutes

    I could just pick from the top down

    AWR

    AWRAverage ExecHourlyDailyWeekly

    Lets try a more balanced approach:

    OK, but where do I start?

    But I will miss SQLs with important hotspots!

  • 7/29/2019 Sqltune Presentation Ow07 130395

    16/79

    Picking Candidate SQL (2)

    AWR

    Average ExecHourly

    y Eventually we need one list to tune from: merge the buckets.

    y All buckets are not created equal: focus on the week,

    but dont forget about the others.

    y Focus on the SQLs we have not seen recently:

    Dont re-tune SQLs if nothing has changed!

    Candidate List

    DailyWeekly

    65%20% 10%

    5%

  • 7/29/2019 Sqltune Presentation Ow07 130395

    17/79

    Tuning FlowTuning activities per SQL

    Candidate SQLs

    Test Profile

    Tournament competition

    Tune SQL

    Fix potential regressions

    Look for indexes, statistics,as with standard tuning

    Fetch next SQL Store findings, exec stats

    Accept Profile

    Require 3X benefit inCPU and IO time

    Still recommend if < 3X

  • 7/29/2019 Sqltune Presentation Ow07 130395

    18/79

    Focus on SQL ProfilesFirst step in automating SQL tuning

    Auto-testing/implementing is limited to profiles because:

    No lengthy, expensive set-up process

    (building an index takes time) Private to the current compilation

    No change to user SQL (does not change semantics)

    SQL-level recommendation, can be effectively tested Easily reversed by the DBA

    Testing is done for regular SQL Tuning Advisor tasks as well!

  • 7/29/2019 Sqltune Presentation Ow07 130395

    19/79

    Automatic SQL Tuning DefaultsSensible defaults with flexible configurations

    Out-of-the-box defaults:

    Runs in each maintenance window(MAINTENANCE_WINDOW_GROUP)

    SQL profiles are tested but not implemented

    DBA can configure using EM:

    Whether / When / How long it runs

    Resources it uses

    Whether it implements profiles

    How many profiles it implements

  • 7/29/2019 Sqltune Presentation Ow07 130395

    20/79

    Automatic SQL Tuning Task

  • 7/29/2019 Sqltune Presentation Ow07 130395

    21/79

    Automatic SQL Tuning Configuration

  • 7/29/2019 Sqltune Presentation Ow07 130395

    22/79

    Automatic SQL Tuning Result Summary

  • 7/29/2019 Sqltune Presentation Ow07 130395

    23/79

    Automatic SQL Tuning Result

    Recommendations

  • 7/29/2019 Sqltune Presentation Ow07 130395

    24/79

    Automatically Tuned SQL Details Drilldown

  • 7/29/2019 Sqltune Presentation Ow07 130395

    25/79

    Conclusions

    Manual SQL tuningis painful even for the experts

    Oracle 10g SQL Tuning Advisorquickly gives DBA goodchoices

    Oracle 11g Automatic SQL Tuningautomates the processby making the easy decisions

    DBA can controlas much of the process as he wants

  • 7/29/2019 Sqltune Presentation Ow07 130395

    26/79

    Just when you thought it was safe to

    run your SQLs

    SingleSQL

    Execution

    Theres a lot more to SQL performance than bad plans!

    Potential run-time issues

    Finding high response-time SQL is no piece of cake

    Keeping tabs on Parallel SQL is even harder

  • 7/29/2019 Sqltune Presentation Ow07 130395

    27/79

    Shining new lighton SQL Performance

    Real-Time SQL Monitoring

  • 7/29/2019 Sqltune Presentation Ow07 130395

    28/79

    Problem:

    Managing High Response-Time SQLs

    Monitoring: tracking high response-time SQL

    What is that expensive SQL (ETL, DDL, batch, report, ) I started up to?

    Do I have any high response-time SQL running on my

    OLTP system?

    Any SQL executing parallel?

    Investigating: why is this execution so expensive? Plan has hundreds of operations -- where is the time being spent?

    Why is a particular operation so expensive?

    SQL runs parallel, is DOP appropriate? is there a skew?

    What is going on inside a SQL execution???

    SingleSQL

    Execution

    S l ti

  • 7/29/2019 Sqltune Presentation Ow07 130395

    29/79

    Enabled out-of-the-box with no performance impact

    Automatically monitors SQL executions that:

    consume more than 5 seconds of CPU or I/O time

    are running parallel: PQ, PDML, PDDL

    Monitors each execution independently

    Exposes monitoring statistics atmultiple levels

    Global execution level

    Plan operation level (Plan Tuning)

    Parallel Execution level (PX Tuning)

    Guides your tuning efforts

    Solution:

    Real-time SQL Monitoring

    Looking inside the SQL

    SingleSQL

    Execution

  • 7/29/2019 Sqltune Presentation Ow07 130395

    30/79

    How does it work?

    Exposes monitoring statistics in: V$SQL_MONITOR Cumulative DB time breakdown (CPU, IO, Application, etc)

    PL/SQL, Java Exec Times

    V$SQL_PLAN_MONITOR #rows, #executions, memory, temp space per plan operation

    Plan operation begin and end times

    V$ACTIVE_SESSION_HISTORY (ASH)

    Each execution of each SQL identifiable in ASHexecution key: (SQL_ID, SQL_EXEC_START, SQL_EXEC_ID)

    Parallel Execution Servers share an execution key with QC, but use aseparate Session ID

    Separate entries for each Parallel Execution Server

    Refreshes statistics every second, during query execution

    Statistics available for at least 5 minutes, even with cursor age-outs

  • 7/29/2019 Sqltune Presentation Ow07 130395

    31/79

    How do I use it?

    11g Enterprise Manager Grid Control

    Additional reporting (available today):

    DBMS_SQLTUNE.REPORT_SQL_MONITOR

  • 7/29/2019 Sqltune Presentation Ow07 130395

    32/79

    Enterprise Manager Flow (1)

    Top Activity

    SQL Details

    Session Details

    Monitoring Details

  • 7/29/2019 Sqltune Presentation Ow07 130395

    33/79

    Enterprise Manager Flow (2)

    Monitoring List Monitoring Details

  • 7/29/2019 Sqltune Presentation Ow07 130395

    34/79

    SQL Monitoring List

  • 7/29/2019 Sqltune Presentation Ow07 130395

    35/79

    SQL Monitoring Details

  • 7/29/2019 Sqltune Presentation Ow07 130395

    36/79

    SQL Monitoring Details (Parallelism)

  • 7/29/2019 Sqltune Presentation Ow07 130395

    37/79

    Conclusion

    Real-Time SQL Monitoring is

    Monitoring and tuning for high response-time SQLs

    New, fine-grained SQL statistics tracked automatically

    updated while the SQL runs

    highly visible and accessible

    at no cost to your production system

    The only way to know whats happening inside single SQLexecution

    The quickest way to the root cause of a performance problem:If you can find the problem, you can fix it!

  • 7/29/2019 Sqltune Presentation Ow07 130395

    38/79

    Partition Advisor

  • 7/29/2019 Sqltune Presentation Ow07 130395

    39/79

    Problem

    SQLs on large tables run too long or timeout

    High I/O counts

    Too much pressure on buffer pool

    Disgruntled users

    Low transaction rates Too many complex SQLs to figure out on my own

    Put out a fire here, another starts over there

  • 7/29/2019 Sqltune Presentation Ow07 130395

    40/79

    Solution

    Get new 11g partition advice along withother advice from the new 11g SQL

    Access Advisor Recommendations targeted at partition

    elimination in query processing

    Recommendations to aid certain joinprocessing

  • 7/29/2019 Sqltune Presentation Ow07 130395

    41/79

    Interval Partitioning

    CREATE TABLE emp(empno NUMBER(6),

    first_name VARCHAR(20),last_name VARCHAR(20),deptno NUMBER(6))

    PARTITION BY RANGE (deptno) INTERVAL 100

    PARTITION p1 VALUES LESS THAN 100

    < 100 < 200 < 300 < 400 < 500 < 600

  • 7/29/2019 Sqltune Presentation Ow07 130395

    42/79

    Interval Partitioning

    CREATE TABLE emp(empno NUMBER(6),

    first_name VARCHAR(20),last_name VARCHAR(20),deptno NUMBER(6))

    PARTITION BY RANGE (deptno) INTERVAL 100

    PARTITION p1 VALUES LESS THAN 100

    < 100 < 200 < 300 < 400 < 500 < 600

    Interval partition is a new, automated

    form of range partitioning.

  • 7/29/2019 Sqltune Presentation Ow07 130395

    43/79

    Partition Elimination

    SELECT empno, last_name, first_nameFROM empWHERE deptno = 123

    CREATE TABLE emp(empno NUMBER(6),

    first_name VARCHAR(20),last_name VARCHAR(20),deptno NUMBER(6))

    PARTITION BY RANGE (deptno) INTERVAL 100

    PARTITION p1 VALUES LESS THAN 100

    < 100 < 200 < 300 < 400 < 500 < 600

  • 7/29/2019 Sqltune Presentation Ow07 130395

    44/79

    Partition Elimination

    SELECT empno, last_name, first_name

    FROM empWHERE deptno = 123

    CREATE TABLE emp(empno NUMBER(6),

    first_name VARCHAR(20),last_name VARCHAR(20),deptno NUMBER(6))

    PARTITION BY RANGE (deptno) INTERVAL 100

    PARTITION p1 VALUES LESS THAN 100

    < 100 < 200 < 300 < 400 < 500 < 600

  • 7/29/2019 Sqltune Presentation Ow07 130395

    45/79

    Partition-wise Join

    Lineitem Orders Lineitem Orders

    Sub-1

    Sub-2

    Sub-3

    05-Apr

    Sub-1

    Sub-2

    Sub-3

    Sub-1

    Sub-2

    Sub-3

    05-Apr

    Sub-1

    Sub-2

    Sub-3

    Node 2

    Node 1

    Node 3

    When joining two tables that are partitioned on the join-

    key, Oracle may choose to join on a per-partition basis.

  • 7/29/2019 Sqltune Presentation Ow07 130395

    46/79

    How does SAA work?Standard

    STSWorkload

    SQL Access Advisorw/new Partition Advice

    Recommendations:partitionindexmv

    New

    SQL cache,user defined,

    etc.Analyzes accesspatterns, column

    usage, etc.

    Determines best partitioningstrategy for the entire

    workload in concert withbest index and materializedview solutions

  • 7/29/2019 Sqltune Presentation Ow07 130395

    47/79

    How does SAA work?Workload

    Table+IndexPartitionAnalysis

    Expensive Qson BIG tables Rank Qs

    Partitionannotatedworkload

    IndexAnalysis

    MVAnalysis

    Recommendationsfeedback output

    MV PartitionAnalysis

  • 7/29/2019 Sqltune Presentation Ow07 130395

    48/79

    How does SAA work?Workload

    Table+IndexPartitionAnalysis

    Expensive Qson BIG tables Rank Qs

    Partitionannotatedworkload

    IndexAnalysis

    MVAnalysis

    Recommendationsfeedback output

    MV PartitionAnalysis

  • 7/29/2019 Sqltune Presentation Ow07 130395

    49/79

    Partition Advisor Problem Space

    Fact: If I partition table T1, all Qs referencing T1 areaffected (+ or -)

    Fact: If I also partition table T2, the same applies

    Fact: Lots of Qs reference multiple tables forming anetwork of inter-relationships

    Therefore: A potential partitioning scheme on eachdifferent table affects each potential partitioningscheme on other tables in that network

  • 7/29/2019 Sqltune Presentation Ow07 130395

    50/79

    Partition Advisor

    Enumeration

    Pruning

    Heuristics

    Evaluation

    P titi Ad i

  • 7/29/2019 Sqltune Presentation Ow07 130395

    51/79

    Partition Advisor

    Enumeration

    Pruning

    Heuristics

    Evaluation

    P titi Ad i

  • 7/29/2019 Sqltune Presentation Ow07 130395

    52/79

    Partition Advisor

    Enumeration

    Pruning

    Heuristics

    Evaluation

    P titi Ad i

  • 7/29/2019 Sqltune Presentation Ow07 130395

    53/79

    Partition Advisor

    Enumeration

    Pruning

    Heuristics

    Evaluation

    P titi Ad i

  • 7/29/2019 Sqltune Presentation Ow07 130395

    54/79

    Partition Advisor

    Enumeration

    Pruning

    Heuristics

    Evaluation

    Partition Annotations

    H d SAA k?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    55/79

    How does SAA work?Workload

    Table+IndexPartitionAnalysis

    Expensive Qson BIG tables Rank Qs

    Partitionannotatedworkload

    IndexAnalysis

    MVAnalysis

    Recommendationsfeedback output

    MV PartitionAnalysis

    H d SAA k?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    56/79

    How does SAA work?Workload

    Table+IndexPartitionAnalysis

    Expensive Qson BIG tables Rank Qs

    Partitionannotatedworkload

    IndexAnalysis

    MVAnalysis

    Recommendationsfeedback output

    MV PartitionAnalysis

    MV & I d Ad i I d A l i

  • 7/29/2019 Sqltune Presentation Ow07 130395

    57/79

    MV & Index AdvisorMV Analysis:

    joinsgroup bysdimensions

    Index Analysis:predicatesgroup bys

    joinsindex-only accessbitmap access

    MV candidates Index candidates

    Optimizer / Query RewriteMV Partition

    Advisor

    Associated groupsof access candidates

    Global access optimization

    Evaluate

    Recommendations

    Wh t d SAA d ?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    58/79

    What does SAA do?

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    59/79

    What does SAA do?

    Recommends:

    Partitioning

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    60/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    61/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    62/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    What does SAA do?

    Supported

  • 7/29/2019 Sqltune Presentation Ow07 130395

    63/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    SupportedPartitioning Types:

    Interval

    Hash

    What does SAA do?

    Supported

  • 7/29/2019 Sqltune Presentation Ow07 130395

    64/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    SupportedPartitioning Types:

    Interval

    Hash

    Supported PartitionKey Types:

    Date

    Number

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    65/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    Creating

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    66/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    Creating Materialized Views

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    67/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    Creating Materialized Views

    Indexes

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    68/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    Creating Materialized Views

    Indexes

    MV Logs

    What does SAA do?

  • 7/29/2019 Sqltune Presentation Ow07 130395

    69/79

    What does SAA do?

    Recommends:

    Partitioning Tables

    Materialized Views

    Indexes

    Creating Materialized Views

    Indexes

    MV Logs

    Holistic Advice

    Choosing Partition Advice

  • 7/29/2019 Sqltune Presentation Ow07 130395

    70/79

    Choosing Partition Advice

    New

    Recommendation summary

  • 7/29/2019 Sqltune Presentation Ow07 130395

    71/79

    Recommendation summary

    New

    Partition recommendations

  • 7/29/2019 Sqltune Presentation Ow07 130395

    72/79

    Partition recommendations

    New

    Partition Recommendation

  • 7/29/2019 Sqltune Presentation Ow07 130395

    73/79

    Partition Recommendation

    Conclusions

  • 7/29/2019 Sqltune Presentation Ow07 130395

    74/79

    Conclusions

    SAA now covers your data access problems with all possibleaccess solutions

    New for 11g:

    Partition advice, including hash and new interval on date andnumber

    Incremental advice

    Partition recommendations are holistically generated,

    simultaneously considering all possible access solutions acrossan entire SQL workload

    SAA is easy to use as ever partition advice is yours for click

    of a checkbox!

  • 7/29/2019 Sqltune Presentation Ow07 130395

    75/79

  • 7/29/2019 Sqltune Presentation Ow07 130395

    76/79

    Navigating to SQL Access Advisor

  • 7/29/2019 Sqltune Presentation Ow07 130395

    77/79

    g g Q

    EM Home Page

    Advisor Central Page

    SQL Advisor Page

    Using SQL Access Advisor

  • 7/29/2019 Sqltune Presentation Ow07 130395

    78/79

    Using SQL Access Advisor

    Choose initial options

    Select a workload

    Running advisor job

  • 7/29/2019 Sqltune Presentation Ow07 130395

    79/79

    g j

    Select job options Review & submit

    Review results