insert,update,delete产生redo日志的比较

对于三种操作产生的redo日志,网上找到的信息:update > delete > insert,但是我实验发现,这需要有个前提条件,就是update的字节总和要约等于整条记录的字节总和如果你使用一个标志位来表示记录删除,那么使用update将会产生更少的redo
决定update产生redo量的一个因素就是更新的字节数。
实验数据如下:
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table test
  2  ( 
  3  a1 char(1),
  4  a2 char(10),
  5  a3 char(100),
  6  a4 char(1000)
  7  );

表已创建。

SQL> set autotrace on
SQL> insert into test(a1, a2, a3, a4)
  2  values('1', '1', '1', '1');

已创建 1 行。


执行计划
----------------------------------------------------------

-------------------------------------------------------------------------
| Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------
|   0 | INSERT STATEMENT |      |     1 |   100 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------


统计信息
----------------------------------------------------------
          3  recursive calls
         22  db block gets
          2  consistent gets
          0  physical reads
          0  redo size
        542  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          1  rows processed
SQL> update test set a2='2' where a1='1';

已更新 1 行。


执行计划
----------------------------------------------------------
Plan hash value: 839355234

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | UPDATE STATEMENT   |      |     1 |    15 |     3   (0)| 00:00:01 |
|   1 |  UPDATE            | TEST |       |       |            |          |
|*  2 |   TABLE ACCESS FULL| TEST |     1 |    15 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("A1"='1')

Note
-----
   - dynamic sampling used for this statement


统计信息
----------------------------------------------------------
         48  recursive calls
          1  db block gets
         19  consistent gets
          0  physical reads
        364  redo size
        541  bytes sent via SQL*Net to client
        479  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL> update test set a3='2' where a1='1';

已更新 1 行。


执行计划
----------------------------------------------------------
Plan hash value: 839355234

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | UPDATE STATEMENT   |      |     1 |   105 |     3   (0)| 00:00:01 |
|   1 |  UPDATE            | TEST |       |       |            |          |
|*  2 |   TABLE ACCESS FULL| TEST |     1 |   105 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("A1"='1')

Note
-----
   - dynamic sampling used for this statement


统计信息
----------------------------------------------------------
         27  recursive calls
          1  db block gets
         17  consistent gets
          0  physical reads
        548  redo size
        545  bytes sent via SQL*Net to client
        479  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL> update test set a4='2' where a1='1';

已更新 1 行。


执行计划
----------------------------------------------------------
Plan hash value: 839355234

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | UPDATE STATEMENT   |      |     1 |  1005 |     3   (0)| 00:00:01 |
|   1 |  UPDATE            | TEST |       |       |            |          |
|*  2 |   TABLE ACCESS FULL| TEST |     1 |  1005 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("A1"='1')

Note
-----
   - dynamic sampling used for this statement


统计信息
----------------------------------------------------------
         27  recursive calls
          1  db block gets
         17  consistent gets
          0  physical reads
       2348  redo size
        546  bytes sent via SQL*Net to client
        479  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL> delete test where a1='1';

已删除 1 行。


执行计划
----------------------------------------------------------
Plan hash value: 180605370

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | DELETE STATEMENT   |      |     1 |     3 |     3   (0)| 00:00:01 |
|   1 |  DELETE            | TEST |       |       |            |          |
|*  2 |   TABLE ACCESS FULL| TEST |     1 |     3 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("A1"='1')

Note
-----
   - dynamic sampling used for this statement


统计信息
----------------------------------------------------------
          4  recursive calls
          2  db block gets
         15  consistent gets
          0  physical reads
       1400  redo size
        547  bytes sent via SQL*Net to client
        468  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL>



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14683446/viewspace-714492/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/14683446/viewspace-714492/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值