This action might not be possible to undo. Are you sure you want to continue?
• • • • Optimizer Ranges Outlines and Profiles SQL Plan Baselines Conclusion
• Profiles and Outlines are used to correct specific SQL 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.
• The Extremes • Optimizer Flexibility • Plan Stability
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 .The Extremes • • • • Optimizer Flexibility Plan Stability Default optimizer does a pretty good job on most SQL.
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 .
Plan Stability • • • • Implement more stringent initialization parameters Limit or eliminate histograms Avoid bind variable peeking issues Port statistics with objects through the development cycle. • Reduce the impact of larger production machines (CPU and Memory) • Execute – infrequent statistics gathering and always store base lines statistics .
Such changes include changes in optimizer statistics. and changes to parameters affecting the sizes of memory structures. . such as SORT_AREA_SIZE and BITMAP_MERGE_AREA_SIZE.Plan Stability • Plan stability prevents certain database environment changes from affecting the performance characteristics of applications. Plan stability is most useful when you cannot risk any performance changes in an application. changes to the optimizer mode settings.
. • SQL Plan Baselines are shown later – In effect – a combination of outlines and profiles with intelligence. • Profiles – Enhanced database statistics for a specific SQL statement.What is an Outline – and – Profile? • Outlines: – An outline is a stored execution path for a specific SQL statement.
ora parameters. • Tuning of 3rd party applications .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 of rule based optimizer. • Allows for tuning without changing SQL or init.
.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.
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 .
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… .
end. / .How to use? create or replace trigger use_outln_<cat> after startup on database begin execute immediate 'alter system set use_stored_outlines=<cat>'.
ol$hints.Where are these stored? • Outlines – Public – outln user – ol$. ol$nodes tables – Private – Pre-10g – personal schema – 10g and above – system schema – DBA_OUTLINES • Profiles – SQL$ and SQL$OBJ tables – DBA_SQL_PROFILES .
• alter system/session set create_stored_outlines=FALSE.Run SQL through the application. • alter system set use_stored_outlines=<cat>. • -. • alter system/session set create_stored_outlines=<cat>.Outline • alter system flush shared_pool.How to create one? . .
• Often created within a “temporary” environment Alter session set optimizer_mode=rule. . Create outline <name> for category AOUG on Select ….How to create one? .Outline • Create outline for category <x> on Select * from dual.
Outln_switch can work on private or public tables.edit • Outln_switch. .sql • Both work by manipulating the base tables.What if I need a hint? • dbms_outln.
Create outline AOUG_hinted for category AOUG on Select /*+ full(dual) */ from dual.sql) @@outln_switch AOUG_HINTED AOUG_BASE . Call this script (put in a SQL called outln_switch.What if I need a hint? Create outline AOUG_base for category AOUG on Select * from dual.
'&&ORIGINALSQL'.Outln_switch. DROP OUTLINE &&HINTSQL.sql • This is also in the paper – along with dbms_outln.'&&HINTSQL'.'&&HINTSQL') WHERE OL_NAME IN ('&&ORIGINALSQL'.edit examples: define HINTSQL=&1 define ORIGINALSQL=&2 UPDATE OUTLN.'&&ORIGINAL SQL'. .OL$HINTS SET OL_NAME= DECODE(OL_NAME.'&&HINTSQL').
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. .
Is it used? .used from dba_outlines group by used. COUNT(*) USED --------------18 UNUSED 109 USED .Outline • At the system level: select count(*).
Where “X” is the name of an outline. Outline_SID .Is it used? .Outline Exec dbms_outln.clear_used(‘x’). • V$SQL – Outline_catgory.
Is it used? .outline "AOUG_OUTLINE" used for this statement . Blah Note ----.display()).Outline • Explain Plan Results: select * from table(dbms_xplan.
Is it used? .SQL profile "SYS_SQLPROF_0146077cbd7f0000" used for this statement .Profile • Explain Plan Results: select * from table(dbms_xplan.Blah Note ----. Blah – Blah .display()).
Activate/De-Activate .Outlines • alter system/session set use_stored_outlines=FALSE. • Drop outline xyz. • Cursor_sharing=force • Change SQL statement Select * from dual Is the same as Select * from dual But – Select dummy from dual is different . • Alter system flush shared_pool.
Profile dbms_outln.EXACT_TEXT_SIGNATURES can ensure that an exact match is required ALTER OUTLINE outline_name CHANGE CATEGORY TO not_used_now. alter system/session set sqltune_category=FALSE. .Activate/De-Activate .
Activate/De-Activate .drop_sql_profile(name => 'SYS_SQLPROF_070515143928038'). end. / .Profile declare begin dbms_sqltune.
• Prod> delete outln.Migrate .ol$hints. .Outlines • $ exp owner=outln file=outln tables=ol$.ol$.ol$hints.ol$nodes query=‘where category=“<cat>”’ username=outln@test • Prod> delete outln.ol$nodes. • Prod> delete outln.
.Outlines • Prod$ imp full=y ignore=y file=outln • Prod> exec dbms_outln.Migrate . • Prod> alter system flush shared_pool.clear_used.
dbms_sqltune.dmp $ imp full=y ignore=y . $ exp tables=AOUG. STAGING_SCHEMA_OWNER=>'AOUG').Profiles # In test dbms_sqltune.pack_stgtab_sqlprof(STAGING_TABLE_NAME=> 'AOUG_PROFILES'.dmp Prod_Host:expdat.create_stgtab_sqlprof('AOUG_PROFILES'.Migrate .AOUG_profiles $ scp expdat.'AOUG ').
unpack_stgtab_sqlprof(PROFILE_NAME=>'%'. REPLACE=>TRUE. . STAGING_TABLE_NAME=>'AOUG_PROFILES'.Profiles dbms_sqltune. PROFILE_CATEGORY=>'%'.Migrate . STAGING_SCHEMA_OWNER=>'AOUG').
. – Can reduce or eliminate statistics jobs – Multiple outlines categories can be used to separate OLTP and BATCH.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.
Pros/Cons • Pros – Easy to use – Easy to implement – Supported by all known third-party applications .
Requires maintenance when the application changes Can be disabled without knowledge Requires “trespassing” into the application Outlines require sophisticated tuning knowledge .Pros/Cons • Cons – – – – – Does not allow for column level variations for plans.
• Used “safe” – or – “trusted” plans • Captures new plans for later analysis • Captures can be manual or automatic • Single repository for Profiles and Outlines .SQL Plan Baselines – What is it? • SQL Plan Baselines is a new feature with release 11 of Oracle.
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 .
.Manual Loading • Plans can be loaded from AWR reports and/or the SQL cursor cache.LOAD_PLANS_FROM_CURSOR_CACHE( sql_id => '99twu5t2dn5xd'). END. v_sql_plans := DBMS_SPM. DECLARE v_sql_plan pls_integer. BEGIN v_sql_plans := DBMS_SPM.LOAD_PLANS_FROM_SQLSET(sqlset_name => 'AOUG_SET').
Validating Plans DBA_SQL_PLAN_BASELINES (SQL_HANDLE) SET SERVEROUTPUT ON SET LONG 10000 DECLARE v_report clob. BEGIN v_report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(sql_handle => 'SYS_SQL_593bc74fca8e6738'). . DBMS_OUTPUT. END.PUT_LINE(v_report).
View an explain plan from a baseline select * from table( dbms_xplan. . format=>'basic')).display_sql_plan_baseline( sql_handle=>'SYS_SQL_209d10fabbedc741'.
/ . END. BEGIN v_plans := DBMS_SPM.PACK_STGTAB_BASELINE(table_name => 'AOUG_SPM'.CREATE_STGTAB_BASELINE(table_name => 'AOUG_SPM').Migrate DBMS_SPM. • enabled => 'yes'). DECLARE v_plans number.
BEGIN v_plans := DBMS_SPM.dmp Prod_Host: $ On Prod Host – imp full=y DECLARE v_plans number. END.UNPACK_STGTAB_BASELINE(table_name => 'AOUG_SPM').Migrate $ exp tables=AOUG_SPM $ scp expdat. / .
.Conclusion • Usage of optimizer features for plan stability provides a powerful and effective means to take control of an application. As with any other database utility. ensure that there is a complete understanding and setting of expectations prior to implementation.
Inc.com http://www. email@example.com.Questions • • • • Frank Bommarito DBA Knowledge.com ? .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.