SQL Gone Wild: Taming Bad SQL the Easy Way (or the Hard Way) Sergey Koltakov Product Manager, Database Manageability

Similar documents
Demystifying SQL Tuning: Tips and Techniques for SQL Experts

<Insert Picture Here> DBA Best Practices: A Primer on Managing Oracle Databases

Copyright 2018, Oracle and/or its affiliates. All rights reserved.

OpenWorld 2018 SQL Tuning Tips for Cloud Administrators

Using Automatic Workload Repository for Database Tuning: Tips for Expert DBAs. Kurt Engeleiter Product Manager

<Insert Picture Here> Managing Oracle Exadata Database Machine with Oracle Enterprise Manager 11g

SQL Tuning for Expert DBAs

<Insert Picture Here> DBA s New Best Friend: Advanced SQL Tuning Features of Oracle Database 11g

Session id: The Self-Managing Database: Guided Application and SQL Tuning

What is Real Application Testing?

Oracle Database 11g: SQL Tuning Workshop

Oralogic Education Systems

EZY Intellect Pte. Ltd., #1 Changi North Street 1, Singapore

Moving Databases to Oracle Cloud: Performance Best Practices

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Oracle Database 12c: Performance Management and Tuning

Database Performance Analysis Techniques Using Metric Extensions and SPA

Oracle Database 10g The Self-Managing Database

Configuration changes such as conversion from a single instance to RAC, ASM, etc.

<Insert Picture Here> Oracle Database 11g: Neue Features im Oracle Optimizer

Trouble-free Upgrade to Oracle Database 12c with Real Application Testing

Oracle Database 11g: Real Application Testing & Manageability Overview

Oracle 1Z Oracle Database 11g Release 2- SQL Tuning. Download Full Version :

Manage Change With Confidence: Upgrading to Oracle Database 11g with Oracle Real Application Testing

Learning Objectives : This chapter provides an introduction to performance tuning scenarios and its tools.

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

Managing Oracle Database 12c with Oracle Enterprise Manager 12c

Session 1079: Using Real Application Testing to Successfully Migrate to Exadata - Best Practices and Customer Case Studies

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

End-to-end Management with Grid Control. John Abrahams Technology Sales Consultant Oracle Nederland B.V.

Oracle Diagnostics Pack For Oracle Database

<Insert Picture Here> Inside the Oracle Database 11g Optimizer Removing the black magic

Top 7 Plan Stability Pitfalls & How to Avoid Them. Neil Chandler Chandler Systems Ltd UK

Oracle Performance Tuning. Overview of performance tuning strategies

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Oracle Database 18c and Autonomous Database

In the Oracle Database 12c: Performance Management and

Worry Free Application Upgrades

Oracle 1Z0-515 Exam Questions & Answers

Oracle 1Z0-054 Exam Questions and Answers (PDF) Oracle 1Z0-054 Exam Questions 1Z0-054 BrainDumps

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Oracle Database 11g : Performance Tuning DBA Release2

Oracle Database 12c Performance Management and Tuning

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

Oracle Database 11g: Performance Tuning DBA Release 2

Oracle SQL Tuning for Developers Workshop Student Guide - Volume I

<Insert Picture Here> Maximizing Database Performance: Performance Tuning with DB Time

Oracle Database 11g: Performance Tuning DBA Release 2

<Insert Picture Here> Forms Strategies: Modernizing Your Oracle Forms Investment

Oracle EXAM - 1Z Oracle Database 11g: Performance Tuning. Buy Full Product.

Oracle and.net: Best Practices for Performance. Christian Shay & Alex Keh Product Managers Oracle October 28, 2015

RAC Performance Monitoring and Diagnosis using Oracle Enterprise Manager. Kai Yu Senior System Engineer Dell Oracle Solutions Engineering

Oracle Enterprise Manager 12c IBM DB2 Database Plug-in

Consolidate and Prepare for Cloud Efficiencies Oracle Database 12c Oracle Multitenant Option

1 Dulcian, Inc., 2001 All rights reserved. Oracle9i Data Warehouse Review. Agenda

PERFORMANCE TUNING TRAINING IN BANGALORE

Oracle WebCenter Portal Performance Tuning

Tuning slow queries after an upgrade

Oracle Database 11g: Manageability Overview. An Oracle White Paper August 2007

Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Data Warehousing 11g Essentials

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

Safe Harbor Statement

Copyright 2018, Oracle and/or its affiliates. All rights reserved.

