Using Stored Outlines & Profiles Chris Lawson. TIP 1: EASY SQL HINTS USING STORED OUTLINES No reason to avoid outlines. Despite threats, are reportedly.

Slides:



Advertisements
Similar presentations
Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Advertisements

Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Introduction to SQL Tuning Brown Bag Three essential concepts.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Oracle 11g Real Application Testing: Avoiding Performance Regressions with SQL Performance Analyzer Khaled Yagoub, Pete Belknap, Benoit Dageville, Karl.
Today’s Agenda Chapter 12 Admin Tasks Chapter 13 Automating Admin Tasks.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
Database Advisors Automatic Database Diagnostic Monitor ( ADDM )
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
1 Robert Wijnbelt Health Check your Database A Performance Tuning Methodology.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Oracle9i Performance Tuning Chapter 12 Tuning Tools.
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
Views Lesson 7.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
M1G Introduction to Database Development 5. Doing more with queries.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Handling Exceptions. 2 home back first prev next last What Will I Learn? Describe several advantages of including exception handling code in PL/SQL Describe.
Module 4 Database SQL Tuning Section 3 Application Performance.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
J.NemecAre Your Statistics Bad Enough?1 Verify the effectiveness of gathering optimizer statistics Jaromir D.B. Nemec UKOUG
Analysing Indexes SQLBits 6 th October 2007 © Colin Leversuch-Roberts Kelem Consulting Limited September 2007.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Sofia, Bulgaria | 9-10 October SQL Server Profiler Richard Campbell.
Sorting and Joining.
1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
Why Should I Care About … The Plan Cache? Tuning When Stakeholders Won’t Say Where It Hurts.
13 Copyright © 2004, Oracle. All rights reserved. Migrating SQL Statements.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Session Name Pelin ATICI SQL Premier Field Engineer.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
3 A Guide to MySQL.
SQL Server Statistics and its relationship with Query Optimizer
Data Virtualization Tutorial: Custom Functions
Query Optimization Techniques
SQL Trace and TKPROF.
How To Pass Oracle 1z0-060 Exam In First Attempt?
Using Stored Outlines & Profiles
Stored Procedures – Facts and Myths
Query Tuning without Production Data
Optimizing SQL Queries
While Loops BIS1523 – Lecture 12.
Introduction to Execution Plans
From 4 Minutes to 8 Seconds in an Hour (or a bit less)
Top Tips for Better TSQL Stored Procedures
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Statistics: What are they and How do I use them
Introduction to Execution Plans
Introduction to Execution Plans
SQL Performance for DBAs
Introduction to Execution Plans
Presentation transcript:

Using Stored Outlines & Profiles Chris Lawson

TIP 1: EASY SQL HINTS USING STORED OUTLINES No reason to avoid outlines. Despite threats, are reportedly still in Oracle 12. So, let’s check ‘em out.

A stored outline preserves an execution plan: 1.You turn-on outline capture. 2. You run the sql. 3. Oracle captures sql and exec plan. 4. Oracle stores sql hints. 5. If sql is run again, Oracle use those sql hints. What is a Stored Outline?

Instead of preserving, Let’s change plans. But Wait That’s Not All!

Create two outlines: ▫ One the “regular” sql. ▫Another using a sql hint. We now have 2 stored outlines: Sql 1: No hint >> Outline 1 (bad plan) Sql 2: hint >> Outline 2 (good plan) Now, reverse hints! Oracle will apply hints from Sql 2 when it sees Sql 1. For a Different Execution Plan

Create outline sql1 on {sql with hint} Create outline sql2 on {regular sql} Update outln.ol$hints set ol_name = decode(ol_name, ‘sql1’, ‘sql2’, ‘sql2’, ‘sql1’) where ol_name in (‘sql1’, ‘sql2’); Here’s the Switch

