Outlines Profiles and SQL Baselines
Outlines Profiles and SQL Baselines
Frank Bommarito
Overview
Optimizer Ranges Outlines and Profiles SQL Plan Baselines Conclusion
Introduction
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.
Optimizer Ranges
The Extremes Optimizer Flexibility Plan Stability
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
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
Plan Stability
Plan stability prevents certain database environment changes from affecting the performance characteristics of applications. Such changes include changes in optimizer statistics, changes to the optimizer mode settings, and changes to parameters affecting the sizes of memory structures, such as SORT_AREA_SIZE and BITMAP_MERGE_AREA_SIZE. Plan stability is most useful when you cannot risk any performance changes in an application.
Profiles
Enhanced database statistics for a specific SQL statement.
How to use?
Must have privileges
CREATE ANY OUTLINE (DROP/ALTER) CREATE ANY PROFILE (DROP/ALTER)
How to use?
Need to clear active SQL memory
ALTER SYSTEM FLUSH SHARED POOL;
How to use?
create or replace trigger use_outln_<cat> after startup on database begin execute immediate 'alter system set use_stored_outlines=<cat>'; end; /
Profiles
SQL$ and SQL$OBJ tables DBA_SQL_PROFILES
Outln_switch.sql
This is also in the paper along with dbms_outln.edit examples:
define HINTSQL=&1 define ORIGINALSQL=&2 UPDATE OUTLN.OL$HINTS SET OL_NAME= DECODE(OL_NAME,'&&HINTSQL','&&ORIGINALSQL','&&ORIGINAL SQL','&&HINTSQL') WHERE OL_NAME IN ('&&ORIGINALSQL','&&HINTSQL'); DROP OUTLINE &&HINTSQL;
Is it used? - Outline
At the system level: select count(*),used from dba_outlines group by used; COUNT(*) USED --------------18 UNUSED 109 USED
Is it used? - Outline
Exec dbms_outln.clear_used(x); Where X is the name of an outline. V$SQL Outline_catgory, Outline_SID
Is it used? - Outline
Explain Plan Results: select * from table(dbms_xplan.display()); Blah Note ----- outline "AOUG_OUTLINE" used for this statement
Is it used? - Profile
Explain Plan Results: select * from table(dbms_xplan.display()); Blah Blah - Blah Note ----- SQL profile "SYS_SQLPROF_0146077cbd7f0000" used for this statement
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 statement Select * from dual Is the same as Select * from dual But Select dummy from dual is different
Activate/De-Activate - Profile
dbms_outln.EXACT_TEXT_SIGNATURES can ensure that an exact match is required
Activate/De-Activate - Profile
declare begin dbms_sqltune.drop_sql_profile(name => 'SYS_SQLPROF_070515143928038'); end; /
Migrate - Outlines
$ exp owner=outln file=outln tables=ol$,ol$hints,ol$nodes query=where category=<cat> username=outln@test Prod> delete outln.ol$; Prod> delete outln.ol$hints; Prod> delete outln.ol$nodes;
Migrate - Outlines
Prod$ imp full=y ignore=y file=outln Prod> exec dbms_outln.clear_used; Prod> alter system flush shared_pool;
Migrate - Profiles
# In test dbms_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
Migrate - Profiles
dbms_sqltune.unpack_stgtab_sqlprof(PROFILE_NAME=>'%', PROFILE_CATEGORY=>'%', REPLACE=>TRUE, STAGING_TABLE_NAME=>'AOUG_PROFILES', STAGING_SCHEMA_OWNER=>'AOUG');
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 separate OLTP and BATCH.
Pros/Cons
Pros
Easy to use Easy to implement Supported by all known third-party applications
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
How to enable?
OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES
For automatic capturing
OPTIMIZER_USE_SQL_PLAN_BASELINES
To enable usage
Manual Loading
Plans can be loaded from AWR reports and/or the SQL cursor cache. DECLARE v_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;
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.PUT_LINE(v_report); END;
Migrate
DBMS_SPM.CREATE_STGTAB_BASELINE(table_name => 'AOUG_SPM'); DECLARE v_plans number; BEGIN v_plans := DBMS_SPM.PACK_STGTAB_BASELINE(table_name => 'AOUG_SPM', enabled => 'yes'); END; /
Migrate
$ exp tables=AOUG_SPM $ scp expdat.dmp Prod_Host: $ On Prod Host imp full=y DECLARE v_plans number; BEGIN v_plans := DBMS_SPM.UNPACK_STGTAB_BASELINE(table_name => 'AOUG_SPM'); END; /
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.
Questions
Frank Bommarito DBA Knowledge, Inc. [email protected] http://www.dbaknow.com