Skip to content

Commit

Permalink
spm fix
Browse files Browse the repository at this point in the history
nigelbayliss committed Oct 7, 2019
1 parent d1e266f commit fdedc62
Showing 24 changed files with 1,368 additions and 0 deletions.
31 changes: 31 additions & 0 deletions optimizer/spm_fix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
This demo shows you how you can use SQL plan management (SPM) to fix a SQL statement that is experiencing a performance regression caused by a sub-optimal plan.

SPM will search for historic plans, choose the best one and enforce it with a SQL plan baseline.

This demonstration is intended for use in Oracle Database 18c onwards.

It works as follows:

- Tables T1 and T2 have data skew
- Q1 is a query that joins T1 and T2
- Histograms tell the optimizer about the skew so Q1 performs well
- We drop the histograms and this induces a poor plan for Q1
- SPM is initiated and it finds the previous good plan
- The good plan is tested (automatically) by SPM and a SQL plan baseline is created
- Q1 now uses the good plan

$ sqlplus / as sysdba [or connect to PDB ADMIN]
SQL> @@user
SQL> connect spmdemo/spmdemo
--
-- Create test tables
--
SQL> @@tab
--
-- Review/execute the following script
--
SQL> @@example

Note that AWR is accessed. Check the Oracle Database License Guide for details.

The test creates two tables T1 and T2 - use a test database
15 changes: 15 additions & 0 deletions optimizer/spm_fix/drop.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DECLARE
l_plans_dropped PLS_INTEGER;
BEGIN

FOR REC IN (SELECT DISTINCT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES )
-- WHERE CREATOR = 'SPMDEMO')
LOOP
L_PLANS_DROPPED := DBMS_SPM.DROP_SQL_PLAN_BASELINE (
sql_handle => rec.sql_handle,
PLAN_NAME => NULL);
END LOOP;

END;
/

3 changes: 3 additions & 0 deletions optimizer/spm_fix/droph.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set echo on
exec dbms_stats.delete_column_stats(user,'t1','d',no_invalidate=>false,col_stat_type=>'HISTOGRAM');
exec dbms_stats.delete_column_stats(user,'t2','d',no_invalidate=>false,col_stat_type=>'HISTOGRAM');
Loading

0 comments on commit fdedc62

Please sign in to comment.