Create outline sqlz for category tune on Merge into tab1_gt gt using ( Select /*+index(a) */ … Create outline sqlz_fix for category tune on Merge into tab1_gt gt using ( Select … Update outln.Ol$hints set ol_name = decode(ol_name, ‘sqlz_fix’, ‘sqlz’, ‘sqlz’, ‘sqlz_fix’) where ol_name in (‘sqlz’, ‘sqlz_fix’); Outline Example

If a good exec plan is in pool, lock-in that plan exec DBMS_OUTLN.CREATE_OUTLINE (hash_value =>'123', child_number=> 0) Super Easy Way

Get the precise sql. Recommend: Use sql in AWR/Sql report Some Traps!

Pitfall 1: AWR Spaces What if the extra blanks occur as part of the functionality of the sql? AWR report removes extra whitespace Yea, yea, so what?

My code had a clause like this: orig: where col1 like '% abc %' altered: where col1 like '%abc%‘ Missing the blanks means the outline won’t work! I had to alter outline script to add back extra blanks. Don’t Change My Code!

Hints stored in outline are not simple hints. Outlines typically have many more hints. More complicated syntax—”extended” format. This ensures that the plan is consistent. Pitfall 2: Hint Count Who cares about number of hints?

When Outline Created, Oracle Saves Number Of Hints If outline imported, secret process counts hints If #hints <> Hintcount, outline dropped! My sad tale

When you do the "hint switch“ you will likely end up with a different number of hints. You might have started with 10 hints, but after switch, you might have 12 hints. So good idea to verify Hintcount. Let’s see an easy way to check the actual number of hints per outline. Hint Count

Update Hintcount Select ol_name, count(*) from Outln.ol$hints Group by ol_name; Select ol_name, Hintcount from Outln.ol$

Enable Outlines after instance restart! Alter System set Use_Stored_Outlines=TRUE

We know: hints override parallelism set at table. Hey--use outline to override table degree? NO--Outline removes any Parallel Hint Use Outline to Fix Parallelism?

Questions on Outlines?

Tip 2: Easy Sql Profiles Not reliable, but easy. We have 127 stored outlines, and 3 sql profiles. For example, an OEM query had odd hint that would not work with stored outline.

Tell me More! A sql profile is not actually an execution plan. It’s a set of sql hints ready for next time sql is run. Like stored outlines, but hints are different. How different?

How do Sql Profiles Work? They use large amounts of cpu time. They can postulate lots of different plans. They use same optimizer that produced poor execution plan in the first place!

Hints, Hints Everywhere Outline uses sql hints to preserve execution plan Like “full” or “index.” Profile hints give optimizer extra information. Outline tends to lock-in a plan, profile makes optimizer smarter.

What do I do? Step 1: Create the Tuning Task Step 2: Run The Tuning Task Step 3: Get Recommendations Step 4: Apply The Profile Step 5: Confirm Profile is Enabled

Step 1 Create the Tuning Task Call Dbms_Sqltune.Create_Tuning_Task Provide a specific sql_id Give time-limit

Step 2: Run Tuning Task Begin Dbms_Sqltune.Execute_Tuning_Task( Task_Name => 'chris1' ); End; Now, get Recommendations

Step 3 Recommendations Set Long [to get full listing] Set Longchunksize 1000 Set Linesize 100 Select Dbms_Sqltune.Report_Tuning_Task( 'chris1') From Dual; This long report will include a summary of recommendations

Step 3 Look for this: SQL Profile Finding (see explain plans section below) A potentially better execution plan was found for this statement. Recommendation (estimated benefit: 67.35%) Consider accepting the recommended SQL profile.

Step 4 Apply Profile Execute dbms_sqltune.accept_sql_profile (task_name => 'chris1', replace => TRUE);

Step 5: Confirm Enabled Select Name, Created, Type, Status From Dba_Sql_Profiles Where Last_Modified > Sysdate – 1; NAME CREATED TYPE STATUS SYS_SQLPROF_01313de6 18-JUL AM MANUAL ENABLED

Behind the Scenes What is Oracle doing with a sql profile? What kinds of sql hints are being applied? You can see the hints by joining Sys.Sqlobj$Data Od, Sys.Sqlobj$ What do the hints look like?

Sql Profiles Actual Hints TABLE, SCALE_ROWS=3024) TABLE, TABLE, Opt_Estimate hint supplies cardinality information. Scale_Rows parameter scales the estimate of the rows

Sql Profiles: A Big “Plus” Profile can handle changing literals (unlike stored outline) Use Force_Match, like this: dbms_sqltune.accept_sql_profile(task_name => 'chris1', - replace => TRUE, force_match => TRUE);

Sql Profiles “Minus” Syntax awkward if you need to supply sql. For instance, if database has recently started. Especially awkward if sql has quotation marks. Stored outline is trivial to create for specific sql.

A Funny Quirk In Dba_Hist_Sqlstat Sql_Profile is listed Outline_Category is not.

Questions?