Skip to content

Commit fdedc62

Browse files
committed
spm fix
1 parent d1e266f commit fdedc62

24 files changed

+1368
-0
lines changed

optimizer/spm_fix/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
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.
2+
3+
SPM will search for historic plans, choose the best one and enforce it with a SQL plan baseline.
4+
5+
This demonstration is intended for use in Oracle Database 18c onwards.
6+
7+
It works as follows:
8+
9+
- Tables T1 and T2 have data skew
10+
- Q1 is a query that joins T1 and T2
11+
- Histograms tell the optimizer about the skew so Q1 performs well
12+
- We drop the histograms and this induces a poor plan for Q1
13+
- SPM is initiated and it finds the previous good plan
14+
- The good plan is tested (automatically) by SPM and a SQL plan baseline is created
15+
- Q1 now uses the good plan
16+
17+
$ sqlplus / as sysdba [or connect to PDB ADMIN]
18+
SQL> @@user
19+
SQL> connect spmdemo/spmdemo
20+
--
21+
-- Create test tables
22+
--
23+
SQL> @@tab
24+
--
25+
-- Review/execute the following script
26+
--
27+
SQL> @@example
28+
29+
Note that AWR is accessed. Check the Oracle Database License Guide for details.
30+
31+
The test creates two tables T1 and T2 - use a test database

optimizer/spm_fix/drop.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DECLARE
2+
l_plans_dropped PLS_INTEGER;
3+
BEGIN
4+
5+
FOR REC IN (SELECT DISTINCT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES )
6+
-- WHERE CREATOR = 'SPMDEMO')
7+
LOOP
8+
L_PLANS_DROPPED := DBMS_SPM.DROP_SQL_PLAN_BASELINE (
9+
sql_handle => rec.sql_handle,
10+
PLAN_NAME => NULL);
11+
END LOOP;
12+
13+
END;
14+
/
15+

optimizer/spm_fix/droph.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set echo on
2+
exec dbms_stats.delete_column_stats(user,'t1','d',no_invalidate=>false,col_stat_type=>'HISTOGRAM');
3+
exec dbms_stats.delete_column_stats(user,'t2','d',no_invalidate=>false,col_stat_type=>'HISTOGRAM');

0 commit comments

Comments
 (0)