|
SQL> create outline ol_t1 for category cc on select count(*) from t1;
Outline created.
SQL> select count(*) from t1;
COUNT(*)
----------
314496
Execution Plan
----------------------------------------------------------
Plan hash value: 3693069535
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 912 (1)| 00:00:11 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T1 | 314K| 912 (1)| 00:00:11 |
-------------------------------------------------------------------
Note
-----
- outline "OL_T1" used for this statement
Statistics
----------------------------------------------------------
34 recursive calls
147 db block gets
4151 consistent gets
0 physical reads
576 redo size
517 bytes sent via SQL*Net to client
492 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> create index ind_t1 on t1(object_id);
Index created.
SQL> alter session set use_stored_outlines=cc;
Session altered.
SQL> select count(*) from t1;
COUNT(*)
----------
314496
Execution Plan
----------------------------------------------------------
Plan hash value: 2450975207
------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 159 (3)| 00:00:02 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IND_T1 | 314K| 159 (3)| 00:00:02 |
------------------------------------------------------------------------
Note
-----
- outline "OL_T1" used for this statement
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
709 consistent gets
702 physical reads
0 redo size
517 bytes sent via SQL*Net to client
492 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
请问为啥2次执行用的一个Outline ,执行计划确不同呢?而且从outln.ol$hints看,ol_t1就是全表扫描,为啥第二次就走了索引呢?
SQL> L
1* select OL_NAME,CATEGORY, HINT_TEXT from outln.ol$hints where ol_name='OL_T1'
SQL> /
OL_NAME CATEGORY HINT_TEXT
---------- ---------- ----------------------------------------------------------------------
OL_T1 CC FULL(@"SEL$1" [email=]"T1"@"SEL$1[/email]")
OL_T1 CC OUTLINE_LEAF(@"SEL$1")
OL_T1 CC ALL_ROWS
OL_T1 CC OPT_PARAM('optimizer_dynamic_sampling' 0)
OL_T1 CC OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
OL_T1 CC IGNORE_OPTIM_EMBEDDED_HINTS |
|