Upload
ashok-thiyagarajan
View
233
Download
0
Embed Size (px)
Citation preview
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 1/44
Outlines, Profiles and SQL Plan
BaselinesFrank Bommarito
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 2/44
Overview
• Optimizer Ranges• Outlines and Profiles• SQL Plan Baselines• Conclusion
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 3/44
Introduction
• Profiles and Outlines are used to correct specificSQL statement
• Profiles and Outlines work on SQL that has already
run and is deemed to be “poor performing”• SQL Plan Baselines capture good times to prevent
poor performing SQL.
• All are used to make a good – predictable system.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 4/44
Optimizer Ranges
• The Extremes• Optimizer Flexibility• Plan Stability
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 5/44
The Extremes
• Optimizer Flexibility• Plan Stability• Default optimizer does a pretty good job on most SQL.• There are always some exceptions – and – often these
are not measured in seconds – sometimes in “days”• Setup the database to where most SQL is good• OLTP lean toward Plan Stability
• DW lean toward Optimizer Flexibility
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 6/44
Optimizer Flexibility
• Give the optimizer as much information as possible• Use histograms where data skews are possible• Generate statistics frequently
• Use dynamic sampling on “load” tables• Start with default settings and adjust only if required
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 7/44
Plan Stability
• Implement more stringent initialization parameters• Limit or eliminate histograms• Avoid bind variable peeking issues
• Port statistics with objects through the developmentcycle.• Reduce the impact of larger production machines (CPU
and Memory)• Execute – infrequent statistics gathering and always
store base lines statistics
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 8/44
Plan Stability
• Plan stability prevents certain database environmentchanges from affecting the performance characteristicsof applications. Such changes include changes inoptimizer statistics, changes to the optimizer modesettings, and changes to parameters affecting the sizesof memory structures, such as SORT_AREA_SIZE andBITMAP_MERGE_AREA_SIZE. Plan stability is mostuseful when you cannot risk any performance changes inan application.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 9/44
What is an Outline – and – Profile?
• Outlines: – An outline is a stored execution path for a specific
SQL statement.
• Profiles – Enhanced database statistics for a specific SQL
statement.
• SQL Plan Baselines are shown later – In effect – a combination of outlines and profiles withintelligence.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 10/44
When to use Outlines and Profiles?
• Plan Stability• Ensure that performance stays consistent between
upgrades (Database and/or application)
• Benefits of cost based optimizer with predictability ofrule based optimizer.
• Allows for tuning without changing SQL or init.ora
parameters.• Tuning of 3 rd party applications
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 11/44
When not to use Outlines and Profiles?
• When Oracle parameters prevent usage• When too many SQL statements need manual
tuning
• When a needed hint is not supported• When it is easy to access the application• This is a reactive tuning method – do not use if
trying to be proactive.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 12/44
How to use?
• Must have privileges – CREATE ANY OUTLINE (DROP/ALTER) – CREATE ANY PROFILE (DROP/ALTER)
• Need to active usage – ALTER SYSTEM/SESSION SET … – USE_STORED_OUTLINES=Category – SQLTUNE_CATEGORY=Category
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 13/44
How to use?
• Need to clear active SQL memory – ALTER SYSTEM FLUSH SHARED POOL;
• Need to persist usage on reboot
– Create trigger <trgname> after startup on database…
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 14/44
How to use?
create or replace trigger use_outln_<cat> after startupon database
begin
execute immediate 'alter system setuse_stored_outlines=<cat>';
end; /
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 15/44
Where are these stored?
• Outlines – Public – outln user – ol$, ol$hints, ol$nodes tables – Private – Pre-10g – personal schema – 10g and
above – system schema – DBA_OUTLINES• Profiles
– SQL$ and SQL$OBJ tables – DBA_SQL_PROFILES
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 16/44
How to create one? - Outline
• alter system flush shared_pool;• alter system/session set create_stored_outlines=<cat>;
• -- Run SQL through the application.
• alter system/session set create_stored_outlines=FALSE;
• alter system set use_stored_outlines=<cat>;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 17/44
How to create one? - Outline
• Create outline for category <x> onSelect * from dual;
• Often created within a “temporary” environmentAlter session set optimizer_mode=rule;Create outline <name> for category AOUG onSelect …;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 18/44
What if I need a hint?
• dbms_outln.edit• Outln_switch.sql• Both work by manipulating the base tables.
Outln_switch can work on private or public tables.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 19/44
What if I need a hint?
Create outline AOUG_base for category AOUG onSelect * from dual;Create outline AOUG_hinted for category AOUG onSelect /*+ full(dual) */ from dual;Call this script (put in a SQL called outln_switch.sql)@@outln_switch AOUG_HINTED AOUG_BASE
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 20/44
Outln_switch.sql
• This is also in the paper – along with dbms_outln.editexamples:define HINTSQL=&1define ORIGINALSQL=&2
UPDATE OUTLN.OL$HINTSSET OL_NAME=DECODE(OL_NAME,'&&HINTSQL','&&ORIGINALSQL','&&ORIGINAL
SQL','&&HINTSQL')
WHERE OL_NAME IN ('&&ORIGINALSQL','&&HINTSQL');DROP OUTLINE &&HINTSQL;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 21/44
How to create one? – Profile
• Oracle OEM• DBMS_SQLTUNE• From an actual SQL statement
• From an AWR report• Paper for this presentation has specific examples• Running the DBMS_SQLTUNE does not guarantee
a fix – but – is very easy to use and often fixes.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 22/44
Is it used? - Outline
• At the system level:select count(*),used from dba_outlines group by
used;COUNT(*) USED
---------- ------18 UNUSED
109 USED
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 23/44
Is it used? - Outline
Exec dbms_outln.clear_used(‘x’);Where “X” is the name of an outline.
• V$SQL – Outline_catgory, Outline_SID
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 24/44
Is it used? - Outline
• Explain Plan Results:select * from table(dbms_xplan.display());Blah
Note-----
- outline "AOUG_OUTLINE" used for thisstatement
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 25/44
Is it used? - Profile
• Explain Plan Results:select * from table(dbms_xplan.display());Blah – Blah - BlahNote-----
- SQL profile "SYS_SQLPROF_0146077cbd7f0000" usedfor this statement
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 26/44
Activate/De-Activate - Outlines• alter system/session set use_stored_outlines=FALSE;• Drop outline xyz;• Alter system flush shared_pool;• Cursor_sharing=force• Change SQL statementSelect * from dualIs the same asSelect * from dualBut –
Select dummy from dualis different
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 27/44
Activate/De-Activate - Profile
dbms_outln.EXACT_TEXT_SIGNATURES can ensurethat an exact match is required
ALTER OUTLINE outline_name CHANGECATEGORY TO not_used_now;alter system/session set sqltune_category=FALSE;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 28/44
Activate/De-Activate - Profile
declarebegindbms_sqltune.drop_sql_profile(name =>
'SYS_SQLPROF_070515143928038');end;
/
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 29/44
Migrate - Outlines
• $ exp owner=outln file=outlntables=ol$,ol$hints,ol$nodes query=‘wherecategory=“<cat>”’ username=outln@test
• Prod> delete outln.ol$;• Prod> delete outln.ol$hints;• Prod> delete outln.ol$nodes;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 30/44
Migrate - Outlines
• Prod$ imp full=y ignore=y file=outln• Prod> exec dbms_outln.clear_used;• Prod> alter system flush shared_pool;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 31/44
Migrate - Profiles
# In testdbms_sqltune.create_stgtab_sqlprof('AOUG_PROFILES','AOUG');
dbms_sqltune.pack_stgtab_sqlprof(STAGING_TABLE_NAME=>
'AOUG_PROFILES',STAGING_SCHEMA_OWNER=>'AOUG');$ exp tables=AOUG.AOUG_profiles$ scp expdat.dmp Prod_Host:expdat.dmp
$ imp full=y ignore=y
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 32/44
Migrate - Profiles
dbms_sqltune.unpack_stgtab_sqlprof(PROFILE_NAME=>'%',PROFILE_CATEGORY=>'%', REPLACE=>TRUE,STAGING_TABLE_NAME=>'AOUG_PROFILES',STAGING_SCHEMA_OWNER=>'AOUG');
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 33/44
Pros/Cons
• Pros – Allows tuning of SQL that is not changeable – Provides “plan stability” – Allows development to production to be predictable – Gives all of the cost-based optimizer advantages with
the rule-based optimizer predictability. – Can reduce or eliminate statistics jobs
– Multiple outlines categories can be used to separateOLTP and BATCH.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 34/44
Pros/Cons
• Pros – Easy to use – Easy to implement
– Supported by all known third-party applications
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 35/44
Pros/Cons
• Cons – Does not allow for column level variations for plans. – Requires maintenance when the application changes
– Can be disabled without knowledge – Requires “trespassing” into the application – Outlines require sophisticated tuning knowledge
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 36/44
SQL Plan Baselines – What is it?
• SQL Plan Baselines is a new feature with release 11of Oracle.• Used “safe” – or – “trusted” plans
• Captures new plans for later analysis• Captures can be manual or automatic• Single repository for Profiles and Outlines
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 37/44
How to enable?
• OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES – For automatic capturing
• Usage of DBMS_SPM package
– For manual capturing and validation• OPTIMIZER_USE_SQL_PLAN_BASELINES
– To enable usage
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 38/44
Manual Loading• Plans can be loaded from AWR reports and/or the SQL cursor
cache.DECLAREv_sql_plan pls_integer;BEGIN
v_sql_plans :=DBMS_SPM.LOAD_PLANS_FROM_SQLSET(sqlset_name =>'AOUG_SET');
v_sql_plans :=DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE(
sql_id => '99twu5t2dn5xd');END;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 39/44
Validating PlansDBA_SQL_PLAN_BASELINES (SQL_HANDLE)
SET SERVEROUTPUT ONSET LONG 10000DECLARE
v_report clob;BEGIN
v_report :=DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(sql_handle =>'SYS_SQL_593bc74fca8e6738');DBMS_OUTPUT.PUT_LINE(v_report);
END;
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 40/44
View an explain plan from a baseline
select * from table(dbms_xplan.display_sql_plan_baseline(sql_handle=>'SYS_SQL_209d10fabbedc741',format=>'basic'));
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 41/44
MigrateDBMS_SPM.CREATE_STGTAB_BASELINE(table_name =>
'AOUG_SPM');DECLAREv_plans number;BEGIN
v_plans := DBMS_SPM.PACK_STGTAB_BASELINE(table_name =>'AOUG_SPM',• enabled => 'yes');END;/
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 42/44
Migrate$ exp tables=AOUG_SPM$ scp expdat.dmp Prod_Host:$ On Prod Host – imp full=yDECLAREv_plans number;
BEGINv_plans := DBMS_SPM.UNPACK_STGTAB_BASELINE(table_name=> 'AOUG_SPM');
END;/
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 43/44
Conclusion
• Usage of optimizer features for plan stabilityprovides a powerful and effective means to takecontrol of an application. As with any otherdatabase utility, ensure that there is a completeunderstanding and setting of expectations prior toimplementation.
8/13/2019 Outlines Profiles and SQL Baselines
http://slidepdf.com/reader/full/outlines-profiles-and-sql-baselines 44/44
Questions
• Frank Bommarito• DBA Knowledge, Inc.• [email protected]
• http://www.dbaknow.com
?