Experiment with SQL profile fixed execution plan
Oracle has outlines before 10 Gb, and SQL profile after 10 Gb is one of the new features.
Outlines is insufficient for SQL statements that are not bound to variables.
The following is the experiment process.
- -- 1. preparation stage
- SQL> select * from v $ version;
- BANNER
- ----------------------------------------------------------------
- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
- PL/SQL Release 10.2.0.1.0-Production
- CORE 10.2.0.1.0 Production
- TNS for 32-bit Windows: Version 10.2.0.1.0-Production
- NLSRTL Version 10.2.0.1.0-Production
- SQL> createtable test_raugher asselect * from dba_objects;
- The table has been created.
- SQL> createindex ind_objectid on test_raugher (object_id );
- The index has been created.
- SQL> select object_id from test_raugher where rownum <2;
- OBJECT_ID
- ----------
- 20
- SQL> exec dbms_stats.gather_table_stats (user, 'test _ RAUGHER ', cascade => true );
- The PL/SQL process is successfully completed.
- -- Original SQL Execution Plan
- SQL> set autot trace explain
- SQL> select * from test_raugher where object_id = 20;
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 800879874
- Bytes --------------------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
- Bytes --------------------------------------------------------------------------------------------
- | 0 | select statement | 1 | 95 | 2 (0) | 00:00:01 |
- | 1 | table access byindex rowid | TEST_RAUGHER | 1 | 95 | 2 (0) | 00:00:01 |
- | * 2 | index range scan | IND_OBJECTID | 1 | 1 (0) | 00:00:01 |
- Bytes --------------------------------------------------------------------------------------------
- Predicate Information (identified by operation id ):
- ---------------------------------------------------
- 2-access ("OBJECT_ID" = 20)
- SQL>
- -- New SQL Execution Plan
- SQL> select/* + full (test_raugher) */* from test_raugher where object_id = 20;
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3725671026
- ----------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
- ----------------------------------------------------------------------------------
- | 0 | select statement | 1 | 95 | 166 (2) | 00:00:02 |
- | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
- ----------------------------------------------------------------------------------
- Predicate Information (identified by operation id ):
- ---------------------------------------------------
- 1-filter ("OBJECT_ID" = 20)
- -- 2. Obtain the SQL _id of the new SQL statement.
- SQL> col SQL _id for a20
- SQL> col SQL _text for a100
- SQL> select SQL _id, SQL _text from v $ SQL where SQL _text like '% full (test_raugher) % ';
- SQL _ID SQL _TEXT
- -------------------- Success ------------------------------------------------------------------------------------------------------------------------
- 5nkhk1_705z3 select SQL _id, SQL _text from v $ SQL where SQL _text like '% full (test_raugher) %'
- G23hbdmcsdahc select/* + full (test_raugher) */* from test_raugher where object_id = 20
- Dqp79vx5pmw0k explain plan set STATEMENT_ID = 'plus4294967295 'FORselect/* + full (test_raugher) */* from test_raug
- Her where object_id = 20
- -- 3. Obtain the outline of the new SQL statement
- SQL> set pagesize 1000
- SQL> select * fromtable (dbms_xplan.display_cursor ('g23hbdmcsdahc ', null, 'outline '));
- PLAN_TABLE_OUTPUT
- Bytes -----------------------------------------------------------------------------------------------
- Bytes -----------------------------------------------------------------------------------------------
- SQL _ID g23hbdmcsdahc, child number 0
- -------------------------------------
- Select/* + full (test_raugher) */* from test_raugher where object_id = 20
- Plan hash value: 3725671026
- ----------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
- ----------------------------------------------------------------------------------
- | 0 | select statement | 166 (100) |
- | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
- ----------------------------------------------------------------------------------
- Outline Data
- -------------
- /* +
- BEGIN_OUTLINE_DATA
- IGNORE_OPTIM_EMBEDDED_HINTS
- OPTIMIZER_FEATURES_ENABLE ('10. 2.0.1 ')
- ALL_ROWS
- OUTLINE_LEAF (@ "SEL $1 ")
- FULL (@ "SEL $1" "TEST_RAUGHER" @ "SEL $1 ")
- END_OUTLINE_DATA
- */
- Predicate Information (identified by operation id ):
- ---------------------------------------------------
- 1-filter ("OBJECT_ID" = 20)
- 31 rows have been selected.
- -- 4. Create an SQL profile (SQLPROFILE_001)
- SQL> declare
- 2 v_hints sys. sqlprof_attr;
- 3 begin
- 4 v_hints: = sys. sqlprof_attr (
- 5 'begin_outline_data ',
- 6 'ignore _ OPTIM_EMBEDDED_HINTS ',
- 7 'optimizer _ FEATURES_ENABLE (''10. 2.0.1 '')',
- 8 'all _ ROWS ',
- 9 'outline _ LEAF (@ "SEL $1 ")',
- 10 'full (@ "SEL $1" "TEST_RAUGHER" @ "SEL $1 ")',
- 11 'end _ OUTLINE_DATA ');
- 12 dbms_sqltune.import_ SQL _profile (
- 13 'select * from test_raugher where object_id = 20 ',
- 14 v_hints, 'sqlprofile _ 001 ',
- 15 force_match => true, replace => false );
- 16 end;
- 17/
- The PL/SQL process is successfully completed.
- -- 5. Check whether SQL profile is used
- SQL> set autot trace explain
- SQL> select * from test_raugher where object_id = 20;
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3725671026
- ----------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
- ----------------------------------------------------------------------------------
- | 0 | select statement | 1 | 95 | 166 (2) | 00:00:02 |
- | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
- ----------------------------------------------------------------------------------
- Predicate Information (identified by operation id ):
- ---------------------------------------------------
- 1-filter ("OBJECT_ID" = 20)
- Note
- -----
- -SQL profile "SQLPROFILE_001" used for this statement
- SQL> select * from test_raugher where object_id = 200;
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3725671026
- ----------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
- ----------------------------------------------------------------------------------
- | 0 | select statement | 1 | 95 | 166 (2) | 00:00:02 |
- | * 1 | table access full | TEST_RAUGHER | 1 | 95 | 166 (2) | 00:00:02 |
- ----------------------------------------------------------------------------------
- Predicate Information (identified by operation id ):
- ---------------------------------------------------
- 1-filter ("OBJECT_ID" = 200)
- Note
- -----
- -SQL profile "SQLPROFILE_001" used for this statement