|
| 1 | +<h2>Using SQL Plan Management to Control SQL Execution Plans</h2> |
| 2 | + |
| 3 | +Based on <a href="https://blogs.oracle.com/optimizer/using-sql-plan-management-to-control-sql-execution-plans">this blog article.</a> |
| 4 | + |
| 5 | +The utility scripts are fix_all.sql and fix_spm.sql |
| 6 | + |
| 7 | +They are intended to be similar in usage to the MOS script "coe_xfr_sql_profile.sql" - but using SQL plan baselines rather than SQL profiles. |
| 8 | + |
| 9 | +You can run a simple testcase as follows: |
| 10 | + |
| 11 | +``` |
| 12 | +$ sqlplus dbauser/password |
| 13 | +SQL> @@setup |
| 14 | +SQL> @@q --- The query will use the BOB_PK execution plan (this is the best one) |
| 15 | +SQL> @@test_spm --- This will force the query to use the BOB_IDX plan instead (not the best plan, but this is a demo!) |
| 16 | +SQL> @@q --- See the query is now using the SQL plan baseline |
| 17 | +SQL> @@look --- Take a look at the SQL plan baseline |
| 18 | +``` |
| 19 | + |
| 20 | +If you are licensed, you can retireve plans from AWR or SQL tuining sets: |
| 21 | + |
| 22 | +``` |
| 23 | +$ sqlplus dbauser/password |
| 24 | +SQL> @@setup |
| 25 | +SQL> @@awr --- Load two different plans in AWR for our SQL Statement [BOB_IDX and BOB_PK] |
| 26 | +SQL> @@sts --- Load BOB FULL plan into a SQL tuning set |
| 27 | +SQL> @@test_all --- Pick one of the plans... |
| 28 | + --- BOB_PK = plan hash value 772239758 |
| 29 | + --- BOB_IDX = plan hash value 4251244305 |
| 30 | + --- BOB FULL scan = plan hash value 1006760864 |
| 31 | +SQL> @@q --- Run the query to see the plan you chose |
| 32 | +SQL> @test_all --- Pick a different plan |
| 33 | +SQL> @@q --- Take another look at the plan |
| 34 | +SQL> @@look --- View SQL plan baselines |
| 35 | +``` |
| 36 | + |
| 37 | +The scripts require Oracle Database 12c Release 2 onwards. |
| 38 | + |
| 39 | +DISCLAIMER: |
| 40 | + <br/>-- These scripts are provided for educational purposes only. |
| 41 | + <br/>-- They are NOT supported by Oracle World Wide Technical Support. |
| 42 | + <br/>-- The scripts have been tested and they appear to work as intended. |
| 43 | + <br/>-- You should always run scripts on a test instance. |
0 commit comments