Refer to below link for manually creating and evolving the baseline plan.
http://www.oracle-base.com/articles/11g/SqlPlanManagement_11gR1.php
In the example given in the url above, after adding index we need to manually evolve. This helps in accepting the right plan.
But what happens if i drop the index.
SQL> drop index spm_test_tab_idx; Index dropped. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'SPM_TEST_TAB', cascade=>TRUE); PL/SQL procedure successfully completed.
SQL> SET AUTOTRACE TRACE
SQL> SELECT description
2Â FROMÂ Â spm_test_tab
3Â WHEREÂ id = 99;
Execution Plan
----------------------------------------------------------
Plan hash value: 1107868462
--------------------------------------------------------------------------------
--
| Id | Operation        | Name        | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
--
|Â Â 0 | SELECT STATEMENTÂ |Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â Â 1 |Â Â Â 25 |Â Â Â 13Â Â (0)| 00:00:01
|
|*Â 1 |Â TABLE ACCESS FULL| SPM_TEST_TAB |Â Â Â Â 1 |Â Â Â 25 |Â Â Â 13Â Â (0)| 00:00:01
|
--------------------------------------------------------------------------------
--
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=99)
Note
-----
- SQL plan baseline "SQL_PLAN_7qxjk7bch8h5tb65c37c8" used for this statement ==> Old base line is taken automatically
Statistics
----------------------------------------------------------
1Â recursive calls
0Â db block gets
47Â consistent gets
0Â physical reads
0Â redo size
441Â bytes sent via SQL*Net to client
416Â bytes received via SQL*Net from client
2Â SQL*Net roundtrips to/from client
0Â sorts (memory)
0Â sorts (disk)
1Â rows processed
Let me try to create that index back and see what happens,
SQL> CREATE INDEX spm_test_tab_idx ON spm_test_tab(id);
Index created.
SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'SPM_TEST_TAB', cascade=>TRUE);
PL/SQL procedure successfully completed.
SQL> SELECT description
2Â FROMÂ Â spm_test_tab
3Â WHEREÂ id = 99;
Execution Plan
----------------------------------------------------------
Plan hash value: 3121206333
--------------------------------------------------------------------------------
----------------
| Id | Operation                  | Name            | Rows | Bytes | Cost (%
CPU)| Time    |
--------------------------------------------------------------------------------
----------------
|Â Â 0 | SELECT STATEMENTÂ Â Â Â Â Â Â Â Â Â Â |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â Â 1 |Â Â Â 25 |Â Â Â Â 2
(0)| 00:00:01 |
|Â Â 1 |Â TABLE ACCESS BY INDEX ROWID| SPM_TEST_TABÂ Â Â Â |Â Â Â Â 1 |Â Â Â 25 |Â Â Â Â 2
(0)| 00:00:01 |
|*Â 2 |Â Â INDEX RANGE SCANÂ Â Â Â Â Â Â Â Â | SPM_TEST_TAB_IDX |Â Â Â Â 1 |Â Â Â Â Â Â |Â Â Â Â 1
(0)| 00:00:01 |
--------------------------------------------------------------------------------
----------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=99)
Note
-----
- SQL plan baseline "SQL_PLAN_7qxjk7bch8h5ted3324c0" used for this statement ==> Goes for the best plan
Statistics
----------------------------------------------------------
1Â recursive calls
0Â db block gets
4Â consistent gets
0Â physical reads
0Â redo size
448Â bytes sent via SQL*Net to client
416Â bytes received via SQL*Net from client
2Â SQL*Net roundtrips to/from client
0Â sorts (memory)
0Â sorts (disk)
1Â rows processed
Note: I have not evolved 2nd time after putting back the index.
Need to check how the auto Evolving of baseline works.