Oracle 表访问方式
本篇记录一些Oracle表访问方式
(1)TABLE ACCESS FULL
全表扫表,使用全表扫描的方式访问表。示例:
SQL> exec sql_explain('select * from t1');
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 80 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T1 | 10 | 80 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
PL/SQL procedure successfully completed.
(2)TABLE ACCESS BY INDEX ROWID
通过索引获得的ROWID访问表。
示例:
SQL> exec sql_explain('select * from t1 where id=1');
Plan hash value: 2347959165
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 1 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 8 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | T1_PK | 1 | | 0 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
PL/SQL procedure successfully completed.
(3)LOAD AS SELECT
以(append)追加的方式向表中插入数据。
示例:
SQL> exec sql_explain('insert /*+ append */ into t1 select * from t1');
Plan hash value: 1069440229
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 10 | 80 | 3 (0)| 00:00:01 |
| 1 | LOAD AS SELECT | T1 | | | | |
| 2 | TABLE ACCESS FULL| T1 | 10 | 80 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
PL/SQL procedure successfully completed.