System altered.
SQL> set autotrace traceonly;
----查询一个范围的执行计划----
SQL> select * from jack where object_id>1000 and object_id<2000;
9880 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 949574992
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9657 | 914K| 1824 (1)| 00:00:22 |
|* 1 | TABLE ACCESS FULL| JACK | 9657 | 914K| 1824 (1)| 00:00:22 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"<2000 AND "OBJECT_ID">1000)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
10993 consistent gets
10340 physical reads
0 redo size
471945 bytes sent via SQL*Net to client
7657 bytes received via SQL*Net from client
660 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9880 rows processed ----注意,object_id上是有索引的,但是这里并没有使用索引,而是使用了全表扫描。
SQL> alter system flush buffer_cache;
System altered.
----强制走索引,查看执行计划----
SQL> select /*+ index(jack jack_ind) */ * from jack where object_id>1000 and object_id<2000;
9880 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2860868395
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9657 | 914K| 9683 (1)| 00:01:57 |
| 1 | TABLE ACCESS BY INDEX ROWID| JACK | 9657 | 914K| 9683 (1)| 00:01:57 |
|* 2 | INDEX RANGE SCAN | JACK_IND | 9657 | | 24 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID">1000 AND "OBJECT_ID"<2000)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
10561 consistent gets
164 physical reads
0 redo size
988947 bytes sent via SQL*Net to client
&nb