Oracle Autonomous Database

Oracle 11g New Features

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. reserved. Insert Information Protection Policy Classification from Slide 8

Advanced Oracle SQL Tuning v3.0 by Tanel Poder

Best Practices for Performance Part 2.NET and Oracle Database

Oracle Database 12c: SQL Tuning for Developers

Architettura Database Oracle

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

1Z Oracle Database Performance and Tuning Essentials 2015 Exam Summary Syllabus Questions

Oracle Database 11g: SQL Tuning Workshop. Student Guide

Best Practices for Performance

ORACLE WHITEPAPER ORACLE ENTERPRISE MANAGER 13C CLOUD CONTROL

An Oracle White Paper June Managing Oracle Exadata with Oracle Enterprise Manager 12c

Exploring Best Practices and Guidelines for Tuning SQL Statements

Oracle Application Express fast = true

Oracle 11g Partitioning new features and ILM

Oracle Database 11g: Real Application Testing & Manageability Overview. An Oracle White Paper June 2007

Oracle Enterprise Manager 12c Sybase ASE Database Plug-in

<Insert Picture Here> What's New for.net Developers for Oracle Database

Exadata Implementation Strategy

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Storage Monitoring Made Easy for DBAs: Diagnosing Performance Problems. Senior Product Manager Consulting Member of Technical Staff

Oracle 11g Optimizer Statistics Inderpal S. Johal. Inderpal S. Johal, Data Softech Inc.

Enterprise Manager: Scalable Oracle Management

Oracle Database 11gR2 Optimizer Insights

Automating Information Lifecycle Management with

Quo Vadis SQLTXPLAIN

Optimize Your Databases Using Foglight for Oracle s Performance Investigator

Oracle Database 11g: New Features for Administrators Release 2

(10393) Database Performance Tuning Hands-On Lab

Tuna Helper Proven Process for SQL Tuning. Dean Richards Senior DBA, Confio Software

How to Troubleshoot Databases and Exadata Using Oracle Log Analytics

Real-World Performance Training Core Database Performance

Taming Banner 7 on Oracle 10g

Gather Schema Statistics Oracle 10g Examples

SQL Plan Management. on 12c Kerry Osborne OakTable World, 2013

Transcription:

SQL Gone Wild: Taming Bad SQL the Easy Way (or the Hard Way) Sergey Koltakov Product Manager, Database Manageability

Oracle Enterprise Manager Top-Down, Integrated Application Management Complete, Open, Integrated Management for Oracle Technologies Deep, Optimized, Best of Breed Database, Middleware, Packaged Applications, Physical and Virtual Infrastructure Business Centric, Top Down Application Management Complete Lifecycle Management Scalable Grid and Cloud Management Manage many as one

Complete, Open and Integrated Management Event Connectors Microsoft, HP, IBM Service Desk Connectors Remedy, HP, Siebel, PeopleSoft Plug-Ins Complete, Best of Breed Management for Oracle Rich Set of Plug-Ins to Monitor Non-Oracle Products Bi-Directional Connectors to Exchange Alerts, Events

Agenda What makes SQL go bad? What should you do about these problems? Identifying Fixing Preventing

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data 2. Missing access structures 3. Poorly written SQL statements 4. Cursor sharing issues a. Bind-sensitive SQL with bind peeking b. Literal usage 5. Resource and contention issues a. Hardware resource crunch b. Contention (row lock contention, block update contention) 6. Parallelism issues a. Not parallelized (no scaling to large data) b. Improperly parallelized (partially parallelized, skews)

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data

Oracle Optimizer Statistics Inaccurate statistics Suboptimal Plans Optimizer Statistics Table Statistics CBO Column Statistics Index Statistics System Statistics

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data 2. Missing access structures

What makes SQL go bad? Missing Access Structures 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, REF partitioning, Virtual Column Based partitioning B-tree index

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data 2. Missing access structures 3. Poorly written SQL statements

What makes SQL go bad? Poorly Written SQL Statements SELECT * FROM employees WHERE to_char(salary) = :sal SELECT * FROM employees WHERE salary = TO_NUMBER(:sal) Convert literal once and not the whole column, index range scan vs. full table scan SELECT * FROM parts_old UNION SELECT * FROM parts_new SELECT * FROM parts_old UNION ALL SELECT * FROM parts_new If you know there are no rows in common

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data 2. Missing access structures 3. Poorly written SQL statements 4. Cursor sharing issues a. Literal usage b. Bind-sensitive SQL with bind peeking

