###############測試插入 刪除 更新表的日誌開銷
建立表
SYS@orcl >create table ssr(id int);
查詢表空間,sys默認system,插入數據後此分配空間
SYS@orcl >select tablespace_name, segment_name from user_segments where segment_name='SSR';
TABLESPACE_NAME SEGMENT_NAME
---------------------------------------------------------
SYSTEM SSR
建立空表
GUOYF@orcl 09:20:01>create table aa as select * from all_objects where 1=0;
查詢現有日誌大小
select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME VALUE
---------------------------------------------------------------- ----------
redo size 254388
插入數據
GUOYF@orcl 09:24:01>insert into aa select * from all_objects where rownum<100;
查詢日誌大小
select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME VALUE
---------------------------------------------------------------- ----------
redo size 268768
更新數據
GUOYF@orcl 09:27:47>update aa set owner='guoyf' where owner='SYS';
查看日誌大小
select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME VALUE
---------------------------------------------------------------- ----------
redo size 294612
刪除數據
GUOYF@orcl 09:29:10>delete from aa where owner='guoyf';
查看日誌大小
select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME VALUE
---------------------------------------------------------------- ----------
redo size 330832
經過以上數據代表產生日誌量
刪除》更新》插入
AUTOTRACE是一個SQL*Plus工具,用於跟蹤SQL的執行計劃,收集執行時所耗用資源的統計信息
set autotrace off :缺省值,將不生成autotrace 報告
set autotrace on :包含執行計劃和統計信息
set autotrace traceonly :等同於set autotrace on,但不顯示查詢輸出的結果
set autotrace on explain :只顯示優化器執行路徑報告
set autotrace on statistics :只顯示執行統計信息
#######測試delete沒法釋放表空間
建立表
SQL> create table bb as select * from dba_objects;
開啓啊autotrace
SQL> set autotrace on ;
##查看I/O
SQL> select count(*) from bb;
COUNT(*)
----------
72573
Execution Plan
----------------------------------------------------------
Plan hash value: 162157452
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 290 (1)| 00:00:04 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| BB | 69590 | 290 (1)| 00:00:04 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
28 recursive calls
0 db block gets
1106 consistent gets
1034 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
關閉啊autotrace
SQL> set autotrace off;
刪除表
SQL> delete from bb;
72653 rows deleted.
SQL> select count(*) from bb;
COUNT(*)
----------
0
SQL> commit;
Commit complete.
SQL> set autotrace on;
SQL> select count(*) from bb;
COUNT(*)
----------
0
Execution Plan
----------------------------------------------------------
Plan hash value: 162157452
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 289 (0)| 00:00:04 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| BB | 1 | 289 (0)| 00:00:04 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1039 consistent gets
0 physical reads
0 redo size
525 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> truncate table bb;
Table truncated.
SQL> select count(*) from bb;
COUNT(*)
----------
0
Execution Plan
----------------------------------------------------------
Plan hash value: 162157452
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| BB | 1 | 2 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
20 recursive calls
1 db block gets
10 consistent gets
0 physical reads
96 redo size
525 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
c#