What makes SQL go bad? a. Literal Usage Issue SELECT * FROM jobs WHERE min_salary > 12000; SELECT * FROM jobs WHERE min_salary > 15000; SELECT * FROM jobs WHERE min_salary > 10000; SELECT * FROM SELECT * FROM SELECT * FROM cursor_sharing ={exact, force, similar} Sharing Cursors is good! Library Cache

What makes SQL go bad? b. Bind Peeking Issue Processed_Flag Y Y Y Y CBO 10g FTS Full Table Scan 99 Two different optimal plans for different bind values Index Range Scan 1 N Problem: Binds will affect optimality in any subsequent uses of the stored plan IRS

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data 2. Missing access structures 3. Poorly written SQL statements 4. Cursor sharing issues a. Bind-sensitive SQL with bind peeking b. Literal usage 5. Resource and contention issues a. Hardware resource crunch b. Contention (row lock contention, block update contention)

What makes SQL go bad? Resource and Contention Issues Hardware Resource Contention CPU Memory I/O Network Logical Contention Row lock contention Block update contention

What makes SQL go bad? Root Causes of Poor SQL Performance 1. Optimizer statistics issues a. Stale/Missing statistics b. Incomplete statistics c. Improper optimizer configuration d. Upgraded database: new optimizer e. Changing statistics f. Rapidly changing data 2. Missing access structures 3. Poorly written SQL statements 4. Cursor sharing issues a. Bind-sensitive SQL with bind peeking b. Literal usage 5. Resource and contention Issues a. Hardware resource crunch b. Contention (row lock contention, block update contention) 6. Parallelism issues a. Not parallelized (no scaling to large data) b. Improperly parallelized (partially parallelized, skews)

What makes SQL go bad? Parallelism Issues Not parallelized (no scaling to large data) Improperly parallelized (partially parallelized, skews) CTAS Large Table Select Insert Serial Table Scan Parallel Servers Serial Insert

Agenda What makes SQL go bad? How should you go about solving these problems? Identifying: Top Activity ADDM SQL Monitoring

Identify High Load SQL Using Top Activity Performance Page Top Activity Identify Top SQL by DB Time: CPU I/O Non-idle waits Different Levels of Analysis Historical analysis AWR data Performance Page Real-time analysis ASH data More granular analysis Enables identification of transient problem SQL Top Activity Page

Identifying Problems with Top SQL Page Problems Stale/Missing statistics Overly general statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Changing data (plans do not scale with data) Not parallelized (no scaling to large data) Improperly parallelized (partially parallel, skews) Missing access structures Poorly written SQL statements Hardware resource crunch Symptom High Load SQL Contention (row lock contention) Bind-sensitive SQL with bind peeking Literal usage

Identify performance problems using ADDM Automatic Database Diagnostic Monitor 11g Provides database and cluster-wide performance diagnostic Throughput centric - Focus on reducing time DB time Identifies top SQL: Shows SQL impact Frequency of occurrence Pinpoints root cause: SQL stmts waiting for Row Lock waits SQL stmts not shared

Identifying and Solving Problems With ADDM Problems Stale/Missing statistics Incomplete statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Rapidly Changing data Not parallelized (no scaling to large data) Improperly parallelized (skews, RAC, etc) Missing access structures Poorly written SQL statements Hardware resource crunch Contention (row lock contention) Bind-sensitive SQL with bind peeking Symptoms & Solutions ADDM (Add CPU recommendation) ADDM (Blocking Sessions recommendation) ADDM (Cursor Sharing recommendation) Literal usage

Real-time SQL Monitoring Problem: Managing High Response-Time SQLs Shows what is happening inside SQL execution Automatically monitors long running SQL > 5 secs of CPU or I/O All parallel statements Enabled out-of-the-box with no performance impact Monitors each SQL execution Exposes monitoring statistics Global execution level Plan operation level Parallel Execution level Guides tuning efforts

SQL Monitoring Use Cases Big Plans

SQL Monitoring Use Cases Expensive Hash Join

SQL Monitoring Use Cases Poor Indexing

SQL Monitoring Use Cases FORCE PARALLEL QUERY PARALLEL 4

SQL Monitoring Enhancements in Oracle Database 11gR2 New save Active Reports for later analysis track PL/SQL cursors track recursive SQL statements executed by the monitored statement SQL monitoring information persists after the SQL cursor is aged out track specific Exadata statistics: cell offload efficiency interconnect bytes exchanged capture error code and error message, if SQL statement fails track when and how long parallel SQL is queued capture binds values used by the monitored SQL execution track detailed session information: user, module, actions, service name, client id and info

Identifying Problems With SQL Monitoring Problems Stale/Missing statistics Incomplete statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Rapidly changing data Not parallelized (no scaling to large data) Improperly parallelized(partially parallel,skews) Missing access structures Poorly written SQL statements Hardware resource crunch Contention (row lock contention) Bind-sensitive SQL with bind peeking Literal usage Symptoms Serial Long Running SQL Parallel Skews Wrong Cardinalities, Poor Index Selectivity I/O, CPU, Memory, Network Waits TX enqueue waits, Row Lock Contention Significantly Different Runtimes with Different Binds

Agenda What makes SQL go bad? What should you do about these problems? Identifying: Top Activity ADDM SQL Monitoring Fixing: SQL Tuning Advisor + Automatic SQL Tuning SQL Access Advisor Optimizer Statistics

SQL Tuning Advisor Categories of Recommendations Automatic Tuning Optimizer Statistics Analysis SQL Profiling Access Path Analysis SQL Tuning Advisor SQL Tuning Recommendations Gather Missing or Stale Statistics Create a SQL Profile Add Missing Access Structures SQL Restructure Analysis Modify SQL Constructs DBA 11gR2 Alternative Plan Analysis Adopt Alternative Execution Plan 11gR2 11gR2 Parallel Execution Analysis Use Parallel Execution for SQL 11gR2

SQL Tuning Advisor Two New Categories of Recommendations 11gR2 Parallel Execution Analysis Alternative Plan Analysis

Automatic SQL Tuning Further automation of SQL Tuning Advisor Nightly Automatic implement Packaged Apps Custom Apps SQL Tuning Advisor SQL Profiles Well-tuned SQL Auto Capture High-Load SQL SQL Analysis Report Manually implement Automatically captures high-load SQL Automatically tunes SQL without changing application by creating SQL Profiles Automatically validates SQL Profiles by test executing them Automatically implements (optional) greatly improved SQL plans Automatically reports analysis Automatically runs during maintenance window

Fixing Problems With SQL Tuning Advisor Problems Stale/Missing statistics Incomplete statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Rapidly changing data Not parallelized (no scaling to large data) Improperly parallelized(partially parallel,skews) Missing access structures Poorly written SQL statements Hardware resource crunch Contention (row lock contention) Solutions Stats recommendation Profile recommendation Profile recommendation Profile recommendation using O_F_E Profile recommendation Profile recommendation PQ recommendation Index recommendation partially Restructure recommendation Bind-sensitive SQL with bind peeking Literal usage

SQL Access Advisor: Partition Advisor Indexes Representative Workload SQL Access Advisor Materialized views Automatic Tuning Optimizer Access Path Analysis Materialized views logs Partitioned objects 11g

Fixing Problems With SQL Access Advisor Problems Stale/Missing statistics Incomplete statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Rapidly changing data Not parallelized (no scaling to large data) Improperly parallelized (partially parallel,skews) Missing access structures Poorly written SQL statements Hardware resource crunch Solution SQL Access Advisor Contention (row lock contention) Bind-sensitive SQL with bind peeking Literal usage

Oracle Optimizer Statistics Preventing SQL Regressions Automatic Statistics Collection Job (stale or missing) Out-of-the box, runs in maintenance window Configuration can be changed (at table level) Gathers statistics on user and dictionary objects Uses new collection algorithm with accuracy of compute and speed faster than sampling of 10% Incrementally maintains statistics for partitioned tables very efficient Set DBMS_STATS.SET_GLOBAL_PREFS Nightly

Oracle Optimizer Statistics Preventing SQL Regressions: Tips Gather statistics for all objects User Objects Non-volatile Volatile Gathers statistics when object at MAX size and then lock table Delete all statistics and lock table dynamic sampling will be used Dictionary Tables Fixed Tables Restoring old optimizer statistics Used when new stats result in poor execution plan selection Scope: table, schema and database History maintained for 30 days API: DBMS_STATS.RESTORE_TABLE_STATS Best Practice: Use DBMS_STATS instead of the ANALYZE command Officially obsolete for optimizer statistics

Oracle Optimizer Statistics Preventing SQL Regressions Extended Statistics Extended Optimizer Statistics provides a mechanism to collect statistics on a group of related columns: Function-Based Statistics Multi-Column Statistics Full integration into existing statistics framework Automatically maintained with column statistics DBMS_STATS.CREATE_EXTENDED_STATS Pending Statistics Allows validation of statistics before publishing Disabled by default To enable, set table/schema PUBLISH setting to FALSE DBMS_STATS.SET_TABLE_PREFS('SH','CUSTOMERS','PUBLISH','false') To use for validation ALTER SESSION SET optimizer_pending_statistics = TRUE; Publish after successful verification

Fixing Problems With Good Statistics Problems Stale/Missing statistics Incomplete statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Rapidly changing data Solution Good Optimizer Statistics Not parallelized (no scaling to large data) Improperly parallelized(partially parallel,skews) Missing access structures Poorly written SQL statements Hardware resource crunch Contention (row lock contention) Bind-sensitive SQL with bind peeking Literal usage

Fixing problems with Adaptive Cursor Sharing Adaptive Cursor Sharing compromise between cursor sharing & optimization SELECT * FROM emp WHERE wage := wage_value Selectivity Ranges: 1 20 25 2 3 22 24 Same Plan Different Plan 4 30 35 34 43 Same Plan, Expand Interval

Fixing Problems With Adaptive Cursor Sharing Problems Stale/Missing statistics Overly general statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Changing data (plans do not scale with data) Not parallelized (no scaling to large data) Solution Adaptive Cursor Sharing Improperly parallelized (partially parallel,skews) Missing access structures Poorly written SQL statements Hardware resource crunch Contention (row lock contention) Bind-sensitive SQL with bind peeking Literal usage

Agenda What makes SQL go bad? What should you do about these problems? Identifying: Top Activity ADDM SQL Monitoring Fixing: SQL Tuning Advisor + Automatic SQL Tuning SQL Access Advisor Optimizer Statistics Preventing: SQL Plan Management SQL Performance Analyzer

Preventing problems with SQL Plan Management Problem: changes in the environment cause plans to change Parse GB NL Plan baseline is established NL SQL statement is parsed again and a different plan is generated New plan is not executed but marked for verification GB NL Statement log Plan history Plan baseline NL GB HJ HJ

SQL Performance Analyzer (SPA) Validate statistics refresh with SPA Steps: 1. Capture SQL workload in STS using automatic cursor cache capture capability 2. Execute SPA pre-change trial 3. Refresh statistics using PENDING option 4. Execute SPA post-change trial 5. Run SPA report comparing SQL execution statistics Before PUBLISHing stats: Remediate individual few SQL for plan regressions: SPM, STA Revert to old statistics if too many regressions observed Validating SQL Workload upgrade with SPA SQL plans + stats SQL plans + stats Pre-change Trial Post-change Trial Compare SQL Performance Analysis Report

Preventing Problems With SPA and SPM Problems Stale/Missing statistics Overly general statistics Improper optimizer configuration Upgraded database: new optimizer Changing statistics Changing data (plans do not scale with data) Not parallelized (no scaling to large data) Improperly parallelized(partially parallel,skews) Missing access structures Poorly written SQL statements Hardware resource crunch Contention (row lock contention) Preventive Solutions SPA + SQL Tune/SPM (on regressed plans) SPM (evolve old plans), SPA (test statistics) Bind-sensitive SQL with bind peeking Literal usage

Conclusion Identify, Resolve, Prevent Prevent SPA SPM Resolve ADDM, Top Activity, SQL Monitoring Identify Top Activity, ADDM, SQL Monitoring Tuning Advisor, Access Advisor, Auto Stat Collection

Oracle Helps You Maximize Customer Value Deploys SOA infrastructure 92% faster Saves 80% time and effort for managing Databases Avoids online revenue losses up to 25% Improves IT productivity by 25% Drives asset utilization up by 70% Cuts configuration management effort by 90% Saves $1.9 million with Oracle Enterprise Manager Saves $170,000 per year with Oracle Enterprise Manager Replaces manual tools with automation; saves time by 50% Reduces Database testing time by 90% Reduces provisioning effort by 75% Saves weeks on application testing time Cuts application testing from weeks to hours Reduces critical patching time by 80% Delivers 24/7 uptime with Oracle Enterprise Manager

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle s products remains at the sole discretion of Oracle.

For More Information search.oracle.com or oracle.com